MediaWiki:Gadget-CodePrettify.js: Difference between revisions

From Elwiki
mNo edit summary
mNo edit summary
Line 10: Line 10:


(function() {
(function() {
         $('pre').addClass('mw-code');
         $('pre').addClass('mw-code prettyprint linenums');
if ( wgPageName.match(/\.js$/) )  $('.mw-code').addClass('prettyprint linenums lang-js');
if ( wgPageName.match(/\.js$/) )  $('.mw-code').addClass('lang-js');
if ( wgPageName.match(/\.css$/) ) $('.mw-code').addClass('prettyprint linenums lang-css');
if ( wgPageName.match(/\.css$/) ) $('.mw-code').addClass('lang-css');
if ( $('.prettyprint').length > 0 ) {
if ( $('.prettyprint').length > 0 ) {
             importStylesheet('MediaWiki:Prettify.css');
             importStylesheet('MediaWiki:Prettify.css');
             $.cachedScript('//zh.moegirl.org/index.php?title=MediaWiki:Gadget-code-prettify-prettify.js&action=raw&ctype=text/javascript').done(function(){
             $.cachedScript(wgScriptPath + '/index.php?title=MediaWiki:Gadget-CodePrettifyMap.js&action=raw&ctype=text/javascript').done(function(){
                 prettyPrint();
                 prettyPrint();
             } );
             } );
}
}
})();
})();

Revision as of 06:43, 18 May 2015

/* 代码高亮  引自http://www.pokemon.name/wiki/MediaWiki:Common.js */
;jQuery.cachedScript = function(url, options) {
	options = $.extend(options || {}, {
		dataType: "script",
		cache: true,
		url: url
	});
	return jQuery.ajax(options);
};

(function() {
        $('pre').addClass('mw-code prettyprint linenums');
	if ( wgPageName.match(/\.js$/) )  $('.mw-code').addClass('lang-js');
	if ( wgPageName.match(/\.css$/) ) $('.mw-code').addClass('lang-css');
	if ( $('.prettyprint').length > 0 ) {
            importStylesheet('MediaWiki:Prettify.css');
            $.cachedScript(wgScriptPath + '/index.php?title=MediaWiki:Gadget-CodePrettifyMap.js&action=raw&ctype=text/javascript').done(function(){
                 prettyPrint();
            } );
	}
})();