-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript_style.js
197 lines (184 loc) · 8.07 KB
/
script_style.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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
// Slide up/down style panel
function stylePanelToggle(direction) {
var selectedStyleTabId = '#dropdown_' + document.querySelector('input[type=radio]:checked + label').getAttribute('for');
if (direction == 'up') $(selectedStyleTabId).slideUp();
if (direction == 'down') $(selectedStyleTabId).slideDown();
}
function moveLayerTo(layer, location) {
var parentNode = layer.parentNode;
if (location == 'forward') parentNode.insertBefore(layer, layer.previousElementSibling);
else if (location == 'backwards') parentNode.insertBefore(layer, layer.nextElementSibling.nextElementSibling);
else if (location == 'front') parentNode.insertBefore(layer, parentNode.childNodes[0]);
else if (location == 'back') parentNode.insertBefore(layer, parentNode.childNodes[parentNode.childNodes.length - 1]);
}
// Slide up/down style panel
function layerControlsToggle(status) {
var layerControls = document.getElementById('layer-order-controls');
if (status == true) layerControls.className = 'toRight';
if (status == false) layerControls.className = 'toRight disabled';
}
function fill_panel_toggle(status) {
if (status == 'enable') {
document.getElementById("dropdown_fill").classList.remove("disabled");
}
else if (status == 'disable') {
document.getElementById("dropdown_fill").classList.add("disabled");
}
}
function stroke_panel_toggle(status) {
if (status == 'enable') {
document.getElementById("dropdown_outline").classList.remove("disabled");
}
else if (status == 'disable') {
document.getElementById("dropdown_outline").classList.add("disabled");
}
}
function shadow_panel_toggle(status) {
if (status == 'enable') {
document.getElementById("dropdown_shadow").classList.remove("disabled");
}
else if (status == 'disable') {
document.getElementById("dropdown_shadow").classList.add("disabled");
}
}
function glow_panel_toggle(status) {
if (status == 'enable') {
document.getElementById("dropdown_glow").classList.remove("disabled");
}
else if (status == 'disable') {
document.getElementById("dropdown_glow").classList.add("disabled");
}
}
var hidden_panels = ["dropdown_fill", "dropdown_outline", "dropdown_shadow", "dropdown_glow"]
$(document).on('click', '.dropdownBtn', function () {
for (var i = 0; i < hidden_panels.length; i++) {
if ("dropdown_" + this.id != hidden_panels[i]) $('#' + hidden_panels[i]).slideUp();
}
$("#dropdown_" + this.id).slideDown();
});
$(document).mouseup(function (e) {
var container = $(".panel");
if (!container.is(e.target) && !$(e.target).parents(container).length && !canvas.getActiveObject()) {
for (var i = 0; i < hidden_panels.length; i++) {
$('#' + hidden_panels[i]).slideUp();
}
}
});
// Responsive canvas
$(window).resize(function () {
var width = (document.getElementsByClassName('group')[0].offsetWidth);
var height = (9 / 16) * width;
canvas.setDimensions({ width: width + 'px', height: height + 'px' }, { cssOnly: true });
// canvas.width = width + 'px';
// canvas.height = height + 'px';
canvas.renderAll();
});
document.getElementById('fillToggle').onchange = function () {
// If the change caused by the user is true (meaning the radio is selected) then....
if (this.checked) {
document.getElementById('fillPick').classList.remove("disabled");
document.getElementById('gp').classList.add("disabled");
}
else {
document.getElementById('fillPick').classList.add("disabled");
document.getElementById('gp').classList.remove("disabled");
}
};
document.getElementById('gradientFill').onchange = function () {
// If the change caused by the user is true (meaning the checkbox is selected) then....
if (this.checked) {
document.getElementById('fillPick').classList.add("disabled");
document.getElementById('gp').classList.remove("disabled");
}
else {
document.getElementById('fillPick').classList.remove("disabled");
document.getElementById('gp').classList.add("disabled");
}
};
document.getElementById('strokeToggle').onchange = function () {
// If the change caused by the user is true (meaning the checkbox is selected) then....
if (this.checked) {
document.getElementById('strokePick').classList.remove("disabled");
document.getElementById('stroke_width').classList.remove("disabled");
// If the selected object doesn't have any stroke then add
if (!canvas.getActiveObject().stroke) {
var strokePickerCurrentColor = document.getElementById('strokePick').style.borderColor;
var strokeWeightCurrentVal = Number(document.getElementById('stroke_width').value) / 10;
canvas.getActiveObject().set({ stroke: strokePickerCurrentColor, strokeWidth: strokeWeightCurrentVal });
canvas.renderAll();
}
}
else {
document.getElementById('strokePick').classList.add("disabled");
document.getElementById('stroke_width').classList.add("disabled");
// If the selected object has stroke, remove it
if (canvas.getActiveObject().stroke) {
canvas.getActiveObject().set({ stroke: null, strokeWidth: null });
canvas.renderAll();
}
}
};
document.getElementById('shadowToggle').onchange = function () {
var shadowColorElement = document.getElementById('shadowPick');
var shadowDistanceElement = document.getElementById('shadow_dis');
var shadowBlurElement = document.getElementById('shadow_blur');
// If the change caused by the user is true (meaning the checkbox is selected) then....
if (this.checked) {
shadowColorElement.classList.remove("disabled");
shadowDistanceElement.classList.remove("disabled");
shadowBlurElement.classList.remove("disabled");
if (!canvas.getActiveObject().shadow) {
var color = shadowColorElement.style.boxShadow.split(" ");
color = color.slice(0, color.length - 3);
color = color[0] + color[1] + color[2];
var shadow_blur = shadowBlurElement.value;
var dis = shadowDistanceElement.value;
canvas.getActiveObject().set('shadow', {
color: color,
blur: shadow_blur,
offsetX: dis,
offsetY: dis
});
canvas.renderAll();
}
}
else {
shadowColorElement.classList.add("disabled");
shadowDistanceElement.classList.add("disabled");
shadowBlurElement.classList.add("disabled");;
if (canvas.getActiveObject().shadow) {
canvas.getActiveObject().set('shadow', null);
canvas.renderAll();;
}
}
};
document.getElementById('glowToggle').onchange = function () {
var glowColorElement = document.getElementById('glowPick');
var glowFeatherElement = document.getElementById('glow_feather');
// If the change caused by the user is true (meaning the checkbox is selected) then....
if (this.checked) {
glowColorElement.classList.remove("disabled");
glowFeatherElement.classList.remove("disabled");
if (!canvas.getActiveObject().shadow) {
var color = glowColorElement.style.boxShadow.split(" ");
color = color.slice(0, color.length - 3);
color = color[0] + color[1] + color[2];
var glow_feather = glowFeatherElement.value;
canvas.getActiveObject().set('shadow', {
color: color,
blur: glow_feather,
offsetX: 0,
offsetY: 0
});
canvas.renderAll();
}
}
else {
glowColorElement.classList.add("disabled");
glowFeatherElement.classList.add("disabled");;
if (canvas.getActiveObject().shadow) {
canvas.getActiveObject().set('shadow', null);
canvas.renderAll();
}
}
};