Plato on Github
Report Home
src/core/ready-no-deferred.js
Maintainability
70.52
Lines of code
111
Difficulty
31.50
Estimated Errors
0.46
Function weight
By Complexity
By SLOC
define( [ "../core", "../var/document" ], function( jQuery, document ) { "use strict"; var readyCallbacks = [], readyFiring = false, whenReady = function( fn ) { readyCallbacks.push( fn ); }, executeReady = function( fn ) { // Prevent errors from freezing future callback execution (gh-1823) // Not backwards-compatible as this does not execute sync window.setTimeout( function() { fn.call( document, jQuery ); } ); }; jQuery.fn.ready = function( fn ) { whenReady( fn ); return this; }; jQuery.extend( { // 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 ); } }, ready: function( wait ) { // Abort if there are pending holds or we're already ready if ( wait === true ? --jQuery.readyWait : jQuery.isReady ) { return; } // 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; } whenReady = function( fn ) { readyCallbacks.push( fn ); if ( !readyFiring ) { readyFiring = true; while ( readyCallbacks.length ) { fn = readyCallbacks.shift(); if ( jQuery.isFunction( fn ) ) { executeReady( fn ); } } readyFiring = false; } }; whenReady(); } } ); // Make jQuery.ready Promise consumable (gh-1778) jQuery.ready.then = jQuery.fn.ready; /** * The ready event handler and self cleanup method */ function completed() { document.removeEventListener( "DOMContentLoaded", completed ); window.removeEventListener( "load", completed ); jQuery.ready(); } // Catch cases where $(document).ready() is called // after the browser event has already occurred. // Support: IE9-10 only // Older IE sometimes signals "interactive" too soon if ( document.readyState === "complete" || ( document.readyState !== "loading" && !document.documentElement.doScroll ) ) { // Handle it asynchronously to allow scripts the opportunity to delay ready window.setTimeout( jQuery.ready ); } else { // Use the handy event callback document.addEventListener( "DOMContentLoaded", completed ); // A fallback to window.onload, that will always work window.addEventListener( "load", completed ); } } );