Skip to content
Permalink
Browse files

Retooled the arguments.callee-related changes in 98ce35d to avoid re-…

…declarations where possible.
  • Loading branch information
jeresig committed Dec 16, 2009
1 parent fe9333c commit 9997620420ec0baf7dba8ce9dee0f19e616e1bc4
Showing with 57 additions and 31 deletions.
  1. +48 −29 src/core.js
  2. +9 −2 src/event.js
@@ -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,
@@ -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 );
}
@@ -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 );
@@ -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 );
@@ -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();
}
}
}
},
@@ -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({
@@ -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.

0 comments on commit 9997620

Please sign in to comment.
You can’t perform that action at this time.