dever 7 years ago
parent
commit
6086db3aec
1 changed files with 35 additions and 10 deletions
  1. 35 10
      front/static/document.js

+ 35 - 10
front/static/document.js

@@ -32,26 +32,34 @@ var Document =
     Init : function(option)
     {
         var self = this;
+        var callback = function() {
+            var cb = function() {
+                var index = layer.load(0, {shade: false});
+                $(window).load(function()
+                {
+                    self.Onload(index);
+                });
+            }
+            if (typeof(layer) != 'object') {
+                self.Script('layer/layer', cb);
+            } else {
+                cb();
+            }
+        }
         if (typeof($) != 'object') {
             self.Script('jquery');
+        } else {
+            callback();
         }
-        if (typeof(layer) != 'object') {
-            self.Script('layer/layer');
-        }
-        var index = layer.load(0, {shade: false});
-        $(window).load(function()
-        {
-            self.Onload(index);
-        });
     }
 
-    ,Script : function(name)
+    ,Script : function(name, callback)
     {
         var self = this;
         if (!self.path) {
             $('script').each(function()
             {
-                if ($(this).attr('src').indexOf('document.js') != -1) {
+                if ($(this).attr('src') && $(this).attr('src').indexOf('document.js') != -1) {
                     path = $(this).attr('src').split('document.js');
                     self.path = path[0];
                 }
@@ -59,8 +67,25 @@ var Document =
         }
         var script = document.createElement("script");
         script.type = "text/javascript";
+        script.async = 'async';
         script.src = self.path + name + ".js";
         document.getElementsByTagName('head')[0].appendChild(script);
+        if (script.readyState) {
+            script.onreadystatechange=function() {
+                if (script.readyState == 'complete'|| script.readyState == 'loaded') {
+                    script.onreadystatechange=null;
+                    callback();
+                }
+            }
+        } else {
+            script.onload = function(){callback();}
+        }
+    }
+
+    ,Sleep : function(n)
+    {
+        var start = new Date().getTime();
+        while (true) if (new Date().getTime() - start > n) break;
     }
 
     ,Onload : function(index)