Browse Source

added new option: draggable

andrew 12 years ago
parent
commit
03764e6968
1 changed files with 27 additions and 1 deletions
  1. 27 1
      js/bootstrap-dialog.js

+ 27 - 1
js/bootstrap-dialog.js

@@ -27,7 +27,8 @@ var BootstrapDialog = null;
             data: {},
             onshow: null,
             onhide: null,
-            autodestroy: true
+            autodestroy: true,
+            draggable: true
         };
         this.indexedButtons = {};
         this.registeredButtonHotkeys = {};
@@ -108,6 +109,31 @@ var BootstrapDialog = null;
             .append(this.getModalBody())
             .append(this.getModalFooter());
 
+            var _isMouseDown = false;
+            var _self = this;
+            var _mouseOffset = {};
+            if (this.options.draggable) {
+                this.getModalHeader().on('mousedown', function (event) {
+                    _isMouseDown = true;
+                    var _dialogOffset = _self.getModalContent().offset();
+                    _mouseOffset = {
+                        top: event.clientY - _dialogOffset.top,
+                        left: event.clientX - _dialogOffset.left
+                    }
+                });
+                this.getModal().on('mouseup mouseleave', function () {
+                    _isMouseDown = false;
+                });
+                $('body').on('mousemove', function (event) {
+                    if (!_isMouseDown)
+                        return;
+                    _self.getModalContent().offset({
+                        top: event.clientY - _mouseOffset.top,
+                        left: event.clientX - _mouseOffset.left,
+                    });
+                });
+            }
+
             return this;
         },
         createModal: function() {