Difference between revisions of "MediaWiki:Common.js"
Jump to navigation
Jump to search
Line 1: | Line 1: | ||
/* Any JavaScript here will be loaded for all users on every page load. */ | /* Any JavaScript here will be loaded for all users on every page load. */ | ||
− | |||
− | var x = document.getElementsByClassName( | + | /** |
+ | * Keep code in MediaWiki:Common.js to a minimum as it is unconditionally | ||
+ | * loaded for all users on every wiki page. If possible create a gadget that is | ||
+ | * enabled by default instead of adding it here (since gadgets are fully | ||
+ | * optimized ResourceLoader modules with possibility to add dependencies etc.) | ||
+ | * | ||
+ | * Since Common.js isn't a gadget, there is no place to declare its | ||
+ | * dependencies, so we have to lazy load them with mw.loader.using on demand and | ||
+ | * then execute the rest in the callback. In most cases these dependencies will | ||
+ | * be loaded (or loading) already and the callback will not be delayed. In case a | ||
+ | * dependency hasn't arrived yet it'll make sure those are loaded before this. | ||
+ | */ | ||
+ | |||
+ | /* global mw, $ */ | ||
+ | /* jshint strict:false, browser:true */ | ||
+ | |||
+ | mw.loader.using( ['mediawiki.user', 'mediawiki.util', 'mediawiki.notify'] ).done( function () { | ||
+ | /* Begin of mw.loader.using callback */ | ||
+ | |||
+ | ( function () { | ||
+ | |||
+ | var x = document.getElementsByClassName("_2392"); | ||
var i; | var i; | ||
for (i = 0; i < x.length; i++) { | for (i = 0; i < x.length; i++) { | ||
Line 9: | Line 29: | ||
} | } | ||
− | }()); | + | } )(); |
+ | |||
+ | |||
+ | /* End of mw.loader.using callback */ | ||
+ | } ); |
Revision as of 21:49, 18 May 2018
/* Any JavaScript here will be loaded for all users on every page load. */
/**
* Keep code in MediaWiki:Common.js to a minimum as it is unconditionally
* loaded for all users on every wiki page. If possible create a gadget that is
* enabled by default instead of adding it here (since gadgets are fully
* optimized ResourceLoader modules with possibility to add dependencies etc.)
*
* Since Common.js isn't a gadget, there is no place to declare its
* dependencies, so we have to lazy load them with mw.loader.using on demand and
* then execute the rest in the callback. In most cases these dependencies will
* be loaded (or loading) already and the callback will not be delayed. In case a
* dependency hasn't arrived yet it'll make sure those are loaded before this.
*/
/* global mw, $ */
/* jshint strict:false, browser:true */
mw.loader.using( ['mediawiki.user', 'mediawiki.util', 'mediawiki.notify'] ).done( function () {
/* Begin of mw.loader.using callback */
( function () {
var x = document.getElementsByClassName("_2392");
var i;
for (i = 0; i < x.length; i++) {
x[i].style.display = "none";
}
} )();
/* End of mw.loader.using callback */
} );