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:
parent
cfbf595605
commit
1c3c826ada
28
isso/js/app/lib/ready.js
Normal file
28
isso/js/app/lib/ready.js
Normal 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;
|
||||||
|
|
||||||
|
});
|
@ -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: {
|
||||||
|
@ -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();
|
||||||
})
|
})
|
||||||
|
@ -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";
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user