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
This commit is contained in:
Martin Zimmermann 2014-02-03 10:54:54 +01:00
parent cfbf595605
commit 1c3c826ada
4 changed files with 30 additions and 3 deletions

28
isso/js/app/lib/ready.js Normal file
View File

@ -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;
});

View File

@ -1,7 +1,6 @@
var requirejs = { var requirejs = {
paths: { paths: {
text : "components/requirejs-text/text", text : "components/requirejs-text/text",
ready: "components/requirejs-domready/domReady"
}, },
config: { config: {

View File

@ -1,4 +1,4 @@
require(["ready", "app/count"], function(domready, count) { require(["app/lib/ready", "app/count"], function(domready, count) {
domready(function() { domready(function() {
count(); count();
}) })

View File

@ -3,7 +3,7 @@
* Distributed under the MIT license * 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"; "use strict";