MediaWiki:Live EriCSSon.js

In this article we are going to analyze MediaWiki:Live EriCSSon.js, a topic that has generated great interest in recent times. MediaWiki:Live EriCSSon.js is a topic that has captured the attention of many people due to its relevance in different areas, from science to popular culture. Furthermore, MediaWiki:Live EriCSSon.js has been the subject of numerous debates and discussions, which has contributed to its growing importance in today's society. Throughout this article, we will explore different aspects related to MediaWiki:Live EriCSSon.js, from its origin and evolution to its impact today. Through detailed analysis, we will try to shed light on this topic and provide a more complete and deeper insight into MediaWiki:Live EriCSSon.js.
mw.loader.load(  );


var live_ericsson = {

	use_css_cookie : 'Live_EriCSSon_useCSS' ,

	init : function () {
		
//		if ( mw.config.get('wgNamespaceNumber') != 0 ) return ;
//		if ( mw.config.get('wgAction') != 'view' ) return ;
		var self = this ;
		var portletLink = mw.util.addPortletLink( 'p-tb', '#', 'Live EriCSSon','t-live-ericsson');
		$(portletLink).click ( function () {
			self.options() ;
			return false ;
		} ) ;
		self.run() ;
	} ,
	
	run : function () {
		var self = this ;
		var use_css = self.getURLParameter ( 'useCSS' ) ;
		if ( !self.isSet ( use_css ) ) {
			use_css = $.cookie( self.use_css_cookie ) ;
			if ( !self.isSet ( use_css ) ) return ;
		}
		self.use_css = use_css ;
		var api = new mw.Api();
		api.get( {
			action: 'query',
			prop: 'revisions' ,
			titles: use_css ,
			rvprop: 'content'
		}, {
			ok: function () {
				var a = arguments ;
				if ( undefined === a || undefined === a.query ) return ;
				var pages = a.query.pages ;
				if ( undefined === pages ) return ;
				$.each ( pages , function ( page , data ) {
					var css = data.revisions ;
					mw.util.addCSS ( css ) ;
				} ) ;
			}
		} );		
		
		if ( use_css != ($.cookie( self.use_css_cookie)||'') ) {
			$('a').each ( function ( k , v ) {
				var href = $(v).attr('href') || '' ;
				if ( href.match ( /^\/wiki\// ) ) $(v).attr('href',href+'?useCSS='+use_css) ;
				else if ( href.match ( /^\/w\// ) ) $(v).attr('href',href+'&useCSS='+use_css) ;
			} ) ;
		} ;
	} ,

	options : function () {
		var self = this ;
		$('#live_ericsson_dialog').remove() ;
		var h = "<div id='live_ericsson_dialog' title='Live EriCSSon - Settings'>" ;

		h += "<div style='border-bottom:1px solid #DDDDDD;padding-bottom:5px;margin-bottom:5px'>" ;
		if ( self.isSet ( self.use_css ) ) {
			h += "Current CSS :<br/>" + self.use_css ;
			h += "<br/><a href='#' onclick='live_ericsson.makeCurrentDefault();return false'>Make default</a>" ;
			h += "<span id='live_ericsson_clear_link' style='display:none'> | <a href='#' onclick='live_ericsson.clearDefault();return false'>Clear current default</a></span>" ;
		} else {
			h += "<i>No CSS loaded</i>" ;
		}
		h += "</div>" ;
		
		h += "<div style='border-bottom:1px solid #DDDDDD;padding-bottom:5px;margin-bottom:5px'>" ;
		h += "Load CSS page:<br/>" ;
		h += "<input type='text' size='30' id='live_ericsson_text_input' value='User:Magnus_Manske/explosion.css' />" ;
		h += "<button onclick='live_ericsson.reloadPageWithNewCSS()'>Reload with this CSS</button>" ;
		h += "</div>" ;
		
		h += "<div id='live_ericsson_message'></div>" ;
		h += "</div>" ;
		$('body').append ( h ) ;
		$('#live_ericsson_dialog').dialog ( {
			open: function(event, ui) { $('#live_ericsson_dialog a').blur().css({'font-weight':'bold'}) ; }
		} ) ;

		var def = $.cookie( self.use_css_cookie ) ;
		if ( self.isSet ( def ) ) $('#live_ericsson_clear_link').show() ;

	} ,
	
	reloadPageWithNewCSS : function () {
		var ncss = $('#live_ericsson_text_input').val() ;
		var url = mw.util.getUrl ( mw.config.get( 'wgPageName' ) ) ;
		url += "?useCSS=" + ncss ;
		window.location.href = url ;
	} ,
	
	isSet : function ( x ) {
		if ( undefined === x ) return false ;
		if ( null === x ) return false ;
		if ( 'null' === x ) return false ;
		return true ;
	} ,
	
	clearDefault : function () {
		var self = this ;
		$.cookie( self.use_css_cookie , null , {
		 expires: 90, // days
		 path: '/' // domain-wide, entire wiki
		} );
		$('#live_ericsson_message').html ( "Default CSS has been removed for this wiki, for this computer." ) ;
		$('#live_ericsson_clear_link').hide() ;
//		console.log ( $.cookie( self.use_css_cookie ) ) ;
	} ,
	
	makeCurrentDefault : function () {
		var self = this ;
		$.cookie( self.use_css_cookie , self.use_css , {
		 expires: 90, // days
		 path: '/' // domain-wide, entire wiki
		} );
		$('#live_ericsson_message').html ( self.use_css + " is now default CSS for this wiki, on this computer." ) ;
		$('#live_ericsson_clear_link').show() ;
//		console.log ( $.cookie( self.use_css_cookie ) ) ;
	} ,
	
	getURLParameter : function(name) {
		return decodeURIComponent(
			(RegExp('\\b' + name + '=' + '(.+?)(&|$)').exec(location.search)||)
		);
	} ,

	the_end : ''
} ;

$( function () { live_ericsson.init () } ) ;