ie_onReady

<html>
<head>
<title>Panel</title>
<script type=”text/javascript”>
     
Crab = {};
Crab.util = {};//把Namespace模拟出来
(function(){
    Crab.util.Event = function(obj, name){
        this.name = name;
        this.obj = obj;
        this.listeners = [];
    };
    Crab.util.Event.prototype = {
        addListener : function(fn){
            if(!this.isListening(fn)){
                var l = this.createListener(fn);
                if(!this.firing){
                    this.listeners.push(l);
                }else{ // if we are currently firing this event, don’t disturb the listener loop
                    this.listeners = this.listeners.slice(0);
                    this.listeners.push(l);
                }
            }
        },
        createListener : function(fn){
            var l = {
    fn:fn,
    fireFn:fn
   };
            return l;
        },
        findListener : function(fn){
            var ls = this.listeners;
            for(var i = 0, len = ls.length; i < len; i++){
                var l = ls[i];
                if(l.fn == fn){
                    return i;
                }
            }
            return -1;
        },
        isListening : function(fn){
            return this.findListener(fn) != -1;
        },
        clearListeners : function(){
            this.listeners = [];
        },
        fire : function(){
            var ls = this.listeners, len = ls.length;
            if(len > 0){
                this.firing = true;
                var args = Array.prototype.slice.call(arguments, 0);
                for(var i = 0; i < len; i++){
                    var l = ls[i];
                    if(l.fireFn.apply(window, arguments) === false){
                        this.firing = false;
                        return false;
                    }
                }
                this.firing = false;
            }
            return true;
        }
    };
})();
    
Crab.EventManager = function(){
 var docReadyEvent, docReadyProcId, docReadyState = false;
 
    var fireDocReady = function(){
        if(!docReadyState){
            docReadyState = true;
    
    ////////////////ie写法
                var defer = document.getElementById(“ie-deferred-loader”);
                if(defer){
                    defer.onreadystatechange = null;
                    defer.parentNode.removeChild(defer);
                }
    //////////////////////
            if(docReadyEvent){
                docReadyEvent.fire();
                docReadyEvent.clearListeners();
            }
        }
    }; 
 
    var initDocReady = function(){
        docReadyEvent = new Crab.util.Event();
   
   //////////////////////ie写法
            document.write(“<s”+’cript id=”ie-deferred-loader” defer=”defer” src=”/’+’/:”></s’+”cript>”);
            var defer = document.getElementById(“ie-deferred-loader”);
            defer.onreadystatechange = function(){
                if(this.readyState == “complete”){
                    fireDocReady();
                }
            };
   ///////////////////////////
        // no matter what, make sure it fires on load
        //E.on(window, “load”, fireDocReady);
    };
 
    var pub = {
        onDocumentReady : function(fn){
            if(docReadyState){ // if it already fired
                docReadyEvent.addListener(fn, scope, options);
                docReadyEvent.fire();
                docReadyEvent.clearListeners();
                return;
            }
            if(!docReadyEvent){
                initDocReady();
            }
            docReadyEvent.addListener(fn);
        }
 }
 return pub;
 
}();
Crab.onReady = Crab.EventManager.onDocumentReady;
Crab.onReady(function(){
 alert(‘hello crabone.com’);
});
  
</script>
</head>
<body>
</body>
</html>


网易邮箱,中国第一大电子邮件服务商

发表评论