(
function(window,document,UN){
document.ready = (
function(){
var readyList,
OBJ="object",OBJF="function",OBJA="array",STRC="complete",STRR="onreadystatechange",STRD="DOMContentLoaded",
// The ready event handler and self cleanup method
DOMContentLoaded =
function() {
if ( document.addEventListener ) {
document.removeEventListener( STRD, DOMContentLoaded,
false );
ReadyObj.ready();
}
else if ( document.readyState === STRC ) {
// we're here because readyState === "complete" in oldIE
// which is good enough for us to call the dom ready!
document.detachEvent( STRR, DOMContentLoaded );
ReadyObj.ready();
}
},
ReadyObj = {
// Is the DOM ready to be used? Set to true once it occurs.
isReady:
false,
// A counter to track how many items to wait for before
// the ready event fires. See #6781
readyWait: 1,
// Hold (or release) the ready event
holdReady:
function( hold ) {
if ( hold ) {
ReadyObj.readyWait++;
}
else {
ReadyObj.ready(
true );
}
},
// Handle when the DOM is ready
ready:
function( wait ) {
// Either a released hold or an DOMready/load event and not yet ready
if ( (wait ===
true && !--ReadyObj.readyWait) || (wait !==
true && !ReadyObj.isReady) ) {
// Make sure body exists, at least, in case IE gets a little overzealous (ticket #5443).
if ( !document.body ) {
return setTimeout( ReadyObj.ready, 1 );
}
// Remember that the DOM is ready
ReadyObj.isReady =
true;
// If a normal DOM Ready event fired, decrement, and wait if need be
if ( wait !==
true && --ReadyObj.readyWait > 0 ) {
return;
}
// If there are functions bound, to execute
readyList.resolveWith( document, [ ReadyObj ] );
// Trigger any bound ready events
//if ( ReadyObj.fn.trigger ) {
// ReadyObj( document ).trigger( "ready" ).unbind( "ready" );
//}
}
},
bindReady:
function() {
if ( readyList ) {
return;
}
readyList = ReadyObj._Deferred();
// Catch cases where $(document).ready() is called after the
// browser event has already occurred.
if ( document.readyState === STRC ) {
// Handle it asynchronously to allow scripts the opportunity to delay ready
setTimeout( ReadyObj.ready, 1 );
// Mozilla, Opera and webkit nightlies currently support this event
}
else if ( document.addEventListener ) {
// Use the handy event callback
document.addEventListener( STRD, DOMContentLoaded,
false );
// A fallback to window.onload, that will always work
window.addEventListener( "load", ReadyObj.ready,
false );
// If IE event model is used
}
else if ( document.attachEvent ) {
// ensure firing before onload,
// maybe late but safe also for iframes
document.attachEvent( STRR, DOMContentLoaded );
// A fallback to window.onload, that will always work
window.attachEvent( "onload", ReadyObj.ready );
// If IE and not a frame
// continually check to see if the document is ready
var top =
false;
try {
top = window.frameElement ==
null && document.documentElement;
}
catch(e) {}
if ( top && top.doScroll ) {
(
function doScrollCheck() {
if ( !ReadyObj.isReady ) {
try {
// Use the trick by Diego Perini
// http://javascript.nwbox.com/IEContentLoaded/
top.doScroll("left");
}
catch(e) {
return setTimeout( doScrollCheck, 50 );
}
// and execute any waiting functions
ReadyObj.ready();
}
})();
}
}
},
_Deferred:
function() {
var // callbacks list
callbacks = [],
// stored [ context , args ]
fired,
// to avoid firing when already doing so
firing,
// flag to know if the deferred has been cancelled
cancelled,
// the deferred itself
deferred = {
// done( f1, f2, )
done:
function() {
if ( !cancelled ) {
var args = arguments,
i,
length,
elem,
type,
_fired,
class2type = {};
class2type["["+OBJ+" Function]"] = OBJF;
class2type["["+OBJ+" Array]"] = OBJA;
if ( fired ) {
_fired = fired;
fired = 0;
}
for ( i = 0, length = args.length; i < length; i++ ) {
elem = args[ i ];
type=(elem ==
null ? String( elem ) : class2type[ Object.prototype.toString.call(elem) ] || OBJ);
if ( type === OBJA ) {
deferred.done.apply( deferred, elem );
}
else if ( type === OBJF ) {
callbacks.push( elem );
}
}
if ( _fired ) {
deferred.resolveWith( _fired[ 0 ], _fired[ 1 ] );
}
}
return this;
},
// resolve with given context and args
resolveWith:
function( context, args ) {
if ( !cancelled && !fired && !firing ) {
// make sure args are available (#8421)
args = args || [];
firing = 1;
try {
while( callbacks[ 0 ] ) {
callbacks.shift().apply( context, args );
//shifts a callback, and applies it to document
}
}
finally {
fired = [ context, args ];
firing = 0;
}
}
return this;
},
// resolve with this as context and given arguments
resolve:
function() {
deferred.resolveWith(
this, arguments );
return this;
},
// Has this deferred been resolved?
isResolved:
function() {
return !!( firing || fired );
},
// Cancel
cancel:
function() {
cancelled = 1;
callbacks = [];
return this;
}
};
return deferred;
}
};
return function( fn ) {
// Attach the listeners
ReadyObj.bindReady();
// Add the callback
readyList.done( fn );
//readyList is result of _Deferred()
};
})();
})(
this,document);