-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathglobal.js
More file actions
187 lines (134 loc) · 3.65 KB
/
global.js
File metadata and controls
187 lines (134 loc) · 3.65 KB
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
var global = {
keys: {
CTRL: false,
SHIFT: false
},
toolbox_visible: true,
init: function(){
// 1. main the main DIV draggable...
$(".cpanel#main").draggable({cancel: "div#cpanel-main-body"});
// 2. initiate tabs...
$("#cpanel-main-tabs").tabs()
// 3. add functionality to the "hide" badge
$("#cpanel-title-hide").click(function(){
$(".cpanel#main").fadeOut({duration: 1000, easing: "linear"});
global.toolbox_visible = false;
});
// 4. Global keystroke handling: key down
document.addEventListener("keydown",function(e){
var myKeycode = e.keyCode;
var keyPressed = String.fromCharCode(myKeycode);//note that this is non-case sensitive.
/* my key assignments
A - add row
B
C
D
E
F
G
H - restore box
I
J
K
L
M
N
O
P
*/
if (keyPressed == 'H'){
// the 'H' key can only UNHIDE....
$(".cpanel#main").fadeIn({duration: 400, easing: "linear"});
global.toolbox_visible = true;
}
if (keyPressed == 'A'){
//Action for 'A' pressed
}
if(myKeycode == 16){//shift key
global.keys.SHIFT = true;
}
if(myKeycode == 17){//control key
global.keys.CTRL = true;
}
if(motifs_edit.active){
// Arrow keys and delete keys must be passed...
motifs_edit.keyStrokeHandler(myKeycode, keyPressed, "keydown");
}
}, false);
// 5. Global keystroke handling: key up
document.addEventListener("keyup",function(e){
var myKeycode = e.keyCode;
var keyPressed = String.fromCharCode(myKeycode);//note that this is non-case sensitive.
if(myKeycode == 16){//shift key
global.keys.SHIFT = false;
}
if(myKeycode == 17){//control key
global.keys.CTRL = false;
}
if(motifs_edit.active){
// Arrow keys and delete keys must be passed...
motifs_edit.keyStrokeHandler(myKeycode, keyPressed, "keyup");
}
}, false);
// 6. click upon anywhere
$(document).click(function(){
if(global.toolbox_visible == false){
global.toast("Press the 'H' key to unhide the toolbox");
}
});
},
toast: function(text){
$("#toast-box")
.text(text)
.fadeIn({duration:200, easing: "linear"});
setTimeout(function(){
$("#toast-box")
.fadeOut({duration:200, easing: "linear"});
}, 1000);
},
$div_array: function(qty, my_class, ColourPot){//function to generate many mini DIVs
var tinies = [];
for(var i=0; i<qty; i++){
var cell_colour = ColourPot ? cpot_util.DrawFromColourPot(ColourPot) : "white";
tinies.push(
$('<div/>').addClass(my_class).css("background",cell_colour)
);
}
return tinies;
}
};
// executive code...
$(document).ready(function() {
global.init();
cpot_view.init();
grids_init.init();
plots.init();
export_pat.init();
gallery.init();
motifs_view.init();
motifs_edit_init.init();
patterns.init();
//code to auto enter CP edit and speed up testing...
/*
//go straight to CP edit
$("#view-cp-table tbody tr").first().click();
$("#cp-view-table-buttons #edit").click();
*/
//go straight to a particular tab...
// Tab sequence:
// 1 - Colour Pots
// 2 - Colouring functions
// 3 - Motifs
// 4 - Grids
// 5 - Plots
// 6 - Paintings
// 7 - Patterns
// 8 - Examples
// 9 - Options
// 10 - Tutorial
$("#cpanel-main-tabs > ul > li:nth-of-type(7) a").click();
// $("#motifs-view .table-buttons #edit").click(); // --> and into Motif EDIT
});
$(window).on("resize", function(){
plots2.render_plot_canvases_background();
});