Commit f53aa62f authored by John Resig's avatar John Resig

Only bind .ready() once per instance of jQuery - and only bind if the ready()...

Only bind .ready() once per instance of jQuery - and only bind if the ready() method is actually called (nothing is bound if window/load is used).
parent 3fb4779a
...@@ -529,6 +529,9 @@ jQuery.fn.extend({ ...@@ -529,6 +529,9 @@ jQuery.fn.extend({
* @see $(Function) * @see $(Function)
*/ */
ready: function(f) { ready: function(f) {
// Attach the listeners
bindReady();
// If the DOM is already ready // If the DOM is already ready
if ( jQuery.isReady ) if ( jQuery.isReady )
// Execute the function immediately // Execute the function immediately
...@@ -928,7 +931,13 @@ jQuery.extend({ ...@@ -928,7 +931,13 @@ jQuery.extend({
}; };
}); });
var readyBound = false;
function bindReady(){
if ( readyBound ) return;
readyBound = true;
// If Mozilla is used // If Mozilla is used
if ( jQuery.browser.mozilla || jQuery.browser.opera ) if ( jQuery.browser.mozilla || jQuery.browser.opera )
// Use the handy event callback // Use the handy event callback
...@@ -974,3 +983,4 @@ jQuery.extend({ ...@@ -974,3 +983,4 @@ jQuery.extend({
// A fallback to window.onload, that will always work // A fallback to window.onload, that will always work
jQuery.event.add( window, "load", jQuery.ready ); jQuery.event.add( window, "load", jQuery.ready );
}
// prevent execution of jQuery if included more than once (function(){
if ( typeof jQuery == "undefined" ) (function(){
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment