dever 7 years ago
parent
commit
8d6e4de1a0
1 changed files with 63 additions and 30 deletions
  1. 63 30
      assets/dever/core.js

+ 63 - 30
assets/dever/core.js

@@ -28,6 +28,7 @@ $(function()
 //公共类库
 var Dever = 
 {
+    countdown : -1,
     Init : function()
     {
         this.Import();
@@ -112,6 +113,27 @@ var Dever =
 		})
 	}
     
+    ,Time : function(e, time, text)
+    {
+        var self = this;
+        if (this.countdown < 0) {
+            this.countdown = time;
+        }
+        if (this.countdown == 0) {
+            e.attr("disabled", false);
+            e.html(text);
+            self.Init();
+            this.countdown = time;
+        } else {
+            e.attr("disabled", true);
+            e.html(this.countdown + 's后' + text);
+            this.countdown--;
+            e.unbind('click');
+            setTimeout(function() {
+                self.Time(e, time, text)
+            },1000)
+        }
+    }
     ,Import : function()
 	{
         var self = this;
@@ -197,20 +219,14 @@ var Dever =
     }
 
     // 输出数据,提示框
-    ,Out : function(content, callback, ele, title)
+    ,Out : function(content, callback, title)
     {
         if (content && content.indexOf('登录') != -1 && $("#login_url").length) {
             var href = $("#login_url").val();
             location.href = href;
             return;
         } else {
-            alert(content);
-
-            if (ele && callback) {
-                ele.unbind('click').bind('click', callback);
-            } else if (callback) {
-                callback();
-            }
+            this.Modal().Alert(content, {'yes':callback, 'no':callback}, title);
         }
     }
 
@@ -252,11 +268,9 @@ var Dever =
         }
     }
 
-    ,Confirm : function(callback)
+    ,Confirm : function(content, callback, title)
     {
-        if (confirm('确定进行此项操作吗?')) {
-            callback();
-        }
+        this.Modal().Confirm(content, {'yes':callback}, title);
     }
     
     ,Extend : function()
@@ -367,54 +381,67 @@ var _Dever_Modal =
     Init : function()
     {
         this.state = false;
-        if (this.html) {
+        if (this.html && this.box && this.content) {
             $('body').append(this.html);
-            if(this.box) this.box = $(this.box);
+            this.box = $(this.box);
+            this.box.hide();
+            this.content = $(this.content);
+
             if(this.title) this.title = $(this.title);
-            if(this.content) this.content = $(this.content);
             if(this.yes) this.yes = $(this.yes);
             if(this.no) this.no = $(this.no);
             if(this.setting) this.setting = $(this.setting);
             if(this.confirm) this.confirm = $(this.confirm);
+            if(!this.timeout) this.timeout = 3000;
 
             this.state = true;
         }
     }
     
-    ,Alert : function(content, callback)
+    ,Alert : function(content, callback, title)
     {
         if (this.state == false) {
             alert(content);
-            return;
+            if (callback) {
+                callback.yes();
+            }
         } else {
             if (this.setting.length && this.setting.html()) {
-                this.confirm.hide();
+                if (this.confirm) this.confirm.hide();
                 this.setting.show();
             } else {
-                this.setting.hide();
-                this.confirm.show();
+                if (this.setting) this.setting.hide();
+                if (this.confirm) this.confirm.show();
+            }
+            this.content.html(content);
+            if (title) {
+                this.title.html(title);
             }
-            this.title.html(content);
             this.box.show();
-            if (callback) {
+            if (callback.yes) {
                 this.Bind(callback);
+            } else {
+                this.TimeOut();
             }
         }
     }
     
-    ,Confirm : function(content, callback)
+    ,Confirm : function(content, callback, title)
     {
         if (this.state == false) {
-            alert(content);
-            return;
+            if (confirm(content)) {
+                callback.yes();
+            }
         } else {
-            this.confirm.show();
-            this.setting.hide();
+            if (this.confirm) this.confirm.show();
+            if (this.setting) this.setting.hide();
             
-            this.title.html(content);
+            this.content.html(content);
+            if (title) {
+                this.title.html(title);
+            }
             this.box.show();
-            if(callback)
-            {
+            if (callback.yes) {
                 this.Bind(callback);
             }
         }
@@ -438,6 +465,12 @@ var _Dever_Modal =
             }
         }
     }
+
+    ,TimeOut : function()
+    {
+        var self = this;
+        setTimeout(function(){self.Close()}, self.timeout);
+    }
     
     ,Close : function()
     {