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