From 387de2629ae2da7fa47d568d8fe7fa755e359ccf Mon Sep 17 00:00:00 2001 From: Ori Livneh Date: Sun, 22 Sep 2013 18:20:25 -0700 Subject: [PATCH] resourceloader: Pass jQuery twice to 'implements' module wrapper 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 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/resources/mediawiki/mediawiki.js b/resources/mediawiki/mediawiki.js index 65380b0e5e..5fbcd32181 100644 --- a/resources/mediawiki/mediawiki.js +++ b/resources/mediawiki/mediawiki.js @@ -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 ) { -- 2.20.1