ui / drag windows

This commit is contained in:
Val Erastov 2016-02-19 21:24:42 -08:00
parent ae8bc2ef0a
commit 8c4a903351

View file

@ -4,7 +4,8 @@ TCAD.ui = {};
TCAD.ui.Window = function(el, winManager) {
this.root = el;
var root = this.root;
this.root.find('.tool-caption').each(function() {
var caption = this.root.find('.tool-caption');
caption.each(function() {
var closeBtn = '<span class="btn rm" style="float: right;"><i class="fa fa-remove"></i></span>';
$(this).append(closeBtn);
});
@ -13,6 +14,7 @@ TCAD.ui.Window = function(el, winManager) {
});
var DIRS = TCAD.ui.DIRECTIONS;
winManager.registerResize(this.root, DIRS.NORTH | DIRS.SOUTH | DIRS.WEST | DIRS.EAST);
winManager.registerDrag(this.root, caption);
};
TCAD.ui.WinManager = function() {
@ -29,6 +31,16 @@ TCAD.ui.WinManager = function() {
});
};
TCAD.ui.WinManager.prototype.captureDrag = function(el, e) {
var origin = {x : e.pageX, y : e.pageY};
var originLocation = el.offset();
this.moveHandler = function(e) {
var dx = e.pageX - origin.x;
var dy = e.pageY - origin.y;
el.offset({left : originLocation.left + dx, top : originLocation.top + dy});
};
};
TCAD.ui.WinManager.prototype.captureResize = function(el, dirMask, e, onResize) {
var origin = {x : e.pageX, y : e.pageY};
@ -155,6 +167,13 @@ TCAD.ui.WinManager.prototype.registerResize = function(el, dirMask, onResize) {
});
};
TCAD.ui.WinManager.prototype.registerDrag = function(el, dragger) {
var wm = this;
dragger.mousedown(function(e) {
wm.captureDrag(el, e);
});
};
TCAD.ui.bindOpening = function(btn, win) {
btn.click(function(e) {