mass的domReady方案

mass框架的domReady解决方案

 1 //mass的domReady方案
 2 var readyList = [];
 3 mass.ready = function(fn) {
 4     if (readyList) {
 5         fn.push(fn);
 6     } else {
 7         fn();
 8     }
 9 }
10 var readyFn, ready = W3C ? "DOMContentLoaded" : "readystatechange";
11 function fireReady() {
12     for (var i = 0, fn; fn = readyList[i++]; ) {
13         fn();
14     }
15     readyList = null;
16     fireReady = $.noop;    //惰性函数,防止IE9二次调用_checkDeps
17 }
18 
19 function doScrollCheck() {
20     try {    //IE下通过doScrollCheck检测DOM树是否建完
21         html.doScroll("left");
22         fireReady();
23     } catch (e) {
24         setTimeout(doScrollCheck);
25     }
26 }
27 
28 //在Firefix3.6之前,不存在readyState属性
29 if (!DOC.readyState) {
30     var readyState = DOC.readyState = DOC.body ? "complete" : "loading";
31 }
32 if (DOC.readyState === "complete") {
33     fireReady();    //如果在domReady之外加载
34 } else {
35     $.bind(DOC, ready, readyFn = function() {
36         if (W3C || DOC.readyState === "complete") {
37             fireReady();
38             if (readyState) {    //IE下不能改写DOC.readyState
39                 DOC.readyState = "complete";
40             }
41         }
42     });
43     if (html.doScroll) {
44         try {    //如果跨域会报错,那时肯定证明是存在两个窗口的
45             if (self.eavl === parent.eval) {
46                 doScrollCheck();
47             }
48         } catch (e) {
49             doScrollCheck();
50         }
51     }
52 }

 

你可能感兴趣的:(mass的domReady方案)