Skip to content

Commit

Permalink
Some overall robustness. More code commenting
Browse files Browse the repository at this point in the history
  • Loading branch information
tipiirai committed Mar 1, 2011
1 parent 4228e45 commit 1ef6250
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 40 deletions.
46 changes: 28 additions & 18 deletions dist/head.js
Expand Up @@ -2,7 +2,7 @@
Head JS The only script in your <HEAD>
Copyright Tero Piirainen (tipiirai)
License MIT / http://bit.ly/mit-license
Version 0.9
Version 0.92dev
http://headjs.com
*/
Expand Down Expand Up @@ -155,7 +155,7 @@
Head JS The only script in your <HEAD>
Copyright Tero Piirainen (tipiirai)
License MIT / http://bit.ly/mit-license
Version 0.9
Version 0.92dev
http://headjs.com
*/
Expand Down Expand Up @@ -295,7 +295,7 @@
Head JS The only script in your <HEAD>
Copyright Tero Piirainen (tipiirai)
License MIT / http://bit.ly/mit-license
Version 0.9
Version 0.92dev
http://headjs.com
*/
Expand Down Expand Up @@ -416,7 +416,8 @@

var script = scripts[key];

if (script && script.state == LOADED || key == 'ALL' && allLoaded()) {
// script already loaded --> execute and return
if (script && script.state == LOADED || key == 'ALL' && allLoaded()) {
one(fn);
return api;
}
Expand All @@ -431,7 +432,7 @@
// perform this when DOM is ready
api.ready(doc, function() {

if (allLoaded()) {
if (allLoaded()) {
each(handlers.ALL, function(fn) {
one(fn);
});
Expand Down Expand Up @@ -503,13 +504,11 @@

els = els || scripts;

var loaded = false,
count = 0;
var loaded;

for (var name in els) {
if (els[name].state != LOADED) { return false; }
loaded = true;
count++;
}

return loaded;
Expand Down Expand Up @@ -564,10 +563,10 @@
// handlers for this script
each(handlers[script.name], function(fn) {
one(fn);
});

});

if (allLoaded()) {
// everything ready
if (allLoaded() && isDomReady) {
each(handlers.ALL, function(fn) {
one(fn);
});
Expand Down Expand Up @@ -597,12 +596,10 @@
}


setTimeout(function() {
isHeadReady = true;
each(queue, function(fn) { fn(); });

}, 300);

/*
The much desired DOM ready check
Thanks to jQuery and http://javascript.nwbox.com/IEContentLoaded/
*/

function fireReady() {
if (!isDomReady) {
Expand All @@ -616,6 +613,8 @@
// W3C
if (window.addEventListener) {
doc.addEventListener("DOMContentLoaded", fireReady, false);

// fallback. this is always called
window.addEventListener("load", fireReady, false);

// IE
Expand All @@ -628,7 +627,6 @@
}
});

/* // http://javascript.nwbox.com/IEContentLoaded/ */

// avoid frames with different domains issue
var frameElement = 1;
Expand Down Expand Up @@ -667,5 +665,17 @@
}, false);
}

/*
We wait for 300 ms before script loading starts. for some reason this is needed
to make sure scripts are cached. Not sure why this happens yet. A case study:
https://github.com/headjs/headjs/issues/closed#issue/83
*/
setTimeout(function() {
isHeadReady = true;
each(queue, function(fn) { fn(); });

}, 300);

})(document);

4 changes: 2 additions & 2 deletions dist/head.load.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1ef6250

Please sign in to comment.