Skip to content

Commit

Permalink
Retooled the arguments.callee-related changes in 98ce35d to avoid re-…
Browse files Browse the repository at this point in the history
…declarations where possible.
  • Loading branch information
jeresig committed Dec 16, 2009
1 parent fe9333c commit 9997620
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 31 deletions.
77 changes: 48 additions & 29 deletions src/core.js
Expand Up @@ -41,6 +41,9 @@ var jQuery = function( selector, context ) {
// The functions to execute on DOM ready
readyList = [],

// The ready event handler
DOMContentLoaded,

// Save a reference to some core methods
toString = Object.prototype.toString,
hasOwnProperty = Object.prototype.hasOwnProperty,
Expand Down Expand Up @@ -347,6 +350,7 @@ jQuery.extend({
ready: function() {
// Make sure that the DOM is not already loaded
if ( !jQuery.isReady ) {
// Make sure body exists, at least, in case IE gets a little overzealous (ticket #5443).
if ( !document.body ) {
return setTimeout( jQuery.ready, 13 );
}
Expand Down Expand Up @@ -386,10 +390,7 @@ jQuery.extend({
// Mozilla, Opera and webkit nightlies currently support this event
if ( document.addEventListener ) {
// Use the handy event callback
document.addEventListener( "DOMContentLoaded", function DOMContentLoaded() {
document.removeEventListener( "DOMContentLoaded", DOMContentLoaded, false );
jQuery.ready();
}, false );
document.addEventListener( "DOMContentLoaded", DOMContentLoaded, false );

// A fallback to window.onload, that will always work
window.addEventListener( "load", jQuery.ready, false );
Expand All @@ -398,13 +399,7 @@ jQuery.extend({
} else if ( document.attachEvent ) {
// ensure firing before onload,
// maybe late but safe also for iframes
document.attachEvent("onreadystatechange", function onreadystatechange() {
// Make sure body exists, at least, in case IE gets a little overzealous (ticket #5443).
if ( document.readyState === "complete" ) {
document.detachEvent( "onreadystatechange", onreadystatechange );
jQuery.ready();
}
});
document.attachEvent("onreadystatechange", DOMContentLoaded);

// A fallback to window.onload, that will always work
window.attachEvent( "onload", jQuery.ready );
Expand All @@ -419,24 +414,6 @@ jQuery.extend({

if ( document.documentElement.doScroll && toplevel ) {
doScrollCheck();

function doScrollCheck() {
if ( jQuery.isReady ) {
return;
}

try {
// If IE is used, use the trick by Diego Perini
// http://javascript.nwbox.com/IEContentLoaded/
document.documentElement.doScroll("left");
} catch( error ) {
setTimeout( doScrollCheck, 1 );
return;
}

// and execute any waiting functions
jQuery.ready();
}
}
}
},
Expand Down Expand Up @@ -653,6 +630,48 @@ if ( indexOf ) {
// All jQuery objects should point back to these
rootjQuery = jQuery(document);

// Cleanup functions for the document ready method
if ( document.addEventListener ) {
DOMContentLoaded = function() {
document.removeEventListener( "DOMContentLoaded", DOMContentLoaded, false );
jQuery.ready();
};

} else if ( document.attachEvent ) {
DOMContentLoaded = function() {
// Make sure body exists, at least, in case IE gets a little overzealous (ticket #5443).
if ( document.readyState === "complete" ) {
document.detachEvent( "onreadystatechange", DOMContentLoaded );
jQuery.ready();
}
};
}

// The DOM ready check for Internet Explorer
function doScrollCheck() {
if ( jQuery.isReady ) {
return;
}

try {
// If IE is used, use the trick by Diego Perini
// http://javascript.nwbox.com/IEContentLoaded/
document.documentElement.doScroll("left");
} catch( error ) {
setTimeout( doScrollCheck, 1 );
return;
}

// and execute any waiting functions
jQuery.ready();
}

if ( indexOf ) {
jQuery.inArray = function( elem, array ) {
return indexOf.call( array, elem );
};
}

function evalScript( i, elem ) {
if ( elem.src ) {
jQuery.ajax({
Expand Down
11 changes: 9 additions & 2 deletions src/event.js
Expand Up @@ -37,13 +37,20 @@ jQuery.event = {

// Init the element's event structure
var events = jQuery.data( elem, "events" ) || jQuery.data( elem, "events", {} ),
handle = jQuery.data( elem, "handle" ) || jQuery.data( elem, "handle", function eventHandle() {
handle = jQuery.data( elem, "handle" ), eventHandle;

if ( !handle ) {
eventHandle = function() {
// Handle the second event of a trigger and when
// an event is called after a page has unloaded
return typeof jQuery !== "undefined" && !jQuery.event.triggered ?
jQuery.event.handle.apply( eventHandle.elem, arguments ) :
undefined;
});
};

handle = jQuery.data( elem, "handle", eventHandle );
}

// Add elem as a property of the handle function
// This is to prevent a memory leak with non-native
// event in IE.
Expand Down

0 comments on commit 9997620

Please sign in to comment.