From 1c3c826ada23f9a712698184c9d5582c3400fa4a Mon Sep 17 00:00:00 2001 From: Martin Zimmermann Date: Mon, 3 Feb 2014 10:54:54 +0100 Subject: [PATCH] replace requirejs-domready with a (self-made) HTML5 idiom, #51 This commit removes yet another dependency. The provided domready function is compatible with IE9, Firefox and Safari/Chrome. Inspired by: * http://stackoverflow.com/a/15580098 * https://github.com/requirejs/domReady/blob/master/domReady.js --- isso/js/app/lib/ready.js | 28 ++++++++++++++++++++++++++++ isso/js/config.js | 1 - isso/js/count.js | 2 +- isso/js/embed.js | 2 +- 4 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 isso/js/app/lib/ready.js 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";