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
/
AlignmentHandler.js
136 lines (117 loc) · 4.2 KB
/
AlignmentHandler.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/**
* @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 layout,
reference,
referenceElement;
function _alignLeft(){
if(layout){
layout.open();
if(referenceElement){
layout.changeLeftTo(referenceElement.getBoundingClientRect().left);
} else if(reference){
layout.changeLeftTo(reference.left);
}
layout.refresh();
layout.close();
$("#html-design-editor").trigger("groupReselect");
}
}
function _alignRight(){
if(layout){
layout.open();
if(referenceElement){
layout.changeRightTo(referenceElement.getBoundingClientRect().right);
} else if(reference){
layout.changeRightTo(reference.right);
}
layout.refresh();
layout.close();
$("#html-design-editor").trigger("groupReselect");
}
}
function _alignTop(){
if(layout){
layout.open();
if(referenceElement){
layout.changeTopTo(referenceElement.getBoundingClientRect().top);
} else if(reference){
layout.changeTopTo(reference.top);
}
layout.refresh();
layout.close();
$("#html-design-editor").trigger("groupReselect");
}
}
function _alignBottom(){
if(layout){
layout.open();
if(referenceElement){
layout.changeBottomTo(referenceElement.getBoundingClientRect().bottom);
} else if(reference){
layout.changeBottomTo(reference.bottom);
}
layout.refresh();
layout.close();
$("#html-design-editor").trigger("groupReselect");
}
}
function _alignMiddle(){
if(layout){
layout.open();
if(referenceElement){
layout.changeMiddleTo((referenceElement.getBoundingClientRect().bottom + referenceElement.getBoundingClientRect().top)/2);
} else if(reference){
layout.changeMiddleTo((reference.bottom + reference.top)/2);
}
layout.refresh();
layout.close();
$("#html-design-editor").trigger("groupReselect");
}
}
function _alignCenter(){
if(layout){
layout.open();
if(referenceElement){
layout.changeCenterTo((referenceElement.getBoundingClientRect().left + referenceElement.getBoundingClientRect().right)/2);
} else if(reference){
layout.changeCenterTo((reference.left + reference.right)/2);
}
layout.refresh();
layout.close();
$("#html-design-editor").trigger("groupReselect");
}
}
$(document).on("grouplayout.decision","#html-design-editor", function(event,layoutObj){
layout = layoutObj;
});
$(document).on("groupreference.selected","#html-design-editor", function(event,referenceObj){
referenceElement = referenceObj;
});
$(document).on("multiselectarea.computed","#html-design-editor",function(event,unionArea){
reference = unionArea;
});
$(document).on('element.selected',"#html-design-editor",function(){
reference = null;
referenceElement = null;
});
$(document).on('deselect.all',"#html-design-editor",function(){
reference = null;
referenceElement = null;
});
$(document).on('click',".alignControl",function(){
var op = $(this).data("operation");
switch(op){
case "align-left":_alignLeft();break;
case "align-center":_alignCenter();break;
case "align-right":_alignRight();break;
case "align-top":_alignTop();break;
case "align-middle":_alignMiddle();break;
case "align-bottom":_alignBottom();break;
}
});
});