resourceloader: Pass jQuery twice to 'implements' module wrapper
authorOri Livneh <ori@wikimedia.org>
Mon, 23 Sep 2013 01:20:25 +0000 (18:20 -0700)
committerKrinkle <krinklemail@gmail.com>
Tue, 11 Mar 2014 23:05:55 +0000 (23:05 +0000)
This must be done in two parts. A follow-up change will update the wrapper
signature in ResourceLoader::makeLoaderImplementScript to bind the
arguments to '$' and 'jQuery'.

Because almost all event-handling and DOM interaction is mediated by
jQuery, ResourceLoader could provide a per-module breakdown of the work
performed on each page view by passing each module a copy of the jQuery
object that wraps certain functions (like jQuery.fn.on) in module-aware
profiling code. I expect that profiling would only be enabled on a small
fraction of requests. The effect on ordinary page-views would be a
possible small speed-up as a result of jQuery look-ups resolving in
module (rather than global) scope, but I expect the difference to be
neglible and it is not a part of my motivation.

Because ResourceLoader must bind both '$' and 'jQuery' to module scope,
we pass jQuery twice. A separate commit will update the wrapper function's
signature in ResourceLoader::makeLoaderImplementScript. This has to happen
separately to ensure that no module binds jQuery to undefined due to
being loaded by an out-of-sync version of mediawiki.js.

Change-Id: I0c9edac359ceb16fc273de1e51ea70322f18353e

resources/mediawiki/mediawiki.js

index 65380b0..5fbcd32 100644 (file)
@@ -1115,7 +1115,9 @@ var mw = ( function ( $, undefined ) {
                                                        nestedAddScript( script, markModuleReady, registry[module].async, 0 );
                                                } else if ( $.isFunction( script ) ) {
                                                        registry[module].state = 'ready';
-                                                       script( $ );
+                                                       // Pass jQuery twice so that the signature of the closure which wraps
+                                                       // the script can bind both '$' and 'jQuery'.
+                                                       script( $, $ );
                                                        handlePending( module );
                                                }
                                        } catch ( e ) {