diff --git a/isso/js/app/lib/ready.js b/isso/js/app/lib/ready.js new file mode 100644 index 0000000..3458eee --- /dev/null +++ b/isso/js/app/lib/ready.js @@ -0,0 +1,28 @@ +define(function() { + + "use strict"; + + var loaded = false; + var once = function(callback) { + if (! loaded) { + loaded = true; + callback(); + } + }; + + var domready = function(callback) { + + // HTML5 standard to listen for dom readiness + document.addEventListener('DOMContentLoaded', function() { + once(callback); + }); + + // if dom is already ready, just run callback + if (document.readyState === "interactive" || document.readyState === "complete" ) { + once(callback); + } + }; + + return domready; + +}); \ No newline at end of file diff --git a/isso/js/config.js b/isso/js/config.js index 7abcb01..70e6408 100644 --- a/isso/js/config.js +++ b/isso/js/config.js @@ -1,7 +1,6 @@ var requirejs = { paths: { text : "components/requirejs-text/text", - ready: "components/requirejs-domready/domReady" }, config: { diff --git a/isso/js/count.js b/isso/js/count.js index 633da8f..e9f2236 100644 --- a/isso/js/count.js +++ b/isso/js/count.js @@ -1,4 +1,4 @@ -require(["ready", "app/count"], function(domready, count) { +require(["app/lib/ready", "app/count"], function(domready, count) { domready(function() { count(); }) diff --git a/isso/js/embed.js b/isso/js/embed.js index 59f825f..6c6fbfc 100644 --- a/isso/js/embed.js +++ b/isso/js/embed.js @@ -3,7 +3,7 @@ * Distributed under the MIT license */ -require(["ready", "app/config", "app/api", "app/isso", "app/count", "app/dom", "app/markup", "app/text/css"], function(domready, config, api, isso, count, $, Mark, css) { +require(["app/lib/ready", "app/config", "app/api", "app/isso", "app/count", "app/dom", "app/markup", "app/text/css"], function(domready, config, api, isso, count, $, Mark, css) { "use strict";