rsence-pre 3.0.0.3 → 3.0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,1270 +0,0 @@
|
|
1
|
-
|
2
|
-
/*** = Description
|
3
|
-
** Mid-level event abstraction manager.
|
4
|
-
**
|
5
|
-
** This engine serves the HControl classes, so usually the existence of it
|
6
|
-
** is not obvious. The main interface to use it is the methods in HControl.
|
7
|
-
***/
|
8
|
-
var//RSence.Foundation
|
9
|
-
EVENT = {
|
10
|
-
|
11
|
-
// Default options for focus (all false)
|
12
|
-
_defaultFocusOptions: {
|
13
|
-
mouseMove: false,
|
14
|
-
mouseDown: false,
|
15
|
-
click: false,
|
16
|
-
mouseUp: false,
|
17
|
-
draggable: false,
|
18
|
-
droppable: false,
|
19
|
-
keyDown: false,
|
20
|
-
keyUp: false,
|
21
|
-
mouseWheel: false,
|
22
|
-
resize: false,
|
23
|
-
textEnter: false,
|
24
|
-
doubleClick: false,
|
25
|
-
contextMenu: false
|
26
|
-
},
|
27
|
-
|
28
|
-
/** = Description
|
29
|
-
* Array that keeps the last known global event status type.
|
30
|
-
*
|
31
|
-
* The format is an array with an index per "interesting" event value.
|
32
|
-
*
|
33
|
-
* = Indexes
|
34
|
-
* +EVENT.status[ EVENT.button1 ]+:: The state of the left mouse button.
|
35
|
-
* false when not pressed
|
36
|
-
* true when pressed.
|
37
|
-
*
|
38
|
-
* +EVENT.status[ EVENT.button2 ]+:: The state of the right mouse button.
|
39
|
-
* false when not pressed
|
40
|
-
* true when pressed.
|
41
|
-
*
|
42
|
-
* +EVENT.status[ EVENT.crsrX ]+:: The x-coordinate of the mouse cursor.
|
43
|
-
*
|
44
|
-
* +EVENT.status[ EVENT.crsrY ]+:: The y-coordinate of the mouse cursor.
|
45
|
-
*
|
46
|
-
* +EVENT.status[ EVENT.keysDown ]+:: A list of keycodes of all the keys
|
47
|
-
* currently held down in the order of
|
48
|
-
* occurrence (first pressed comes first,
|
49
|
-
* last pressed last).
|
50
|
-
*
|
51
|
-
* +EVENT.status[ EVENT.altKeyDown ]+:: The boolean status of the Alt
|
52
|
-
* modifier key being held down.
|
53
|
-
*
|
54
|
-
* +EVENT.status[ EVENT.ctrlKeyDown ]+:: The boolean status of the Ctrl
|
55
|
-
* modifier key being held down.
|
56
|
-
*
|
57
|
-
* +EVENT.status[ EVENT.shiftKeyDown ]+:: The boolean status of the Shift
|
58
|
-
* modifier key being held down.
|
59
|
-
*
|
60
|
-
* +EVENT.status[ EVENT.metaKeyDown ]+:: The boolean status of the Meta
|
61
|
-
* modifier key being held down.
|
62
|
-
*
|
63
|
-
* +EVENT.status[ EVENT.cmdKeyDown ]+:: The boolean status of any of the system-specific
|
64
|
-
* Command, Menu or Start modifier keys being held down.
|
65
|
-
*
|
66
|
-
**/
|
67
|
-
status: [false, false, -1, -1, [], false, false, false, false, false],
|
68
|
-
|
69
|
-
/** The index in the status array for the left mouse button.
|
70
|
-
**/
|
71
|
-
button1: 0,
|
72
|
-
|
73
|
-
/** The index in the status array for the right mouse button.
|
74
|
-
**/
|
75
|
-
button2: 1,
|
76
|
-
|
77
|
-
/** The index in the status array for the mouse cursor x coordinate.
|
78
|
-
**/
|
79
|
-
crsrX: 2,
|
80
|
-
|
81
|
-
/** The index in the status array for the mouse cursor y coordinate.
|
82
|
-
**/
|
83
|
-
crsrY: 3,
|
84
|
-
|
85
|
-
/** The index in the status array for the list of keycodes of all the
|
86
|
-
* keys currently held down in the order of occurrence (first pressed
|
87
|
-
* comes first, last pressed last).
|
88
|
-
*
|
89
|
-
**/
|
90
|
-
keysDown: 4,
|
91
|
-
|
92
|
-
/** The index in the status array for the state of the Alt modifier key.
|
93
|
-
**/
|
94
|
-
altKeyDown: 5,
|
95
|
-
|
96
|
-
/** The index in the status array for the state of the Ctrl modifier key.
|
97
|
-
**/
|
98
|
-
ctrlKeyDown: 6,
|
99
|
-
|
100
|
-
/** The index in the status array for the state of the Shift modifier key.
|
101
|
-
**/
|
102
|
-
shiftKeyDown: 7,
|
103
|
-
|
104
|
-
/** The index in the status array for the state of the Meta modifier key.
|
105
|
-
**/
|
106
|
-
metaKeyDown: 8,
|
107
|
-
|
108
|
-
/** The index in the status array for the state of the Command modifier key.
|
109
|
-
**/
|
110
|
-
cmdKeyDown: 9,
|
111
|
-
|
112
|
-
/** A flag to disable, if your applications don't need drop events.
|
113
|
-
* Setting this to false when not needed improves overall performance,
|
114
|
-
* because the drop events need constant calculation of the mouse cursor
|
115
|
-
* location against all possible drop targets.
|
116
|
-
*
|
117
|
-
**/
|
118
|
-
enableDroppableChecks: true,
|
119
|
-
|
120
|
-
/** Initializes the members used by the drop -related events.
|
121
|
-
* This method is called from within EVENT and is never called,
|
122
|
-
* if enableDroppableChecks is false.
|
123
|
-
**/
|
124
|
-
startDroppable: function() {
|
125
|
-
var _this = EVENT;
|
126
|
-
_this.hovered = [];
|
127
|
-
// items currently under the mouse cursor
|
128
|
-
_this.hoverInterval = 200;
|
129
|
-
// 50 means send hover events at most with 50ms intervals
|
130
|
-
_this.hoverTimer = new Date().getTime();
|
131
|
-
// Time since last hover event triggered
|
132
|
-
},
|
133
|
-
|
134
|
-
|
135
|
-
// cleans up events that would be lost when browser window is blurred
|
136
|
-
_domWindowBlur: function(){
|
137
|
-
// console.log('window blurred');
|
138
|
-
var
|
139
|
-
_this = EVENT,
|
140
|
-
_status = _this.status;
|
141
|
-
// _status[_this.button1] = false;
|
142
|
-
// _status[_this.button2] = false;
|
143
|
-
// _status[_this.crsrX] = -1;
|
144
|
-
// _status[_this.crsrY] = -1;
|
145
|
-
_status[_this.keysDown] = [];
|
146
|
-
_status[_this.altKeyDown] = false;
|
147
|
-
_status[_this.ctrlKeyDown] = false;
|
148
|
-
_status[_this.shiftKeyDown] = false;
|
149
|
-
_status[_this.metaKeyDown] = false;
|
150
|
-
_status[_this.cmdKeyDown] = false;
|
151
|
-
_this.enableDroppableChecks = false;
|
152
|
-
if( HSystem.defaultInterval !== HSystem._blurredInterval ){
|
153
|
-
_this._sysDefaultInterval = HSystem.defaultInterval;
|
154
|
-
COMM.Queue.push( function(){
|
155
|
-
HSystem.defaultInterval = HSystem._blurredInterval;
|
156
|
-
} );
|
157
|
-
}
|
158
|
-
},
|
159
|
-
_domWindowFocus: function(){
|
160
|
-
var
|
161
|
-
_this = EVENT;
|
162
|
-
_this.enableDroppableChecks = _this._origDroppableChecks;
|
163
|
-
if( HSystem.defaultInterval === HSystem._blurredInterval && _this._sysDefaultInterval ){
|
164
|
-
COMM.Queue.push( function(){
|
165
|
-
HSystem.defaultInterval = _this._sysDefaultInterval;
|
166
|
-
} );
|
167
|
-
}
|
168
|
-
// console.log('window focused');
|
169
|
-
},
|
170
|
-
|
171
|
-
/** Starts event listening.
|
172
|
-
**/
|
173
|
-
start: function() {
|
174
|
-
var _globalEventTargetElement = (BROWSER_TYPE.ie && !BROWSER_TYPE.ie9)?document:window,
|
175
|
-
_this = EVENT;
|
176
|
-
Event.observe( _globalEventTargetElement, 'mousemove', _this.mouseMove );
|
177
|
-
Event.observe( _globalEventTargetElement, 'mouseup', _this.mouseUp );
|
178
|
-
Event.observe( _globalEventTargetElement, 'mousedown', _this.mouseDown );
|
179
|
-
Event.observe( _globalEventTargetElement, 'click', _this.click );
|
180
|
-
Event.observe( _globalEventTargetElement, 'keyup', _this.keyUp );
|
181
|
-
Event.observe( _globalEventTargetElement, 'keydown', _this.keyDown );
|
182
|
-
if( !BROWSER_TYPE.safari && !BROWSER_TYPE.ie){
|
183
|
-
Event.observe( _globalEventTargetElement, 'keypress', _this.keyPress );
|
184
|
-
}
|
185
|
-
Event.observe( _globalEventTargetElement, 'contextmenu', _this.contextMenu );
|
186
|
-
Event.observe( _globalEventTargetElement, 'resize', _this.resize );
|
187
|
-
Event.observe( _globalEventTargetElement, 'mousewheel', _this.mouseWheel );
|
188
|
-
Event.observe( _globalEventTargetElement, 'dblclick', _this.doubleClick );
|
189
|
-
if (window.addEventListener) {
|
190
|
-
window.addEventListener('DOMMouseScroll', EVENT.mouseWheel, false);
|
191
|
-
window.addEventListener('resize', EVENT.resize, false);
|
192
|
-
}
|
193
|
-
_this._origDroppableChecks = _this.enableDroppableChecks;
|
194
|
-
Event.observe( window, 'blur', _this._domWindowBlur );
|
195
|
-
Event.observe( window, 'focus', _this._domWindowFocus );
|
196
|
-
_this.listeners = [];
|
197
|
-
// keep elemId buffer of all listeners
|
198
|
-
_this.focused = [];
|
199
|
-
// keep elemId buffer of all focused listeners
|
200
|
-
_this.resizeListeners = [];
|
201
|
-
// list of resize-event listeners
|
202
|
-
_this.coordListeners = [];
|
203
|
-
// global mouse movement listeners
|
204
|
-
_this.focusOptions = {};
|
205
|
-
// keep property lists by elemId
|
206
|
-
_this.dragItems = [];
|
207
|
-
// elemId of currently dragged items
|
208
|
-
if (_this.enableDroppableChecks) {
|
209
|
-
_this.startDroppable();
|
210
|
-
}
|
211
|
-
|
212
|
-
_this.topmostDroppable = null;
|
213
|
-
// the currently hovered element accepting droppable items
|
214
|
-
_this.textEnterCtrls = [];
|
215
|
-
// ID of controls with textfields
|
216
|
-
// position caching benefits performance, see coordCacheFlush
|
217
|
-
_this._coordCache = [];
|
218
|
-
_this._coordCacheFlag = true;
|
219
|
-
_this._lastCoordFlushTimeout = null;
|
220
|
-
|
221
|
-
_this.activeControl = null;
|
222
|
-
// control that currently has the focus
|
223
|
-
_this._lastKeyDown = null;
|
224
|
-
// the most recent keypress
|
225
|
-
},
|
226
|
-
|
227
|
-
/** Flushes the position cache by elemId, if no elemId is specified,
|
228
|
-
* everything is flushed.
|
229
|
-
**/
|
230
|
-
coordCacheFlush: function(_elemId) {
|
231
|
-
if (_elemId) {
|
232
|
-
EVENT._coordCache[_elemId] = null;
|
233
|
-
}
|
234
|
-
else {
|
235
|
-
EVENT._coordCache = [];
|
236
|
-
}
|
237
|
-
},
|
238
|
-
|
239
|
-
/** Registers the _ctrl object by event listener flags in _focusOptions.
|
240
|
-
**/
|
241
|
-
reg: function(_ctrl, _focusOptions) {
|
242
|
-
var
|
243
|
-
// Binds the class to the element (so it can be called on the event)
|
244
|
-
_elemId = _ctrl.elemId,
|
245
|
-
_elem = ELEM.get(_elemId),
|
246
|
-
_this = EVENT,
|
247
|
-
_propIn,
|
248
|
-
_init = ( _this.listeners[_elemId] === undefined || _this.listeners[_elemId] === false );
|
249
|
-
if (BROWSER_TYPE.ie && !BROWSER_TYPE.ie9) {
|
250
|
-
_elem.setAttribute('ctrl', _ctrl);
|
251
|
-
}
|
252
|
-
else {
|
253
|
-
_elem.ctrl = _ctrl;
|
254
|
-
}
|
255
|
-
if(_init){
|
256
|
-
_this.listeners[_elemId] = true;
|
257
|
-
_this.focused[_elemId] = false;
|
258
|
-
}
|
259
|
-
for (_propIn in _this._defaultFocusOptions) {
|
260
|
-
if (_focusOptions[_propIn] === undefined) {
|
261
|
-
_focusOptions[_propIn] = _defaultFocusOptions[_propIn];
|
262
|
-
}
|
263
|
-
}
|
264
|
-
_this.focusOptions[_elemId] = _focusOptions;
|
265
|
-
var _coordListenIdx = _this.coordListeners.indexOf(_elemId);
|
266
|
-
if (_focusOptions.mouseMove) {
|
267
|
-
if (_coordListenIdx === -1) {
|
268
|
-
_this.coordListeners.push(_elemId);
|
269
|
-
}
|
270
|
-
}
|
271
|
-
else if (_coordListenIdx !== -1) {
|
272
|
-
_this.coordListeners.splice(_coordListenIdx, 1);
|
273
|
-
}
|
274
|
-
//console.log('focusOptions:',_focusOptions);
|
275
|
-
//console.log('focusOptions.textEnter: ',_focusOptions.textEnter);
|
276
|
-
if (_focusOptions.textEnter) {
|
277
|
-
if (_this.textEnterCtrls.indexOf(_ctrl.viewId) === -1) {
|
278
|
-
_this.textEnterCtrls.push(_ctrl.viewId);
|
279
|
-
}
|
280
|
-
}
|
281
|
-
else {
|
282
|
-
var _textEnterIndex = _this.textEnterCtrls.indexOf(_ctrl.viewId);
|
283
|
-
if (_textEnterIndex !== -1) {
|
284
|
-
_this.textEnterCtrls.splice(_textEnterIndex,1);
|
285
|
-
}
|
286
|
-
}
|
287
|
-
if (_focusOptions.resize) {
|
288
|
-
if (_this.resizeListeners.indexOf(_ctrl.viewId) === -1) {
|
289
|
-
_this.resizeListeners.push(_ctrl.viewId);
|
290
|
-
}
|
291
|
-
}
|
292
|
-
else {
|
293
|
-
var _resizeIndex = _this.resizeListeners.indexOf(_ctrl.viewId);
|
294
|
-
if (_resizeIndex !== -1) {
|
295
|
-
_this.resizeListeners.splice(_resizeIndex,1);
|
296
|
-
}
|
297
|
-
}
|
298
|
-
if(_init){
|
299
|
-
Event.observe(_elem, 'mouseover', _this._mouseOver);
|
300
|
-
}
|
301
|
-
if(_ctrl.drawn){
|
302
|
-
_this._updateHoverItems();
|
303
|
-
if (_this.hovered.length !== 0 && _this.hovered.indexOf(_ctrl.elemId) === _this.hovered.length-1){
|
304
|
-
_this.focus(_ctrl);
|
305
|
-
}
|
306
|
-
}
|
307
|
-
},
|
308
|
-
|
309
|
-
/** Unregisters the _ctrl object event listeners
|
310
|
-
**/
|
311
|
-
unreg: function(_ctrl) {
|
312
|
-
var
|
313
|
-
_this = EVENT,
|
314
|
-
_elemId,
|
315
|
-
_elem;
|
316
|
-
if (_ctrl === this.activeControl) {
|
317
|
-
_this.changeActiveControl(null);
|
318
|
-
}
|
319
|
-
_elemId = _ctrl.elemId;
|
320
|
-
if (_this.focused[_elemId]){
|
321
|
-
_this.blur(_ctrl);
|
322
|
-
}
|
323
|
-
_elem = ELEM.get(_elemId);
|
324
|
-
|
325
|
-
_this._coordCache[_elemId] = null;
|
326
|
-
|
327
|
-
_this.listeners[_elemId] = false;
|
328
|
-
_this.focused[_elemId] = false;
|
329
|
-
_this.focusOptions[_elemId] = { ctrl: _ctrl };
|
330
|
-
var _coordListenIdx = _this.coordListeners.indexOf(_elemId);
|
331
|
-
if (_coordListenIdx !== -1) {
|
332
|
-
_this.coordListeners.splice(_coordListenIdx, 1);
|
333
|
-
}
|
334
|
-
|
335
|
-
var _textEnterIndex = _this.textEnterCtrls.indexOf(_ctrl.viewId);
|
336
|
-
if (_textEnterIndex !== -1) {
|
337
|
-
_this.textEnterCtrls.splice(_textEnterIndex, 1);
|
338
|
-
}
|
339
|
-
var _resizeIndex = _this.resizeListeners.indexOf(_ctrl.viewId);
|
340
|
-
if (_resizeIndex !== -1) {
|
341
|
-
_this.resizeListeners.splice(_resizeIndex, 1);
|
342
|
-
}
|
343
|
-
if (_elem !== undefined) {
|
344
|
-
Event.stopObserving(_elem, 'mouseover', _this._mouseOver);
|
345
|
-
Event.stopObserving(_elem, 'mouseout', _this._mouseOut);
|
346
|
-
}
|
347
|
-
},
|
348
|
-
|
349
|
-
/** Receiver of the onResize event.
|
350
|
-
* Delegates calls to the high-level event receivers of all
|
351
|
-
* controls registered for the event.
|
352
|
-
**/
|
353
|
-
resize: function(e) {
|
354
|
-
var
|
355
|
-
i = 0,
|
356
|
-
_this = EVENT,
|
357
|
-
_ctrlID,
|
358
|
-
_ctrl;
|
359
|
-
HSystem._updateFlexibleRects();
|
360
|
-
for (; i < _this.resizeListeners.length; i++) {
|
361
|
-
_ctrlID = _this.resizeListeners[i];
|
362
|
-
_ctrl = HSystem.views[_ctrlID];
|
363
|
-
if (_ctrl['resize']) {
|
364
|
-
_ctrl.resize();
|
365
|
-
}
|
366
|
-
if (_ctrl['onResize']) {
|
367
|
-
_ctrl.onResize();
|
368
|
-
}
|
369
|
-
}
|
370
|
-
HSystem._updateFlexibleRects();
|
371
|
-
},
|
372
|
-
|
373
|
-
/* Element-specific mouse over/out event receiver. */
|
374
|
-
_mouseOver: function(e) {
|
375
|
-
if (!Event.element) {
|
376
|
-
return;
|
377
|
-
}
|
378
|
-
var _that = Event.element(e);
|
379
|
-
while (_that && _that.ctrl === undefined) {
|
380
|
-
_that = _that.parentNode;
|
381
|
-
}
|
382
|
-
if (!_that) {
|
383
|
-
return;
|
384
|
-
}
|
385
|
-
var _this = _that.ctrl;
|
386
|
-
EVENT.focus(_this);
|
387
|
-
Event.stop(e);
|
388
|
-
},
|
389
|
-
|
390
|
-
/* Element-specific mouse over/out event receiver. */
|
391
|
-
_mouseOut: function(e) {
|
392
|
-
if (!Event.element) {
|
393
|
-
return;
|
394
|
-
}
|
395
|
-
var _that = Event.element(e);
|
396
|
-
while (_that && _that.ctrl === undefined) {
|
397
|
-
_that = _that.parentNode;
|
398
|
-
}
|
399
|
-
if (!_that) {
|
400
|
-
return;
|
401
|
-
}
|
402
|
-
var _this = _that.ctrl;
|
403
|
-
EVENT.blur(_this);
|
404
|
-
Event.stop(e);
|
405
|
-
},
|
406
|
-
|
407
|
-
/** Mid-level focus manager.
|
408
|
-
* Gets called on the onMouseOver event.
|
409
|
-
* Starts listening for onMouseOut to blur.
|
410
|
-
* Delegates focus calls to the high-level event receivers of all
|
411
|
-
* enabled controls registered.
|
412
|
-
**/
|
413
|
-
focus: function(_ctrl) {
|
414
|
-
var _this = EVENT,
|
415
|
-
_elemId = _ctrl.elemId,
|
416
|
-
_elem = ELEM.get(_elemId);
|
417
|
-
if (_this.focused[_elemId] === false ){ // && _this.dragItems.indexOf(_elemId) === -1) {
|
418
|
-
Event.stopObserving(_elem, 'mouseover', _this._mouseOver);
|
419
|
-
Event.observe(_elem, 'mouseout', _this._mouseOut);
|
420
|
-
_this.focused[_elemId] = true;
|
421
|
-
if (_ctrl['focus']) {
|
422
|
-
_ctrl.focus();
|
423
|
-
}
|
424
|
-
}
|
425
|
-
},
|
426
|
-
|
427
|
-
/** Mid-level blur (focus lost) manager.
|
428
|
-
* Gets called on the onMouseOut event.
|
429
|
-
* Starts listening for onMouseOver to (re)focus.
|
430
|
-
* Delegates blur calls to the high-level event receivers of all
|
431
|
-
* enabled controls registered.
|
432
|
-
**/
|
433
|
-
blur: function(_ctrl) {
|
434
|
-
var _this = EVENT,
|
435
|
-
_elemId = _ctrl.elemId,
|
436
|
-
_elem = ELEM.get(_elemId);
|
437
|
-
if (_this.focused[_elemId] === true ){ // && _this.dragItems.indexOf(_elemId) === -1) {
|
438
|
-
Event.stopObserving(_elem, 'mouseout', _this._mouseOut);
|
439
|
-
Event.observe(_elem, 'mouseover', _this._mouseOver);
|
440
|
-
_this.focused[_elemId] = false;
|
441
|
-
if (_ctrl['blur']) {
|
442
|
-
_ctrl.blur();
|
443
|
-
}
|
444
|
-
}
|
445
|
-
},
|
446
|
-
|
447
|
-
/** Mid-level mouse movement manager.
|
448
|
-
* Gets called on the onMouseMove event.
|
449
|
-
* Delegates the following calls to the high-level event receivers of all
|
450
|
-
* enabled controls registered, depending on the events they registered:
|
451
|
-
* - drag
|
452
|
-
* - mouseMove
|
453
|
-
* - endHover
|
454
|
-
* - startHover
|
455
|
-
*
|
456
|
-
**/
|
457
|
-
mouseMove: function(e) {
|
458
|
-
var _this = EVENT,
|
459
|
-
_scrollPos = ELEM.getScrollPosition(0),
|
460
|
-
x = Event.pointerX(e) - _scrollPos[0],
|
461
|
-
y = Event.pointerY(e) - _scrollPos[1],
|
462
|
-
_currentlyDragging = _this.flushMouseMove(x, y);
|
463
|
-
_this.status[_this.crsrX] = x;
|
464
|
-
_this.status[_this.crsrY] = y;
|
465
|
-
_this._modifiers(e);
|
466
|
-
// might work
|
467
|
-
if (_currentlyDragging) {
|
468
|
-
Event.stop(e);
|
469
|
-
}
|
470
|
-
// Only prevent default action when we are dragging something.
|
471
|
-
},
|
472
|
-
|
473
|
-
/** Processes dragging calculations, triggered by mouseMove.
|
474
|
-
**/
|
475
|
-
flushMouseMove: function(x, y) {
|
476
|
-
var _this = EVENT,
|
477
|
-
_currentlyDragging = false,
|
478
|
-
i = 0,
|
479
|
-
j,
|
480
|
-
_elemId,
|
481
|
-
_ctrl;
|
482
|
-
|
483
|
-
clearTimeout(_this._lastCoordFlushTimeout);
|
484
|
-
|
485
|
-
// send drag event to all drag-interested ctrls
|
486
|
-
for (; i < _this.dragItems.length; i++) {
|
487
|
-
_elemId = _this.dragItems[i];
|
488
|
-
_this.focusOptions[_elemId].ctrl.drag(x, y);
|
489
|
-
_this.coordCacheFlush(_elemId);
|
490
|
-
_currentlyDragging = true;
|
491
|
-
}
|
492
|
-
if(!_currentlyDragging){
|
493
|
-
if (new Date().getTime() > _this.hoverTimer + _this.hoverInterval) {
|
494
|
-
// sends mouseMove pseudo-events to ctrls interested
|
495
|
-
for (i = 0; i < _this.coordListeners.length; i++) {
|
496
|
-
_elemId = _this.coordListeners[i];
|
497
|
-
_ctrl = _this.focusOptions[_elemId].ctrl;
|
498
|
-
_ctrl.mouseMove(x, y);
|
499
|
-
}
|
500
|
-
_this.hoverTimer = new Date().getTime();
|
501
|
-
}
|
502
|
-
else {
|
503
|
-
_this._lastCoordFlushTimeout = setTimeout(
|
504
|
-
function(){
|
505
|
-
EVENT.flushMouseMove(x,y);
|
506
|
-
}, _this.hoverInterval
|
507
|
-
);
|
508
|
-
}
|
509
|
-
return false;
|
510
|
-
}
|
511
|
-
|
512
|
-
if (_this.enableDroppableChecks) {
|
513
|
-
// Check which items are under the mouse coordinates now.
|
514
|
-
if (new Date().getTime() > _this.hoverTimer + _this.hoverInterval) {
|
515
|
-
// sends mouseMove pseudo-events to ctrls interested
|
516
|
-
for (i = 0; i < _this.coordListeners.length; i++) {
|
517
|
-
_elemId = _this.coordListeners[i];
|
518
|
-
_ctrl = _this.focusOptions[_elemId].ctrl;
|
519
|
-
_ctrl.mouseMove(x, y);
|
520
|
-
}
|
521
|
-
if (_this.enableDroppableChecks) {
|
522
|
-
_this._updateHoverItems();
|
523
|
-
}
|
524
|
-
// sends drag&drop pseudo-events
|
525
|
-
var _wasTopmostDroppable;
|
526
|
-
for (i = 0; i < _this.dragItems.length; i++) {
|
527
|
-
// Find the current droppable while dragging.
|
528
|
-
_wasTopmostDroppable = _this.topmostDroppable;
|
529
|
-
_this.topmostDroppable = null;
|
530
|
-
_elemId = _this.dragItems[i];
|
531
|
-
_ctrl = _this.focusOptions[_elemId].ctrl;
|
532
|
-
|
533
|
-
// Check for a drop target from the currently hovered items
|
534
|
-
var _hoverIndex,
|
535
|
-
_dropCtrl;
|
536
|
-
for (j = 0; j !== _this.hovered.length; j++) {
|
537
|
-
_hoverIndex = _this.hovered[j];
|
538
|
-
if (_hoverIndex !== _elemId && _this.focusOptions[_hoverIndex].ctrl) {
|
539
|
-
_dropCtrl = _this.focusOptions[_hoverIndex].ctrl;
|
540
|
-
if (
|
541
|
-
// First time
|
542
|
-
!_this.topmostDroppable ||
|
543
|
-
// Z beaten
|
544
|
-
_dropCtrl.zIndex() > _this.topmostDroppable.zIndex() ||
|
545
|
-
// subview
|
546
|
-
_dropCtrl.parent === _this.topmostDroppable
|
547
|
-
) {
|
548
|
-
if (_this.focusOptions[_dropCtrl.elemId].droppable) {
|
549
|
-
_this.topmostDroppable = _dropCtrl;
|
550
|
-
// Finally, the item must accept drop events.
|
551
|
-
}
|
552
|
-
}
|
553
|
-
}
|
554
|
-
}
|
555
|
-
|
556
|
-
// Topmost item has changed, send startHover or endHover to the droppable.
|
557
|
-
if (_wasTopmostDroppable !== _this.topmostDroppable) {
|
558
|
-
if (_wasTopmostDroppable) {
|
559
|
-
_wasTopmostDroppable.endHover(_ctrl);
|
560
|
-
}
|
561
|
-
if (_this.topmostDroppable) {
|
562
|
-
_this.topmostDroppable.startHover(_ctrl);
|
563
|
-
}
|
564
|
-
}
|
565
|
-
}
|
566
|
-
_this.hoverTimer = new Date().getTime();
|
567
|
-
}
|
568
|
-
else {
|
569
|
-
_this._lastCoordFlushTimeout = setTimeout(
|
570
|
-
function(){
|
571
|
-
EVENT.flushMouseMove(x,y);
|
572
|
-
}, _this.hoverInterval
|
573
|
-
);
|
574
|
-
}
|
575
|
-
}
|
576
|
-
return true;
|
577
|
-
},
|
578
|
-
|
579
|
-
// Loops through all registered items and store indices of elements
|
580
|
-
// that are currenly under the mouse cursor in .hovered array. Uses
|
581
|
-
// cached position and dimensions value when possible.
|
582
|
-
_updateHoverItems: function() {
|
583
|
-
var _this = EVENT,
|
584
|
-
x = _this.status[_this.crsrX],
|
585
|
-
y = _this.status[_this.crsrY],
|
586
|
-
i = 0,
|
587
|
-
_ctrl,
|
588
|
-
_elem,
|
589
|
-
_rect,
|
590
|
-
_pos,
|
591
|
-
_size,
|
592
|
-
_coords,
|
593
|
-
_hovered = [];
|
594
|
-
for (; i < _this.listeners.length; i++) {
|
595
|
-
if (!_this.listeners[i] || !_this.focusOptions[i].ctrl) {
|
596
|
-
continue;
|
597
|
-
}
|
598
|
-
_ctrl = _this.focusOptions[i].ctrl;
|
599
|
-
if(_ctrl.drawn){
|
600
|
-
if(ELEM.getStyle(i,'visibility',true) === 'hidden'){
|
601
|
-
continue;
|
602
|
-
}
|
603
|
-
_elem = ELEM.get(i);
|
604
|
-
if (!_this._coordCacheFlag || !_this._coordCache[i]) {
|
605
|
-
_rect = _ctrl.rect;
|
606
|
-
_pos = [_ctrl.pageX(),_ctrl.pageY()];
|
607
|
-
_size = [_rect.width,_rect.height];
|
608
|
-
_this._coordCache[i] = [_pos[0], _pos[1], _size[0], _size[1]];
|
609
|
-
}
|
610
|
-
_coords = _this._coordCache[i];
|
611
|
-
|
612
|
-
// Is the mouse pointer inside the element's rectangle?
|
613
|
-
if (x >= _coords[0] && x <= _coords[0] + _coords[2] && y >= _coords[1] && y <= _coords[1] + _coords[3]) {
|
614
|
-
_hovered.push(i);
|
615
|
-
}
|
616
|
-
}
|
617
|
-
}
|
618
|
-
_this.hovered = _hovered;
|
619
|
-
},
|
620
|
-
|
621
|
-
/** = Description
|
622
|
-
* Starts dragging the control given.
|
623
|
-
*
|
624
|
-
* Call this method to start dragging another component.
|
625
|
-
*
|
626
|
-
* = Parameters
|
627
|
-
* +_ctrl+:: An object that uses the HControl API, becomes new drag target.
|
628
|
-
*
|
629
|
-
**/
|
630
|
-
startDragging: function(_ctrl, _isLeftButton) {
|
631
|
-
// console.log('startDragging');
|
632
|
-
var _this = EVENT;
|
633
|
-
_this.dragItems = [_ctrl.elemId];
|
634
|
-
_this.focus(_ctrl);
|
635
|
-
_this.changeActiveControl(_ctrl);
|
636
|
-
_ctrl.startDrag( _this.status[_this.crsrX], _this.status[_this.crsrY], _isLeftButton );
|
637
|
-
},
|
638
|
-
|
639
|
-
/** Mid-level mouse button press manager.
|
640
|
-
* Gets called on the onMouseDown event.
|
641
|
-
* Delegates the following calls to the high-level event receivers of all
|
642
|
-
* enabled controls registered, depending on the events they registered:
|
643
|
-
* - mouseDown
|
644
|
-
* - startDrag
|
645
|
-
*
|
646
|
-
**/
|
647
|
-
mouseDown: function(e, _isLeftButton) {
|
648
|
-
// console.log('mouseDown');
|
649
|
-
var
|
650
|
-
_this = EVENT,
|
651
|
-
_didStartDrag = false,
|
652
|
-
x = _this.status[_this.crsrX],
|
653
|
-
y = _this.status[_this.crsrY],
|
654
|
-
i = 0,
|
655
|
-
|
656
|
-
// Unset the active control when clicking on anything.
|
657
|
-
_newActiveControl = null,
|
658
|
-
|
659
|
-
// The startDrag and mouseDown event receivers are first collected into
|
660
|
-
// these arrays and the events are sent after the active control status has
|
661
|
-
// been changed.
|
662
|
-
_startDragElementIds = [],
|
663
|
-
_mouseDownElementIds = [];
|
664
|
-
|
665
|
-
_this._modifiers(e);
|
666
|
-
if (_isLeftButton === undefined) {
|
667
|
-
_isLeftButton = Event.isLeftClick(e);
|
668
|
-
}
|
669
|
-
if (_isLeftButton) {
|
670
|
-
_this.status[_this.button1] = true;
|
671
|
-
}
|
672
|
-
else {
|
673
|
-
_this.status[_this.button2] = true;
|
674
|
-
}
|
675
|
-
|
676
|
-
for (; i < _this.focused.length; i++) {
|
677
|
-
if (_this.focused[i] === true) {
|
678
|
-
// Set the active control to the currently focused item.
|
679
|
-
if (_this.focusOptions[i].ctrl.enabled) {
|
680
|
-
_newActiveControl = _this.focusOptions[i].ctrl;
|
681
|
-
}
|
682
|
-
if ((_this.focusOptions[i].draggable === true) && _this.dragItems.indexOf(i) === -1) {
|
683
|
-
_startDragElementIds.push(i);
|
684
|
-
}
|
685
|
-
if (_this.focusOptions[i].mouseDown === true) {
|
686
|
-
_mouseDownElementIds.push(i);
|
687
|
-
}
|
688
|
-
}
|
689
|
-
}
|
690
|
-
// Handle the active control selection.
|
691
|
-
if (_newActiveControl) {
|
692
|
-
_this.changeActiveControl(_newActiveControl);
|
693
|
-
}
|
694
|
-
// Call the mouseDown and startDrag events after the active control change has been handled.
|
695
|
-
for (i = 0; i < _startDragElementIds.length; i++) {
|
696
|
-
_this.dragItems.push(_startDragElementIds[i]);
|
697
|
-
_this.focusOptions[_startDragElementIds[i]].ctrl.startDrag(x, y, _isLeftButton);
|
698
|
-
_didStartDrag = true;
|
699
|
-
}
|
700
|
-
|
701
|
-
var _stopEvent = _mouseDownElementIds.length;
|
702
|
-
for (i = 0; i < _mouseDownElementIds.length; i++) {
|
703
|
-
if (_this.focusOptions[_mouseDownElementIds[i]].ctrl.mouseDown(x, y, _isLeftButton)) {
|
704
|
-
_stopEvent--;
|
705
|
-
}
|
706
|
-
}
|
707
|
-
if (_didStartDrag) {
|
708
|
-
// Remove possible selections.
|
709
|
-
document.body.focus();
|
710
|
-
// Prevent text selection in MSIE when dragging starts.
|
711
|
-
_this._storedOnSelectStart = document.onselectstart;
|
712
|
-
document.onselectstart = function() {
|
713
|
-
return false;
|
714
|
-
};
|
715
|
-
Event.stop(e);
|
716
|
-
}
|
717
|
-
// Stop the event only when we are hovering over some control, allows normal DOM events to co-exist.
|
718
|
-
if (_this.enableDroppableChecks) {
|
719
|
-
// console.log('stopEvent:',_stopEvent,', hoverlen:',(_this.hovered.length !== 0),', newActive:',_newActiveControl);
|
720
|
-
if ( (_mouseDownElementIds.length !== 0) && (_stopEvent === 0) && (_this.hovered.length !== 0) && _newActiveControl) {
|
721
|
-
Event.stop(e);
|
722
|
-
}
|
723
|
-
}
|
724
|
-
// else {
|
725
|
-
// console.log('not enableDroppableChecks');
|
726
|
-
// }
|
727
|
-
return true;
|
728
|
-
},
|
729
|
-
|
730
|
-
/** Mid-level mouse click manager.
|
731
|
-
* Gets called on the onClick event.
|
732
|
-
* Delegates click calls to the high-level event receivers of all
|
733
|
-
* controls registered for that event.
|
734
|
-
*
|
735
|
-
**/
|
736
|
-
click: function(e, _isLeftButton) {
|
737
|
-
// if( new Date().getTime() - EVENT.lastMouseUp < 10 ){
|
738
|
-
// console.log('should prevent click?');
|
739
|
-
// // return false; // prevent click and mousedown coexistence
|
740
|
-
// }
|
741
|
-
// else{
|
742
|
-
// console.log('click');
|
743
|
-
// }
|
744
|
-
var _this = EVENT,
|
745
|
-
x = _this.status[_this.crsrX],
|
746
|
-
y = _this.status[_this.crsrY],
|
747
|
-
i = 0,
|
748
|
-
// Unset the active control when clicking on anything.
|
749
|
-
_newActiveControl = null,
|
750
|
-
// The startDrag and mouseDown event receivers are first collected into
|
751
|
-
// these arrays and the events are sent after the active control status has
|
752
|
-
// been changed.
|
753
|
-
_clickElementIds = [];
|
754
|
-
_this._modifiers(e);
|
755
|
-
if (_isLeftButton === undefined) {
|
756
|
-
_isLeftButton = Event.isLeftClick(e);
|
757
|
-
}
|
758
|
-
if (BROWSER_TYPE.ie && !BROWSER_TYPE.ie9) {
|
759
|
-
_isLeftButton = true; // IE only supports click on left button
|
760
|
-
}
|
761
|
-
// Prevent right-click event from triggering click.
|
762
|
-
// Only firefox seems to fire the click-event with the
|
763
|
-
// right mouse button, so this prevents it from happening
|
764
|
-
// in the name of uniform behavior.
|
765
|
-
if(!_isLeftButton){
|
766
|
-
return true;
|
767
|
-
}
|
768
|
-
var _fCount = 0;
|
769
|
-
for (; i < _this.focused.length; i++) {
|
770
|
-
if (_this.focused[i] === true) {
|
771
|
-
_fCount+=1;
|
772
|
-
// Set the active control to the currently focused item.
|
773
|
-
|
774
|
-
if (_this.focusOptions[i].ctrl.enabled) {
|
775
|
-
_newActiveControl = _this.focusOptions[i].ctrl;
|
776
|
-
}
|
777
|
-
if(_this.traceFocused){
|
778
|
-
_newActiveControl.setStyle('border','2px solid #FF00FF');
|
779
|
-
}
|
780
|
-
if (_this.focusOptions[i].click === true) {
|
781
|
-
_clickElementIds.push(i);
|
782
|
-
}
|
783
|
-
}
|
784
|
-
}
|
785
|
-
console.log('focused length:',_fCount);
|
786
|
-
// Handle the active control selection.
|
787
|
-
if (_newActiveControl) {
|
788
|
-
// console.log('click new active control');
|
789
|
-
_this.changeActiveControl(_newActiveControl);
|
790
|
-
}
|
791
|
-
var _stopEvent = _clickElementIds.length;
|
792
|
-
for (i = 0; i < _clickElementIds.length; i++) {
|
793
|
-
if (_this.focusOptions[_clickElementIds[i]].ctrl.click(x, y, _isLeftButton)) {
|
794
|
-
_stopEvent--;
|
795
|
-
}
|
796
|
-
}
|
797
|
-
if( _stopEvent === 0 ){
|
798
|
-
Event.stop(e);
|
799
|
-
}
|
800
|
-
return true;
|
801
|
-
},
|
802
|
-
|
803
|
-
focusTrace: false,
|
804
|
-
prevActiveCtrl: null,
|
805
|
-
|
806
|
-
/** Changes active ctrl.
|
807
|
-
* The previous active ctrl gets the _lostActiveStatus pseudo-event,
|
808
|
-
* The new active ctrl gets the _gainedActiveStatus pseudo-event
|
809
|
-
**/
|
810
|
-
changeActiveControl: function(_ctrl) {
|
811
|
-
var
|
812
|
-
_this = EVENT,
|
813
|
-
_disAllowLose = true,
|
814
|
-
// Store the currently active control so we can inform it,
|
815
|
-
// if it's no longer the active control.
|
816
|
-
_prevActiveCtrl = _this.activeControl;
|
817
|
-
// Did the active control change?
|
818
|
-
if (_ctrl && (_ctrl !== _prevActiveCtrl) && (_ctrl._gainedActiveStatus || (_prevActiveCtrl && _prevActiveCtrl._lostActiveStatus))) {
|
819
|
-
if (_prevActiveCtrl && _prevActiveCtrl._lostActiveStatus) {
|
820
|
-
// Previously active control just lost the active status.
|
821
|
-
if( _prevActiveCtrl ){
|
822
|
-
_disAllowLose = _prevActiveCtrl._lostActiveStatus(_ctrl) === false;
|
823
|
-
if( _disAllowLose ){
|
824
|
-
// console.log('disallow losing focus: ',_prevActiveCtrl.componentName,' -> ',_ctrl.componentName);
|
825
|
-
return;
|
826
|
-
}
|
827
|
-
// else{
|
828
|
-
// console.log('allow losing focus: ',_prevActiveCtrl.componentName,' -> ',_ctrl.componentName);
|
829
|
-
// }
|
830
|
-
_this.blur(_prevActiveCtrl);
|
831
|
-
_this.focus(_ctrl);
|
832
|
-
_prevActiveCtrl.active = false;
|
833
|
-
if(_this.focusTrace){
|
834
|
-
_prevActiveCtrl.setStyle('border','2px solid green');
|
835
|
-
if( _this.prevActiveCtrl ){
|
836
|
-
_this.prevActiveCtrl.setStyle('border','2px solid blue');
|
837
|
-
}
|
838
|
-
}
|
839
|
-
}
|
840
|
-
_this.prevActiveCtrl = _prevActiveCtrl;
|
841
|
-
}
|
842
|
-
if (_ctrl && _ctrl._gainedActiveStatus) {
|
843
|
-
// A new control gained the active status.
|
844
|
-
_ctrl.active = true;
|
845
|
-
_this.activeControl = _ctrl;
|
846
|
-
_ctrl._gainedActiveStatus(_prevActiveCtrl);
|
847
|
-
if(_this.focusTrace){
|
848
|
-
_ctrl.setStyle('border','2px solid red');
|
849
|
-
}
|
850
|
-
}
|
851
|
-
else {
|
852
|
-
_this.activeControl = null;
|
853
|
-
}
|
854
|
-
}
|
855
|
-
|
856
|
-
},
|
857
|
-
|
858
|
-
|
859
|
-
/** Mid-level mouse button release manager.
|
860
|
-
* Gets called on the onMouseUp event.
|
861
|
-
* Delegates the following calls to the high-level event receivers of all
|
862
|
-
* enabled controls registered, depending on the events they registered:
|
863
|
-
* - mouseUp
|
864
|
-
* - endHover
|
865
|
-
* - drop
|
866
|
-
* - endDrag
|
867
|
-
*
|
868
|
-
**/
|
869
|
-
// lastMouseUp: 0,
|
870
|
-
mouseUp: function(e) {
|
871
|
-
// console.log('mouseUp',EVENT.dragItems.length);
|
872
|
-
// EVENT.lastMouseUp = new Date().getTime();
|
873
|
-
var
|
874
|
-
_this = EVENT,
|
875
|
-
_didEndDrag = false,
|
876
|
-
_isLeftButton = Event.isLeftClick(e),
|
877
|
-
x = _this.status[_this.crsrX],
|
878
|
-
y = _this.status[_this.crsrY],
|
879
|
-
_elemId,
|
880
|
-
_ctrl,
|
881
|
-
i = 0;
|
882
|
-
_this._modifiers(e);
|
883
|
-
// Send endDrag for the currently dragged items even when they don't have focus, and clear the drag item array.
|
884
|
-
for (; i < _this.dragItems.length; i++) {
|
885
|
-
_elemId = _this.dragItems[i];
|
886
|
-
_ctrl = _this.focusOptions[_elemId].ctrl;
|
887
|
-
_ctrl.endDrag(x, y, _isLeftButton);
|
888
|
-
_didEndDrag = true;
|
889
|
-
// If the mouse slipped off the dragged item before the mouse button was released, blur the item manually
|
890
|
-
if (_this.enableDroppableChecks) {
|
891
|
-
_this._updateHoverItems();
|
892
|
-
if (_this.hovered.indexOf(_elemId) === -1) {
|
893
|
-
_this.blur(_ctrl);
|
894
|
-
}
|
895
|
-
}
|
896
|
-
// If there is a drop target in the currently hovered items, send drop to it.
|
897
|
-
if (_this.topmostDroppable) {
|
898
|
-
// Droppable found at the release point.
|
899
|
-
_this.topmostDroppable.endHover(_ctrl);
|
900
|
-
_this.topmostDroppable.drop(_ctrl);
|
901
|
-
_this.topmostDroppable = null;
|
902
|
-
}
|
903
|
-
}
|
904
|
-
_this.dragItems = [];
|
905
|
-
// Restore MSIE's ability to select text after dragging has ended.
|
906
|
-
if (_didEndDrag) {
|
907
|
-
document.onselectstart = _this._storedOnSelectStart;
|
908
|
-
}
|
909
|
-
// Check for mouseUp listeners.
|
910
|
-
for (i = 0; i < _this.focused.length; i++) {
|
911
|
-
if (_this.focused[i] === true) {
|
912
|
-
_ctrl = _this.focusOptions[i].ctrl;
|
913
|
-
if (_this.focusOptions[i].mouseUp === true) {
|
914
|
-
if( _ctrl.mouseUp(x, y, _isLeftButton) ){
|
915
|
-
// Event.stop(e);
|
916
|
-
}
|
917
|
-
}
|
918
|
-
}
|
919
|
-
}
|
920
|
-
if(_isLeftButton){
|
921
|
-
_this.status[_this.button1] = false;
|
922
|
-
}
|
923
|
-
else {
|
924
|
-
_this.status[_this.button2] = false;
|
925
|
-
}
|
926
|
-
return true;
|
927
|
-
},
|
928
|
-
|
929
|
-
/** Mid-level double-click manager.
|
930
|
-
* Gets called on the onDoubleClick event.
|
931
|
-
* Delegates the following call to the high-level event receivers of all
|
932
|
-
* enabled controls registered, depending on the events they registered:
|
933
|
-
* - doubleClick
|
934
|
-
*
|
935
|
-
**/
|
936
|
-
doubleClick: function(e) {
|
937
|
-
var _this = EVENT,
|
938
|
-
x = _this.status[_this.crsrX],
|
939
|
-
y = _this.status[_this.crsrY],
|
940
|
-
_elemId,
|
941
|
-
_ctrl,
|
942
|
-
i = 0;
|
943
|
-
_this._modifiers(e);
|
944
|
-
// Check for doubleClick listeners.
|
945
|
-
for (i = 0; i < _this.focused.length; i++) {
|
946
|
-
if (_this.focused[i] === true) {
|
947
|
-
if (_this.focusOptions[i].doubleClick === true) {
|
948
|
-
if ( _this.focusOptions[i].ctrl.doubleClick(x, y, true) ){
|
949
|
-
Event.stop(e);
|
950
|
-
}
|
951
|
-
}
|
952
|
-
}
|
953
|
-
}
|
954
|
-
return true;
|
955
|
-
},
|
956
|
-
|
957
|
-
|
958
|
-
/** Mid-level mouse scroll wheel event manager.
|
959
|
-
* Delegates mouseWheel calls to the high-level event receivers of all
|
960
|
-
* controls registered for that event.
|
961
|
-
**/
|
962
|
-
mouseWheel: function(e) {
|
963
|
-
var _this = EVENT,
|
964
|
-
_delta = 0,
|
965
|
-
i = 0;
|
966
|
-
if (!e) {
|
967
|
-
e = window.event;
|
968
|
-
}
|
969
|
-
if (e.wheelDelta) {
|
970
|
-
_delta = 0 - (e.wheelDelta / 120);
|
971
|
-
}
|
972
|
-
else if (e.detail) {
|
973
|
-
_delta = 0 - (e.detail / 3);
|
974
|
-
}
|
975
|
-
if (BROWSER_TYPE.opera || BROWSER_TYPE.safari || BROWSER_TYPE.ie) {
|
976
|
-
_delta = 0 - _delta;
|
977
|
-
}
|
978
|
-
for (; i < _this.focused.length; i++) {
|
979
|
-
if (_this.focused[i] === true) {
|
980
|
-
if (_this.focusOptions[i].mouseWheel === true) {
|
981
|
-
Event.stop(e);
|
982
|
-
_this.focusOptions[i].ctrl.mouseWheel(_delta);
|
983
|
-
}
|
984
|
-
}
|
985
|
-
}
|
986
|
-
},
|
987
|
-
|
988
|
-
/** Mid-level context menu manager.
|
989
|
-
* Gets called on the onContextMenu event.
|
990
|
-
* Delegates the following call to the high-level event receivers of all
|
991
|
-
* enabled controls registered, depending on the events they registered:
|
992
|
-
* - contextMenu
|
993
|
-
*
|
994
|
-
* Just make a component return true to allow the browser's default action.
|
995
|
-
*
|
996
|
-
**/
|
997
|
-
contextMenu: function(e) {
|
998
|
-
var _this = EVENT,
|
999
|
-
x = _this.status[_this.crsrX],
|
1000
|
-
y = _this.status[_this.crsrY],
|
1001
|
-
_preventDefault = true,
|
1002
|
-
_elemId,
|
1003
|
-
_ctrl,
|
1004
|
-
i = 0;
|
1005
|
-
_this._modifiers(e);
|
1006
|
-
// Check for contextMenu listeners.
|
1007
|
-
for (i = 0; i < _this.focused.length; i++) {
|
1008
|
-
if (_this.focused[i] === true) {
|
1009
|
-
if (_this.focusOptions[i].contextMenu === true) {
|
1010
|
-
if( _this.focusOptions[i].ctrl.contextMenu() ){
|
1011
|
-
_preventDefault = false;
|
1012
|
-
}
|
1013
|
-
}
|
1014
|
-
}
|
1015
|
-
}
|
1016
|
-
if( _preventDefault ){
|
1017
|
-
Event.stop( e );
|
1018
|
-
}
|
1019
|
-
return true;
|
1020
|
-
},
|
1021
|
-
|
1022
|
-
|
1023
|
-
/** Mid-level key press manager.
|
1024
|
-
* Gets called on the onKeyDown event.
|
1025
|
-
* Delegates keyDown calls to the high-level event receivers of all
|
1026
|
-
* controls registered for that event.
|
1027
|
-
**/
|
1028
|
-
keyDown: function(e) {
|
1029
|
-
var
|
1030
|
-
_this = EVENT,
|
1031
|
-
_keyCode = _this.translateKeyCodes(e.keyCode),
|
1032
|
-
_keyDownStateForActiveControl = _this.activeControl?(_this.focusOptions[_this.activeControl.elemId]?_this.focusOptions[_this.activeControl.elemId].keyDown:false):false,
|
1033
|
-
_repeat = (_keyDownStateForActiveControl === 'repeat'),
|
1034
|
-
_stopEvent = false;
|
1035
|
-
_this._modifiers(e);
|
1036
|
-
_this._lastKeyPressTime = new Date().getTime();
|
1037
|
-
if(!_this.status[_this.cmdKeyDown] && _this._detectCmdKey(_keyCode)){
|
1038
|
-
_this.status[_this.cmdKeyDown] = true;
|
1039
|
-
}
|
1040
|
-
if (_this.activeControl && _keyDownStateForActiveControl) {
|
1041
|
-
if ((_this._lastKeyDown !== _keyCode) || _repeat) {
|
1042
|
-
if(_this.activeControl.keyDown(_keyCode)){
|
1043
|
-
_stopEvent = true;
|
1044
|
-
}
|
1045
|
-
}
|
1046
|
-
}
|
1047
|
-
// Insert key to the realtime array, remove in keyUp
|
1048
|
-
if(!_this.isKeyDown(_keyCode)) {
|
1049
|
-
_this.status[_this.keysDown].push(_keyCode);
|
1050
|
-
}
|
1051
|
-
if (!_this.status[_this.cmdKeyDown] && _stopEvent){
|
1052
|
-
Event.stop(e);
|
1053
|
-
}
|
1054
|
-
_this._lastKeyDown = _keyCode;
|
1055
|
-
},
|
1056
|
-
|
1057
|
-
|
1058
|
-
/** Mid-level key release manager.
|
1059
|
-
* Gets called on the onKeyUp event.
|
1060
|
-
* Delegates keyUp calls to the high-level event receivers of all
|
1061
|
-
* controls registered for that event.
|
1062
|
-
* Also delegates the textEnter calls to all controls
|
1063
|
-
* registered for that event.
|
1064
|
-
**/
|
1065
|
-
keyUp: function(e) {
|
1066
|
-
var
|
1067
|
-
_this = EVENT,
|
1068
|
-
_keyCode = _this.translateKeyCodes(e.keyCode),
|
1069
|
-
_keyCodeIndex,
|
1070
|
-
i = 0,
|
1071
|
-
_stopEvent = false,
|
1072
|
-
_ctrlId,
|
1073
|
-
_ctrl;
|
1074
|
-
_this._modifiers(e);
|
1075
|
-
_this._lastKeyDown = null;
|
1076
|
-
if (_this.activeControl && _this.activeControl.elemId && _this.focusOptions[_this.activeControl.elemId].keyUp === true) {
|
1077
|
-
if(_this.activeControl.keyUp(_keyCode)){
|
1078
|
-
_stopEvent = true;
|
1079
|
-
}
|
1080
|
-
}
|
1081
|
-
for (; i < _this.textEnterCtrls.length; i++) {
|
1082
|
-
_ctrlId = _this.textEnterCtrls[i];
|
1083
|
-
_ctrl = HSystem.views[_ctrlId];
|
1084
|
-
if (_ctrl.textEnter) {
|
1085
|
-
if(_ctrl.textEnter()){
|
1086
|
-
_stopEvent = true;
|
1087
|
-
}
|
1088
|
-
}
|
1089
|
-
}
|
1090
|
-
if (!_this.status[_this.cmdKeyDown] && _stopEvent){
|
1091
|
-
Event.stop(e);
|
1092
|
-
}
|
1093
|
-
if(_this.status[_this.cmdKeyDown] && _this._detectCmdKey(_keyCode)){
|
1094
|
-
_this.status[_this.cmdKeyDown] = false;
|
1095
|
-
}
|
1096
|
-
// Remove the key from the realtime array, inserted in keyDown
|
1097
|
-
if(_this.isKeyDown(_keyCode)){
|
1098
|
-
_keyCodeIndex = _this.status[_this.keysDown].indexOf(_keyCode);
|
1099
|
-
_this.status[_this.keysDown].splice(_keyCodeIndex, 1);
|
1100
|
-
}
|
1101
|
-
},
|
1102
|
-
|
1103
|
-
isKeyDown: function(_keyCode){
|
1104
|
-
return ( this.status[this.keysDown].indexOf(_keyCode) !== -1 );
|
1105
|
-
},
|
1106
|
-
|
1107
|
-
isKeyUp: function(_keyCode){
|
1108
|
-
return !this.isKeyDown(_keyCode);
|
1109
|
-
},
|
1110
|
-
|
1111
|
-
isAltKeyDown: function(){
|
1112
|
-
return this.status[this.altKeyDown];
|
1113
|
-
},
|
1114
|
-
|
1115
|
-
isCtrlKeyDown: function(){
|
1116
|
-
return this.status[this.ctrlKeyDown];
|
1117
|
-
},
|
1118
|
-
|
1119
|
-
isShiftKeyDown: function(){
|
1120
|
-
return this.status[this.shiftKeyDown];
|
1121
|
-
},
|
1122
|
-
|
1123
|
-
isMetaKeyDown: function(){
|
1124
|
-
return this.status[this.metaKeyDown];
|
1125
|
-
},
|
1126
|
-
|
1127
|
-
/* The keyPress itself is ignored per se and used only as a repetition event for the last keyDown. */
|
1128
|
-
keyPress: function(e) {
|
1129
|
-
var
|
1130
|
-
_this = EVENT,
|
1131
|
-
_timeNow = new Date().getTime();
|
1132
|
-
_this._modifiers(e);
|
1133
|
-
// Prevent non-repeat behaviour by waiting at least 100ms before repeating
|
1134
|
-
if(_this._lastKeyPressTime > (_timeNow-100)){
|
1135
|
-
return;
|
1136
|
-
}
|
1137
|
-
if(_this._lastKeyDown !== null){
|
1138
|
-
var
|
1139
|
-
_keyCode = _this.translateKeyCodes(_this._lastKeyDown),
|
1140
|
-
_keyDownStateForActiveControl = _this.activeControl?(_this.focusOptions[_this.activeControl.elemId]?_this.focusOptions[_this.activeControl.elemId].keyDown:false):false,
|
1141
|
-
_repeat = (_keyDownStateForActiveControl === 'repeat'),
|
1142
|
-
_stopEvent = false;
|
1143
|
-
if (_this.activeControl && _keyDownStateForActiveControl && _repeat) {
|
1144
|
-
if(_this.activeControl.keyDown(_keyCode)){
|
1145
|
-
_stopEvent = true;
|
1146
|
-
}
|
1147
|
-
}
|
1148
|
-
if(_stopEvent){
|
1149
|
-
Event.stop(e);
|
1150
|
-
}
|
1151
|
-
}
|
1152
|
-
},
|
1153
|
-
|
1154
|
-
|
1155
|
-
// Normalization map of keyCodes for Opera specifically
|
1156
|
-
_operaKeyCodeTranslations: {
|
1157
|
-
|
1158
|
-
// Symbol keys:
|
1159
|
-
59: 186, // [;:]
|
1160
|
-
61: 187, // [=+]
|
1161
|
-
44: 188, // [,<]
|
1162
|
-
45: 189, // [-_]
|
1163
|
-
46: 190, // [.>]
|
1164
|
-
47: 191, // [/?]
|
1165
|
-
96: 192, // [`~]
|
1166
|
-
91: 219, // [[{]
|
1167
|
-
92: 220, // [\|]
|
1168
|
-
93: 221, // []}]
|
1169
|
-
39: 222, // ['"]
|
1170
|
-
|
1171
|
-
// Numeric keypad keys can't be mapped on Opera, because Opera
|
1172
|
-
// doesn't differentiate between the keys on the numeric keypad
|
1173
|
-
// versus the functionally same keys elsewhere on the keyboard.
|
1174
|
-
|
1175
|
-
// Branded keys:
|
1176
|
-
// Apple Command keys are same as ctrl, but ctrl is 0; Can't be re-mapped reliably.
|
1177
|
-
// The Windows Menu key also return 0, so it can't be re-mapped either.
|
1178
|
-
219: 91, // Left Windows key (Start)
|
1179
|
-
220: 92 // Right Windows key (Start)
|
1180
|
-
},
|
1181
|
-
|
1182
|
-
// Normalization map of keyCodes for Gecko (Mozilla) browsers specifically
|
1183
|
-
_mozillaKeyCodeTranslations: {
|
1184
|
-
|
1185
|
-
// Symbol keys:
|
1186
|
-
59: 186, // [;:]
|
1187
|
-
61: 187, // [=+]
|
1188
|
-
109: 189, // [-_]
|
1189
|
-
|
1190
|
-
// Branded keys:
|
1191
|
-
224: 91 // Apple Command key to left windows key mapping
|
1192
|
-
|
1193
|
-
},
|
1194
|
-
|
1195
|
-
/** Translates keyCodes to the normalized pseudo-ascii used by IE and WebKit browsers.
|
1196
|
-
* Opera and Mozilla browsers use different codes, so they'll need translations.
|
1197
|
-
**/
|
1198
|
-
translateKeyCodes: function(_keyCode){
|
1199
|
-
var
|
1200
|
-
_this = EVENT,
|
1201
|
-
_transCode;
|
1202
|
-
|
1203
|
-
// We use the WebKit and IE browsers as the normalization base, because
|
1204
|
-
// there is no variance between in these. Returns the keyCode as-is for
|
1205
|
-
// browsers in this category.
|
1206
|
-
if(BROWSER_TYPE.safari || BROWSER_TYPE.ie){
|
1207
|
-
return _keyCode;
|
1208
|
-
}
|
1209
|
-
// Opera has its own keyCodes, which are different from all others.
|
1210
|
-
else if(BROWSER_TYPE.opera){
|
1211
|
-
_transCode = _this._operaKeyCodeTranslations[_keyCode];
|
1212
|
-
}
|
1213
|
-
// The assumption is that the other browsers do what mozille does.
|
1214
|
-
else {
|
1215
|
-
_transCode = _this._mozillaKeyCodeTranslations[_keyCode];
|
1216
|
-
}
|
1217
|
-
if(_transCode === undefined || _transCode === null){
|
1218
|
-
return _keyCode;
|
1219
|
-
}
|
1220
|
-
// else {
|
1221
|
-
// console.log('key map from:',_keyCode,' to:',_transCode);
|
1222
|
-
// }
|
1223
|
-
return _transCode;
|
1224
|
-
},
|
1225
|
-
|
1226
|
-
_cmdKeys: [
|
1227
|
-
17, // Ctrl
|
1228
|
-
91, // Others (Left Start Key or Left Command Key)
|
1229
|
-
92, // Others (Right Start Key)
|
1230
|
-
93 // Others (Menu Key or Right Command Key)
|
1231
|
-
],
|
1232
|
-
_detectCmdKey: function( _keyCode ) {
|
1233
|
-
|
1234
|
-
// On Opera, return true on any of the keycodes
|
1235
|
-
if(BROWSER_TYPE.opera){
|
1236
|
-
return (EVENT._cmdKeys.indexOf(_keyCode) !== -1);
|
1237
|
-
}
|
1238
|
-
// Any mac browser (except opera, above) uses left or right windows key
|
1239
|
-
// equivalent as the Command key.
|
1240
|
-
else if(BROWSER_TYPE.mac){
|
1241
|
-
return ((_keyCode === 91) || (_keyCode === 93));
|
1242
|
-
}
|
1243
|
-
// Other platforms use CTRL as the command key.
|
1244
|
-
else {
|
1245
|
-
return (_keyCode === 17);
|
1246
|
-
}
|
1247
|
-
},
|
1248
|
-
|
1249
|
-
/* Handle the event modifiers. */
|
1250
|
-
_modifiers: function(e) {
|
1251
|
-
var _this = EVENT;
|
1252
|
-
_this.status[_this.altKeyDown] = e.altKey;
|
1253
|
-
_this.status[_this.ctrlKeyDown] = e.ctrlKey;
|
1254
|
-
_this.status[_this.shiftKeyDown] = e.shiftKey;
|
1255
|
-
_this.status[_this.metaKeyDown] = e.metaKey;
|
1256
|
-
}
|
1257
|
-
|
1258
|
-
};
|
1259
|
-
|
1260
|
-
var//RSence.Foundation
|
1261
|
-
EventManager = EVENT;
|
1262
|
-
|
1263
|
-
|
1264
|
-
/** Starts the only instance
|
1265
|
-
*/
|
1266
|
-
LOAD(
|
1267
|
-
function() {
|
1268
|
-
EVENT.start();
|
1269
|
-
}
|
1270
|
-
);
|