| 1 | define( [
|
| 2 | "../core",
|
| 3 | "../var/document",
|
| 4 | "../var/isFunction"
|
| 5 | ], function( jQuery, document, isFunction ) {
|
| 6 |
|
| 7 | "use strict";
|
| 8 |
|
| 9 | var readyCallbacks = [],
|
| 10 | whenReady = function( fn ) {
|
| 11 | readyCallbacks.push( fn );
|
| 12 | },
|
| 13 | executeReady = function( fn ) {
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 | window.setTimeout( function() {
|
| 18 | fn.call( document, jQuery );
|
| 19 | } );
|
| 20 | };
|
| 21 |
|
| 22 | jQuery.fn.ready = function( fn ) {
|
| 23 | whenReady( fn );
|
| 24 | return this;
|
| 25 | };
|
| 26 |
|
| 27 | jQuery.extend( {
|
| 28 |
|
| 29 |
|
| 30 | isReady: false,
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 | readyWait: 1,
|
| 35 |
|
| 36 | ready: function( wait ) {
|
| 37 |
|
| 38 |
|
| 39 | if ( wait === true ? --jQuery.readyWait : jQuery.isReady ) {
|
| 40 | return;
|
| 41 | }
|
| 42 |
|
| 43 |
|
| 44 | jQuery.isReady = true;
|
| 45 |
|
| 46 |
|
| 47 | if ( wait !== true && --jQuery.readyWait > 0 ) {
|
| 48 | return;
|
| 49 | }
|
| 50 |
|
| 51 | whenReady = function( fn ) {
|
| 52 | readyCallbacks.push( fn );
|
| 53 |
|
| 54 | while ( readyCallbacks.length ) {
|
| 55 | fn = readyCallbacks.shift();
|
| 56 | if ( isFunction( fn ) ) {
|
| 57 | executeReady( fn );
|
| 58 | }
|
| 59 | }
|
| 60 | };
|
| 61 |
|
| 62 | whenReady();
|
| 63 | }
|
| 64 | } );
|
| 65 |
|
| 66 |
|
| 67 | jQuery.ready.then = jQuery.fn.ready;
|
| 68 |
|
| 69 | |
| 70 | |
| 71 |
|
| 72 | function completed() {
|
| 73 | document.removeEventListener( "DOMContentLoaded", completed );
|
| 74 | window.removeEventListener( "load", completed );
|
| 75 | jQuery.ready();
|
| 76 | }
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 | if ( document.readyState === "complete" ||
|
| 83 | ( document.readyState !== "loading" && !document.documentElement.doScroll ) ) {
|
| 84 |
|
| 85 |
|
| 86 | window.setTimeout( jQuery.ready );
|
| 87 |
|
| 88 | } else {
|
| 89 |
|
| 90 |
|
| 91 | document.addEventListener( "DOMContentLoaded", completed );
|
| 92 |
|
| 93 |
|
| 94 | window.addEventListener( "load", completed );
|
| 95 | }
|
| 96 |
|
| 97 | } );
|