(function(){
($try(function(){
temp.doScroll(‘left’);
return $(temp).inject(document.body).set(‘html’, ‘temp’).dispose();
})) ? domready() : arguments.callee.delay(50);
})();
} else if (Browser.Engine.webkit && Browser.Engine.version < 525){
(function(){
([‘loaded’, ‘complete’].contains(document.readyState)) ? domready() : arguments.callee.delay(50);
})();
} else {
window.addEvent(‘load’, domready);
document.addEvent(‘DOMContentLoaded’, domready);
}
})();
实现思路如下:
如果是IE则使用doScroll方法来实现。
如果是小于525版本的Webkit则通过轮询document.readyState来实现。
其他的(FF/Webkit高版/Opera)则直接注册DOMContentLoaded事件
Moontools的实现方案prototype和jQeury中的综合体,对webkit做了版本判断则使得该方案更加的健壮。在doScroll的实现方面,与jQuery相比,这里是新建了一个div元素,并且在使用完毕后进行销毁,而jQuery则直接使用了documentElement的 doScroll来检测,更简单高效一些。
四、Dojo
// START DOMContentLoaded
// Mozilla and Opera 9 expose the event we could use
if(document.addEventListener){
// NOTE:
// due to a threading issue in Firefox 2.0, we can’t enable
// DOMContentLoaded on that platform. For more information, see:
// http://trac.dojotoolkit.org/ticket/1704
if(dojo.isOpera || dojo.isFF >= 3 || (dojo.isMoz && dojo.config.enableMozDomContentLoaded === true)){
document.addEventListener(“DOMContentLoaded”, dojo._loadInit, null);
}
// mainly for Opera 8.5, won’t be fired if DOMContentLoaded fired already.
// also used for Mozilla because of trac #1640
window.addEventListener(“load”, dojo._loadInit, null);
}
if(dojo.isAIR){
window.addEventListener(“load”, dojo._loadInit, null);
}else if(/(WebKit|khtml)/i.test(navigator.userAgent)){ // sniff
dojo._khtmlTimer = setInterval(function(){
if(/loaded|complete/.test(document.readyState)){
dojo._loadInit(); // call the onload handler
}
}, 10);
}
// END DOMContentLoaded
(function(){
var _w = window;
var _handleNodeEvent = function(/*String*/evtName, /*Function*/fp){
// summary:
// non-destructively adds the specified function to the node’s
// evtName handler.
// evtName: should be in the form “onclick” for “onclick” handlers.
// Make sure you pass in the “on” part.
var oldHandler = _w[evtName] || function(){};
_w[evtName] = function(){
fp.apply(_w, arguments);
oldHandler.apply(_w, arguments);
};
};
if(dojo.isIE){
// for Internet Explorer. readyState will not be achieved on init
// call, but dojo doesn’t need it however, we’ll include it
// because we don’t know if there are other functions added that










