vendor: 3,081 bytes, lines 1-72
1(function(funcName, baseObj) { 2 // The public function name defaults to window.docReady 3 // but you can pass in your own object and own function name and those will be used 4 // if you want to put them in a different namespace 5 funcName = funcName || "docReady"; 6 baseObj = baseObj || window; 7 var readyList = []; 8 var readyFired = false; 9 var readyEventHandlersInstalled = false; 10 11 // call this when the document is ready 12 // this function protects itself against being called more than once 13 function ready() { 14 if (!readyFired) { 15 // this must be set to true before we start calling callbacks 16 readyFired = true; 17 for (var i = 0; i < readyList.length; i++) { 18 // if a callback here happens to add new ready handlers, 19 // the docReady() function will see that it already fired 20 // and will schedule the callback to run right after 21 // this event loop finishes so all handlers will still execute 22 // in order and no new ones will be added to the readyList 23 // while we are processing the list 24 readyList[i].fn.call(window, readyList[i].ctx); 25 } 26 // allow any closures held by these functions to free 27 readyList = []; 28 } 29 } 30 31 function readyStateChange() { 32 if ( document.readyState === "complete" ) { 33 ready(); 34 } 35 } 36 37 // This is the one public interface 38 // docReady(fn, context); 39 // the context argument is optional - if present, it will be passed 40 // as an argument to the callback 41 baseObj[funcName] = function(callback, context) { 42 if (typeof callback !== "function") { 43 throw new TypeError("callback for docReady(fn) must be a function"); 44 } 45 // if ready has already fired, then just schedule the callback 46 // to fire asynchronously, but right away 47 if (readyFired) { 48 setTimeout(function() {callback(context);}, 1); 49 return; 50 } else { 51 // add the function and context to the list 52 readyList.push({fn: callback, ctx: context}); 53 } 54 // if document already ready to go, schedule the ready function to run 55 if (document.readyState === "complete") { 56 setTimeout(ready, 1); 57 } else if (!readyEventHandlersInstalled) { 58 // otherwise if we don't have event handlers installed, install them 59 if (document.addEventListener) { 60 // first choice is DOMContentLoaded event 61 document.addEventListener("DOMContentLoaded", ready, false); 62 // backup is window load event 63 window.addEventListener("load", ready, false); 64 } else { 65 // must be IE 66 document.attachEvent("onreadystatechange", readyStateChange); 67 window.attachEvent("onload", ready); 68 } 69 readyEventHandlersInstalled = true; 70 } 71 } 72})("gkitWinReady", window);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.