rabin 7 years ago
parent
commit
0757c0fca8
1 changed files with 60 additions and 37 deletions
  1. 60 37
      assets/dever/core.js

+ 60 - 37
assets/dever/core.js

@@ -29,6 +29,7 @@ $(function()
 var Dever = 
 {
     countdown : -1,
+    modal : false,
     Init : function()
     {
         this.Import();
@@ -226,7 +227,11 @@ var Dever =
             location.href = href;
             return;
         } else {
-            this.Modal().Alert(content, {'yes':callback, 'no':callback}, title);
+            if (this.modal) {
+                this.model.Alert(content, {'yes':callback, 'no':callback}, title);
+            } else {
+                this.Modal().Alert(content, {'yes':callback, 'no':callback}, title);
+            }
         }
     }
 
@@ -270,7 +275,11 @@ var Dever =
 
     ,Confirm : function(content, callback, title)
     {
-        this.Modal().Confirm(content, {'yes':callback}, title);
+        if (this.modal) {
+            this.model.Confirm(content, {'yes':callback}, title);
+        } else {
+            this.Modal().Confirm(content, {'yes':callback}, title);
+        }
     }
     
     ,Extend : function()
@@ -381,20 +390,24 @@ var _Dever_Modal =
     Init : function()
     {
         this.state = false;
-        if (this.html && this.box && this.content) {
+        if (this.html) {
             $('body').append(this.html);
+        }
+        if (this.box && this.content) {
             this.box = $(this.box);
-            this.box.hide();
-            this.content = $(this.content);
-
-            if(this.title) this.title = $(this.title);
-            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;
+            if (this.box.length) {
+                this.box.hide();
+                this.content = $(this.content);
+
+                if(this.title) this.title = $(this.title);
+                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;
+            }
         }
     }
     
@@ -560,30 +573,34 @@ var _Dever_User =
                 for (var i in config.input) {
                     var option = false;
                     var input = config.input[i];
-                    if (input.indexOf('|') != -1) {
-                        var t = input.split('|');
-                        input = t[0];
-                        option = true;
-                    }
-                    var m = true;
-                    var el = $(input);
-                    //e.get(0).tagName == 'TEXTAREA'
-                    send[i] = el.val();
-
-                    if (option == false) {
-                        if (send[i] && el.attr('dever-match')) {
-                            var r = new RegExp(el.attr('dever-match'));
-                            m = r.test(send[i]);
+                    if (typeof(input) == 'object') {
+                        send[i] = input();
+                    } else {
+                        if (input.indexOf('|') != -1) {
+                            var t = input.split('|');
+                            input = t[0];
+                            option = true;
                         }
+                        var m = true;
+                        var el = $(input);
+                        //e.get(0).tagName == 'TEXTAREA'
+                        send[i] = el.val();
+
+                        if (option == false) {
+                            if (send[i] && el.attr('dever-match')) {
+                                var r = new RegExp(el.attr('dever-match'));
+                                m = r.test(send[i]);
+                            }
 
-                        if (send[i] && el.attr('dever-value')) {
-                            m = $(el.attr('dever-value')).val() == send[i];
-                        }
+                            if (send[i] && el.attr('dever-value')) {
+                                m = $(el.attr('dever-value')).val() == send[i];
+                            }
 
-                        if (!send[i] || m != true) {
-                            var error = el.attr('dever-error') ? el.attr('dever-error') : config.error;
-                            callback(error);
-                            return;
+                            if (!send[i] || m != true) {
+                                var error = el.attr('dever-error') ? el.attr('dever-error') : config.error;
+                                callback(error);
+                                return;
+                            }
                         }
                     }
                 }
@@ -845,7 +862,10 @@ var _Dever_Upload =
                             } else {
                                 html += '<li><img src="'+data.url+'" class="pics"><em class="dever-upload-close"></em></li>';
                             }
-                            e.before(html);
+
+                            if (html) {
+                                e.before(html);
+                            }
                             self.Close(value);
 
                             self.upload_pic[value].push(data.url);
@@ -857,7 +877,10 @@ var _Dever_Upload =
                             } else {
                                 html = '<img src="'+data.url+'" class="pics">';
                             }
-                            e.html(html);
+
+                            if (html) {
+                                e.html(html);
+                            }
                         }
                     } else {
                         layer.msg(data.msg, {icon: 4});