forked from rse/componentjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomponent.plugin.debugger-window.js
257 lines (239 loc) · 11.1 KB
/
component.plugin.debugger-window.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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
/*
** ComponentJS -- Component System for JavaScript <http://componentjs.com>
** Copyright (c) 2009-2013 Ralf S. Engelschall <http://engelschall.com>
**
** This Source Code Form is subject to the terms of the Mozilla Public
** License, v. 2.0. If a copy of the MPL was not distributed with this
** file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
/*
* ComponentJS debugger window
*/
/* debugger window */
_cs.dbg = null;
/* debugger update state */
_cs.dbg_state_invalid = {
components: false,
states: false,
requests: false,
console: false
};
_cs.dbg_state_invalidate = function (name) {
_cs.dbg_state_invalid[name] = true;
};
/* debugger canvas: natural tree direction flag */
_cs.dbg_natural = false;
/* try to determine whether we are running instrumented,
i.e., whether the native Browser debugger is active/open */
$cs.debug_instrumented = function () {
return (
typeof GLOBAL !== "undefined" &&
GLOBAL.console &&
(GLOBAL.console.firebug || /* precision: Firefox Firebug */
(GLOBAL.outerHeight - GLOBAL.innerHeight) > 120) /* guessing: Chrome/Safari Inspector, IE Debugger */
);
};
/* try to determine whether Internet Explorer is used */
_cs.isIE = function () {
/* global navigator:false */
return (
typeof navigator !== "undefined" &&
navigator.appName === "Microsoft Internet Explorer" &&
navigator.userAgent.match(new RegExp("MSIE ([0-9]+[.0-9]*)"))
);
};
/* debugger window API entry point */
$cs.debug_window = function () {
/* determine parameters */
var params = $cs.params("debugger", arguments, {
enable: { pos: 0, def: null },
autoclose: { pos: 1, def: false },
name: { pos: 2, def: null },
width: { def: 800 },
height: { def: 600 },
natural: { def: false }
});
/* dispatch according to requested operation */
if (params.enable === null)
/* determine debugger state */
return (_cs.dbg !== null);
else if (params.enable) {
/* remember natural rendering flag */
_cs.dbg_natural = params.natural;
/* enable debugger */
if (_cs.dbg === null) {
/* determine (potentially application specific) title */
var title = "ComponentJS Debugger";
if (typeof params.name !== null)
title += " (" + params.name + ")";
/* create external debugger window */
var wname = title;
var wopts = "location=no,scrollbars=no,toolbars=no,menubar=no,status=no";
wopts += ",width=" + params.width + ",height=" + params.height;
if (_cs.isIE())
wname = wname.replace(/ /g, "_").replace(/[()]/g, "");
else
wopts += ",replace=yes";
_cs.dbg = GLOBAL.open("about:blank", wname, wopts);
if (_cs.isIE()) {
/* IE does not support reuse flag, so close old instance and open a fresh one */
_cs.dbg.close();
_cs.dbg = GLOBAL.open("about:blank", wname, wopts);
}
/* initialize the window content (deferred to avoid problems) */
/* global setTimeout:false */
setTimeout(_cs.hook("ComponentJS:plugin:debugger:settimeout:func", "pass", function () {
_cs.jq(_cs.dbg.document).ready(function () {
/* optionally automatically close debugger window with application window */
if (params.autoclose) {
_cs.jq(GLOBAL).bind("beforeunload", function () {
if (_cs.dbg !== null)
_cs.dbg.close();
});
}
/* generate view mask */
_cs.dbg_view_mask(title);
/* window-based resize support */
_cs.dbg_refresh();
_cs.jq(_cs.dbg).bind("resize", function () {
_cs.dbg_refresh();
});
/* avoid text selections (which confuse the grabbing) [non cross-browser event!] */
_cs.jq(".dbg", _cs.dbg.document).bind("selectstart", function (ev) {
ev.preventDefault();
return false;
});
/* grabbing-based resize support */
var grabbing = false;
var positioning = false;
var positioning_x = -1;
var positioning_y = -1;
_cs.jq(".dbg .grabber", _cs.dbg.document).bind("mousedown", function (ev) {
grabbing = true;
_cs.jq(".dbg .grabber", _cs.dbg.document).css("background-color", "red");
ev.preventDefault();
});
_cs.jq(".dbg", _cs.dbg.document).bind("mousemove", function (ev) {
if (grabbing) {
var offset = ev.pageY;
if (offset < 300)
offset = 300;
var vh = _cs.jq(_cs.dbg).height();
if (offset > vh - 100)
offset = vh - 100;
_cs.jq(".dbg .grabber", _cs.dbg.document).css("top", offset);
_cs.dbg_grabber_offset = offset;
ev.preventDefault();
}
else if (positioning) {
if (positioning_x === -1)
positioning_x = ev.pageX;
if (positioning_y === -1)
positioning_y = ev.pageY;
var offsetX = positioning_x - ev.pageX;
var offsetY = positioning_y - ev.pageY;
positioning_x = ev.pageX;
positioning_y = ev.pageY;
_cs.dbg_canvas_info.x += offsetX;
_cs.dbg_canvas_info.y += offsetY;
_cs.dbg_reposition();
}
});
_cs.jq(".dbg", _cs.dbg.document).bind("mouseup", function (ev) {
if (grabbing) {
_cs.jq(".dbg .grabber", _cs.dbg.document).css("background-color", "transparent");
_cs.dbg_refresh();
grabbing = false;
ev.preventDefault();
}
});
/* canvas export functionality */
_cs.jq(".dbg .exporter", _cs.dbg.document).bind("click", function (ev) {
var ctx = _cs.jq(".dbg .viewer canvas", _cs.dbg.document).get(0);
if (typeof ctx !== "undefined") {
var dataurl = ctx.toDataURL("image/png");
GLOBAL.open(dataurl);
}
ev.preventDefault();
return false;
});
/* canvas scroll and zoom functionality */
var zoom_step = 100;
var scroll_step = 10;
_cs.jq(".dbg .plus", _cs.dbg.document).bind("click", function (/* ev */) {
_cs.dbg_canvas_info.w += zoom_step;
_cs.dbg_canvas_info.h += zoom_step;
_cs.dbg_refresh();
});
_cs.jq(".dbg .minus", _cs.dbg.document).bind("click", function (/* ev */) {
_cs.dbg_canvas_info.w -= zoom_step;
_cs.dbg_canvas_info.h -= zoom_step;
_cs.dbg_refresh();
});
_cs.jq(".dbg .reset", _cs.dbg.document).bind("click", function (/* ev */) {
_cs.dbg_canvas_info.w = _cs.dbg_canvas_info.wmin;
_cs.dbg_canvas_info.h = _cs.dbg_canvas_info.hmin;
_cs.dbg_refresh();
});
_cs.jq(".dbg .viewer canvas", _cs.dbg.document).bind("mousedown", function (/* ev */) {
positioning = true;
positioning_x = -1;
positioning_y = -1;
});
_cs.jq(".dbg .viewer canvas", _cs.dbg.document).bind("mouseup", function (/* ev */) {
positioning = false;
});
_cs.jq(_cs.dbg.document).bind("keydown", function (ev) {
if (ev.keyCode === 43 || ev.keyCode === 107 || ev.keyCode === 187) {
/* key "+" pressed */
_cs.dbg_canvas_info.w += zoom_step;
_cs.dbg_canvas_info.h += zoom_step;
_cs.dbg_refresh();
}
else if (ev.keyCode === 45 || ev.keyCode === 109 || ev.keyCode === 189) {
/* key "-" pressed */
_cs.dbg_canvas_info.w -= zoom_step;
_cs.dbg_canvas_info.h -= zoom_step;
_cs.dbg_refresh();
}
else if (ev.keyCode === 48) {
/* key "0" pressed */
_cs.dbg_canvas_info.w = _cs.dbg_canvas_info.wmin;
_cs.dbg_canvas_info.h = _cs.dbg_canvas_info.hmin;
_cs.dbg_refresh();
}
else if (ev.keyCode === 37) {
/* key LEFT pressed */
_cs.dbg_canvas_info.x += scroll_step;
_cs.dbg_reposition();
}
else if (ev.keyCode === 38) {
/* key UP pressed */
_cs.dbg_canvas_info.y += scroll_step;
_cs.dbg_reposition();
}
else if (ev.keyCode === 39) {
/* key RIGHT pressed */
_cs.dbg_canvas_info.x -= scroll_step;
_cs.dbg_reposition();
}
else if (ev.keyCode === 40) {
/* key DOWN pressed */
_cs.dbg_canvas_info.y -= scroll_step;
_cs.dbg_reposition();
}
});
});
}), 500);
}
$cs.debug(3, "debugger enabled");
}
else {
/* disable debugger */
if (_cs.dbg !== null) {
$cs.debug(3, "debugger disabled");
_cs.dbg.close();
_cs.dbg = null;
}
}
};