Difference between revisions of "MediaWiki:Common.js"
Kbjarkefur (talk | contribs) |
Kbjarkefur (talk | contribs) |
||
Line 29: | Line 29: | ||
var myElement = document.getElementById('mw-mywiki-example'); | var myElement = document.getElementById('mw-mywiki-example'); | ||
myElement.innerHTML = '<p>hello world</p>'; | myElement.innerHTML = '<p>hello world!</p>'; | ||
}()); | }()); |
Revision as of 14:16, 9 February 2017
/* Any JavaScript here will be loaded for all users on every page load. */
/**
* @source https://www.mediawiki.org/wiki/Snippets/Load_JS_and_CSS_by_URL
* @revision 2016-03-26
*/
mw.loader.using( ['mediawiki.util', 'mediawiki.notify'], function () {
var extraCSS = mw.util.getParamValue( 'withCSS' ),
extraJS = mw.util.getParamValue( 'withJS' );
if ( extraCSS ) {
if ( /^MediaWiki:[^&<>=%#]*\.css$/.test( extraCSS ) ) {
mw.loader.load( '/w/index.php?title=' + extraCSS + '&action=raw&ctype=text/css', 'text/css' );
} else {
mw.notify( 'Only pages from the MediaWiki namespace are allowed.', { title: 'Invalid withCSS value' } );
}
}
if ( extraJS ) {
if ( /^MediaWiki:[^&<>=%#]*\.js$/.test( extraJS ) ) {
mw.loader.load( '/w/index.php?title=' + extraJS + '&action=raw&ctype=text/javascript' );
} else {
mw.notify( 'Only pages from the MediaWiki namespace are allowed.', { title: 'Invalid withJS value' } );
}
}
});
$(function () {
var myElement = document.getElementById('mw-mywiki-example');
myElement.innerHTML = '<p>hello world!</p>';
}());