Jump to content

MediaWiki:Live EriCSSon.js: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
mNo edit summary
mNo edit summary
Line 18: Line 18:
var use_css = self.getURLParameter ( 'useCSS' ) ;
var use_css = self.getURLParameter ( 'useCSS' ) ;
if ( undefined === use_css ) return ;
if ( undefined === use_css ) return ;
if ( null == use_css ) return ;
if ( 'null' == use_css ) return ;
var api = new mw.Api();
var api = new mw.Api();
api.get( {
api.get( {

Revision as of 13:17, 16 July 2012

if ( typeof ( $ ) === 'undefined' ) $ = $j ;

var live_ericsson = {
	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 ( undefined === use_css ) return ;
		if ( 'null' == use_css ) return ;
		var api = new mw.Api();
		api.get( {
			action: 'query',
			prop: 'revisions' ,
			titles: use_css ,
			rvprop: 'content'
		}, {
			ok: function () {
				var a = arguments[0] ;
				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[0]['*'] ;
					mw.util.addCSS ( css ) ;
				} ) ;
			}
		} );		
		
		$('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 () {
	} ,
	
	getURLParameter : function(name) {
		return decodeURI(
			(RegExp('\\b' + name + '=' + '(.+?)(&|$)').exec(location.search)||[,null])[1]
		);
	} ,

	the_end : ''
} ;

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