]> source.dussan.org Git - jquery.git/commitdiff
Core: allow init to accept an alternate rootjQuery for migrate's sake
authorTimmy Willison <timmywillisn@gmail.com>
Mon, 4 May 2015 22:16:28 +0000 (15:16 -0700)
committerTimmy Willison <timmywillisn@gmail.com>
Mon, 4 May 2015 22:16:28 +0000 (15:16 -0700)
- This will be tested in migrate

Fixes gh-2101

src/core/init.js

index f49b560b69b848bc8356a44bc7fcf511a8be670c..861cb835152afd889ae9673c462c7b66b164c255 100644 (file)
@@ -15,7 +15,7 @@ var rootjQuery,
        // Shortcut simple #id case for speed
        rquickExpr = /^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]+))$/,
 
-       init = jQuery.fn.init = function( selector, context ) {
+       init = jQuery.fn.init = function( selector, context, root ) {
                var match, elem;
 
                // HANDLE: $(""), $(null), $(undefined), $(false)
@@ -23,6 +23,10 @@ var rootjQuery,
                        return this;
                }
 
+               // init accepts an alternate rootjQuery
+               // so migrate can support jQuery.sub (gh-2101)
+               root = root || rootjQuery;
+
                // Handle HTML strings
                if ( typeof selector === "string" ) {
                        if ( selector[0] === "<" &&
@@ -81,7 +85,7 @@ var rootjQuery,
 
                        // HANDLE: $(expr, $(...))
                        } else if ( !context || context.jquery ) {
-                               return ( context || rootjQuery ).find( selector );
+                               return ( context || root ).find( selector );
 
                        // HANDLE: $(expr, context)
                        // (which is just equivalent to: $(context).find(expr)
@@ -98,8 +102,8 @@ var rootjQuery,
                // HANDLE: $(function)
                // Shortcut for document ready
                } else if ( jQuery.isFunction( selector ) ) {
-                       return rootjQuery.ready !== undefined ?
-                               rootjQuery.ready( selector ) :
+                       return root.ready !== undefined ?
+                               root.ready( selector ) :
                                // Execute immediately if ready is not present
                                selector( jQuery );
                }