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
/
DistributionHandler.js
111 lines (92 loc) · 3.25 KB
/
DistributionHandler.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
/**
* @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 _distributeHorizontally(){
if(layout){
layout.open();
layout.distributeHorizontally(reference,$("#distribute-horz-input").val(),null);
layout.refresh();
layout.close();
$("#html-design-editor").trigger("groupReselect");
}
}
function _distributeVertically(){
if(layout){
layout.open();
layout.distributeVertically(reference,$("#distribute-vert-input").val(),null);
layout.refresh();
layout.close();
$("#html-design-editor").trigger("groupReselect");
}
}
function _normalizeHeight(){
if(layout){
layout.open();
var height = 0;
if(referenceElement){
height = referenceElement.getBoundingClientRect().height;
} else {
height = $("#normalize-height-input").val() || (reference.bottom - reference.top);
}
layout.changeHeightTo(height);
layout.refresh();
layout.close();
$("#html-design-editor").trigger("groupReselect");
}
}
function _normalizeWidth(){
if(layout){
layout.open();
var width = 0;
if(referenceElement){
width = referenceElement.getBoundingClientRect().width;
} else {
width = $("#normalize-width-input").val() || (reference.right - reference.left);
}
layout.changeWidthTo(width);
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;
$("#distribute-horz-input").val("");
$("#distribute-vert-input").val("");
$("#normalize-width-input").val("");
$("#normalize-height-input").val("");
});
$(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',"#distribute-horz",function(){
_distributeHorizontally();
});
$(document).on('click',"#distribute-vert",function(){
_distributeVertically();
});
$(document).on('click',"#normalize-height",function(){
_normalizeHeight();
});
$(document).on('click',"#normalize-width",function(){
_normalizeWidth();
});
});