From MediaWiki.org
Jump to: navigation, search

Other languages:
català • ‎Deutsch • ‎English • ‎British English • ‎español • ‎suomi • ‎français • ‎italiano • ‎日本語 • ‎polski • ‎português • ‎português do Brasil • ‎русский

We have been shipping the jQuery JavaScript library with MediaWiki since the 1.17 release.

Version[edit | edit source]

ResourceLoader[edit | edit source]

MediaWiki version: 1.17

As of MediaWiki 1.17 all resources are (or should be) loaded through ResourceLoader. The default modules are stored in /resources. There are no static minified versions anymore as ResourceLoader takes care of this when combing and optimizing all queued files.

However, if your site skin was created prior to 1.17, ResourceLoader will not be loaded and jQuery will not be available.

Before ResourceLoader[edit | edit source]

MediaWiki version: 1.16

MediaWiki 1.16 shipped with jQuery version 1.3.2 with some patches by Trevor Parscal and Roan Kattouw to fix jQuery bug #5081 (see r60697 and r61700).

In 1.16, the jQuery file is in skins/common/jquery.js and the minified version is jquery-min.js in the same directory.

Extensions can use OutputPage's includeJQuery method, which has existed since r61431, to avoid loading minified version of jQuery core multiple times. It should be noted that includeJQuery does not support jQuery plugins and such.

To include it, paste the following at the bottom of LocalSettings.php:

// Include jQuery
function wfIncludeJQuery() {
	global $wgOut;
$wgExtensionFunctions[] = 'wfIncludeJQuery';

MediaWiki 1.16: jQuery.noConflict[edit | edit source]

Please pay attention to the fact that, to avoid conflicts with other libraries (since it's not loaded by default in 1.16) jQuery will be loaded in noConflict()-mode into window.$j.

You can use either jQuery, $j or something like the following to locally wrap-alias it:

( function ( $ ) { 
        // Simple scope wrap, where $ is available as alias for jQuery.
        // Code here will be executed immediately
}( jQuery ) );
/* or */
jQuery( document ).ready( function ( $ ) { 
        // Code wrapped in this function will be executed when the document is ready
        // When the document is ready, jQuery calls this callback function with itself as
        // first parameter, allowing you to locally alias it (e.g. as "$")
} );

See also[edit | edit source]

External links[edit | edit source]