This repository has been archived by the owner on Dec 8, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 90
/
DragHandler.js
93 lines (77 loc) · 3.25 KB
/
DragHandler.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/**
* @author Swagatam Mitra
*/
/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */
/*global define, document, console, brackets, $, Mustache */
define(function (require, exports, module) {
"use strict";
var startOffset = null;
var isDragged = false;
var dragSourceArea = null;
var layout = null;
function _isPinInEventOnDragSource(point){
if(dragSourceArea){
if( point.x >= dragSourceArea.left && point.x <= dragSourceArea.right
&& point.y >= dragSourceArea.top && point.y <= dragSourceArea.bottom){
return true;
} else {
return false;
}
} else {
return false;
}
}
function _initDrag(event,element,point){
if(element && element.tagName !== 'BODY'){
$("#html-design-editor").trigger("design.editor.drag.activated");
if(_isPinInEventOnDragSource(point) || (layout && layout.boxModel && layout.boxModel.cssRuleSet.element === element)){
startOffset = point;
isDragged = false;
$('.controlDiv').css('pointer-events','none');
layout.open();
} /*else {
startOffset = point;
isDragged = false;
$('.controlDiv').css('pointer-events','none');
$("#html-design-editor").trigger("select.element",[element]);
setTimeout(function(){ layout.open();},50);
}*/
}
}
function _doDrag(event,element,point){
if(startOffset){
layout.changeX(startOffset.x - point.x);
layout.changeY(startOffset.y - point.y);
startOffset = point;
layout.refresh();
//dragSourceArea = element.getBoundingClientRect();
isDragged = true;
}
}
function _endDrag(event,element,point){
if(startOffset){
$("#html-design-editor").trigger("design.editor.drag.deactivated");
$("#hover-outline").hide();
startOffset = null;
isDragged = false;
$('.controlDiv').css('pointer-events','all');
dragSourceArea = element.getBoundingClientRect();
layout.close();
}
}
$(document).on("layout.decision","#html-design-editor", function(event,layoutObj){
layout = layoutObj;
});
$(document).on("grouplayout.decision","#html-design-editor", function(event,layoutObj){
layout = layoutObj;
});
$(document).on("element.selected","#html-design-editor",function(event,element){
dragSourceArea = element.getBoundingClientRect();
});
$(document).on("multiselectarea.computed","#html-design-editor",function(event,unionArea){
dragSourceArea = unionArea;
});
$(document).on("targetdom.element.mousedown","#html-design-editor", _initDrag);
$(document).on("targetdom.element.mousemove","#html-design-editor", _doDrag);
$(document).on("targetdom.element.mouseup targetdom.element.mouseout targetdom.element.mouseleave","#html-design-editor",_endDrag);
});