Blame view
app/bower_components/jquery/src/core/ready.js
2.2 KB
|
87c93a029
|
1 |
define( [ |
|
f986e111b
|
2 |
"../core", |
|
87c93a029
|
3 4 |
"../var/document", "../core/readyException", |
|
f986e111b
|
5 |
"../deferred" |
|
87c93a029
|
6 7 8 |
], function( jQuery, document ) {
"use strict";
|
|
f986e111b
|
9 10 |
// The deferred used on DOM ready |
|
87c93a029
|
11 |
var readyList = jQuery.Deferred(); |
|
f986e111b
|
12 13 |
jQuery.fn.ready = function( fn ) {
|
|
87c93a029
|
14 15 16 17 18 19 20 21 22 23 |
readyList
.then( fn )
// Wrap jQuery.readyException in a function so that the lookup
// happens at the time of error handling instead of callback
// registration.
.catch( function( error ) {
jQuery.readyException( error );
} );
|
|
f986e111b
|
24 25 26 |
return this; }; |
|
87c93a029
|
27 |
jQuery.extend( {
|
|
f986e111b
|
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
// 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 ) {
jQuery.readyWait++;
} else {
jQuery.ready( true );
}
},
// Handle when the DOM is ready
ready: function( wait ) {
// Abort if there are pending holds or we're already ready
if ( wait === true ? --jQuery.readyWait : jQuery.isReady ) {
return;
}
|
|
f986e111b
|
51 52 53 54 55 56 57 58 59 60 |
// Remember that the DOM is ready
jQuery.isReady = true;
// If a normal DOM Ready event fired, decrement, and wait if need be
if ( wait !== true && --jQuery.readyWait > 0 ) {
return;
}
// If there are functions bound, to execute
readyList.resolveWith( document, [ jQuery ] );
|
|
f986e111b
|
61 |
} |
|
87c93a029
|
62 63 64 |
} ); jQuery.ready.then = readyList.then; |
|
f986e111b
|
65 |
|
|
87c93a029
|
66 |
// The ready event handler and self cleanup method |
|
f986e111b
|
67 |
function completed() {
|
|
87c93a029
|
68 69 70 |
document.removeEventListener( "DOMContentLoaded", completed ); window.removeEventListener( "load", completed ); jQuery.ready(); |
|
f986e111b
|
71 |
} |
|
87c93a029
|
72 73 74 75 76 77 |
// Catch cases where $(document).ready() is called
// after the browser event has already occurred.
// Support: IE <=9 - 10 only
// Older IE sometimes signals "interactive" too soon
if ( document.readyState === "complete" ||
( document.readyState !== "loading" && !document.documentElement.doScroll ) ) {
|
|
f986e111b
|
78 |
|
|
87c93a029
|
79 80 |
// Handle it asynchronously to allow scripts the opportunity to delay ready window.setTimeout( jQuery.ready ); |
|
f986e111b
|
81 |
|
|
87c93a029
|
82 |
} else {
|
|
f986e111b
|
83 |
|
|
87c93a029
|
84 85 |
// Use the handy event callback document.addEventListener( "DOMContentLoaded", completed ); |
|
f986e111b
|
86 |
|
|
87c93a029
|
87 88 89 |
// A fallback to window.onload, that will always work window.addEventListener( "load", completed ); } |
|
f986e111b
|
90 |
|
|
87c93a029
|
91 |
} ); |