Subversion Repositories Applications.papyrus

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1318 alexandre_ 1
/*
2
	Copyright (c) 2004-2006, The Dojo Foundation
3
	All Rights Reserved.
4
 
5
	Licensed under the Academic Free License version 2.1 or above OR the
6
	modified BSD license. For more information on Dojo licensing, see:
7
 
8
		http://dojotoolkit.org/community/licensing.shtml
9
*/
10
 
11
dojo.provide("dojo.event.browser");
12
dojo.require("dojo.event.common");
13
dojo._ie_clobber = new function () {
14
	this.clobberNodes = [];
15
	function nukeProp(node, prop) {
16
		try {
17
			node[prop] = null;
18
		}
19
		catch (e) {
20
		}
21
		try {
22
			delete node[prop];
23
		}
24
		catch (e) {
25
		}
26
		try {
27
			node.removeAttribute(prop);
28
		}
29
		catch (e) {
30
		}
31
	}
32
	this.clobber = function (nodeRef) {
33
		var na;
34
		var tna;
35
		if (nodeRef) {
36
			tna = nodeRef.all || nodeRef.getElementsByTagName("*");
37
			na = [nodeRef];
38
			for (var x = 0; x < tna.length; x++) {
39
				if (tna[x]["__doClobber__"]) {
40
					na.push(tna[x]);
41
				}
42
			}
43
		} else {
44
			try {
45
				window.onload = null;
46
			}
47
			catch (e) {
48
			}
49
			na = (this.clobberNodes.length) ? this.clobberNodes : document.all;
50
		}
51
		tna = null;
52
		var basis = {};
53
		for (var i = na.length - 1; i >= 0; i = i - 1) {
54
			var el = na[i];
55
			try {
56
				if (el && el["__clobberAttrs__"]) {
57
					for (var j = 0; j < el.__clobberAttrs__.length; j++) {
58
						nukeProp(el, el.__clobberAttrs__[j]);
59
					}
60
					nukeProp(el, "__clobberAttrs__");
61
					nukeProp(el, "__doClobber__");
62
				}
63
			}
64
			catch (e) {
65
			}
66
		}
67
		na = null;
68
	};
69
};
70
if (dojo.render.html.ie) {
71
	dojo.addOnUnload(function () {
72
		dojo._ie_clobber.clobber();
73
		try {
74
			if ((dojo["widget"]) && (dojo.widget["manager"])) {
75
				dojo.widget.manager.destroyAll();
76
			}
77
		}
78
		catch (e) {
79
		}
80
		if (dojo.widget) {
81
			for (var name in dojo.widget._templateCache) {
82
				if (dojo.widget._templateCache[name].node) {
83
					dojo.dom.destroyNode(dojo.widget._templateCache[name].node);
84
					dojo.widget._templateCache[name].node = null;
85
					delete dojo.widget._templateCache[name].node;
86
				}
87
			}
88
		}
89
		try {
90
			window.onload = null;
91
		}
92
		catch (e) {
93
		}
94
		try {
95
			window.onunload = null;
96
		}
97
		catch (e) {
98
		}
99
		dojo._ie_clobber.clobberNodes = [];
100
	});
101
}
102
dojo.event.browser = new function () {
103
	var clobberIdx = 0;
104
	this.normalizedEventName = function (eventName) {
105
		switch (eventName) {
106
		  case "CheckboxStateChange":
107
		  case "DOMAttrModified":
108
		  case "DOMMenuItemActive":
109
		  case "DOMMenuItemInactive":
110
		  case "DOMMouseScroll":
111
		  case "DOMNodeInserted":
112
		  case "DOMNodeRemoved":
113
		  case "RadioStateChange":
114
			return eventName;
115
			break;
116
		  default:
117
			var lcn = eventName.toLowerCase();
118
			return (lcn.indexOf("on") == 0) ? lcn.substr(2) : lcn;
119
			break;
120
		}
121
	};
122
	this.clean = function (node) {
123
		if (dojo.render.html.ie) {
124
			dojo._ie_clobber.clobber(node);
125
		}
126
	};
127
	this.addClobberNode = function (node) {
128
		if (!dojo.render.html.ie) {
129
			return;
130
		}
131
		if (!node["__doClobber__"]) {
132
			node.__doClobber__ = true;
133
			dojo._ie_clobber.clobberNodes.push(node);
134
			node.__clobberAttrs__ = [];
135
		}
136
	};
137
	this.addClobberNodeAttrs = function (node, props) {
138
		if (!dojo.render.html.ie) {
139
			return;
140
		}
141
		this.addClobberNode(node);
142
		for (var x = 0; x < props.length; x++) {
143
			node.__clobberAttrs__.push(props[x]);
144
		}
145
	};
146
	this.removeListener = function (node, evtName, fp, capture) {
147
		if (!capture) {
148
			var capture = false;
149
		}
150
		evtName = dojo.event.browser.normalizedEventName(evtName);
151
		if (evtName == "key") {
152
			if (dojo.render.html.ie) {
153
				this.removeListener(node, "onkeydown", fp, capture);
154
			}
155
			evtName = "keypress";
156
		}
157
		if (node.removeEventListener) {
158
			node.removeEventListener(evtName, fp, capture);
159
		}
160
	};
161
	this.addListener = function (node, evtName, fp, capture, dontFix) {
162
		if (!node) {
163
			return;
164
		}
165
		if (!capture) {
166
			var capture = false;
167
		}
168
		evtName = dojo.event.browser.normalizedEventName(evtName);
169
		if (evtName == "key") {
170
			if (dojo.render.html.ie) {
171
				this.addListener(node, "onkeydown", fp, capture, dontFix);
172
			}
173
			evtName = "keypress";
174
		}
175
		if (!dontFix) {
176
			var newfp = function (evt) {
177
				if (!evt) {
178
					evt = window.event;
179
				}
180
				var ret = fp(dojo.event.browser.fixEvent(evt, this));
181
				if (capture) {
182
					dojo.event.browser.stopEvent(evt);
183
				}
184
				return ret;
185
			};
186
		} else {
187
			newfp = fp;
188
		}
189
		if (node.addEventListener) {
190
			node.addEventListener(evtName, newfp, capture);
191
			return newfp;
192
		} else {
193
			evtName = "on" + evtName;
194
			if (typeof node[evtName] == "function") {
195
				var oldEvt = node[evtName];
196
				node[evtName] = function (e) {
197
					oldEvt(e);
198
					return newfp(e);
199
				};
200
			} else {
201
				node[evtName] = newfp;
202
			}
203
			if (dojo.render.html.ie) {
204
				this.addClobberNodeAttrs(node, [evtName]);
205
			}
206
			return newfp;
207
		}
208
	};
209
	this.isEvent = function (obj) {
210
		return (typeof obj != "undefined") && (obj) && (typeof Event != "undefined") && (obj.eventPhase);
211
	};
212
	this.currentEvent = null;
213
	this.callListener = function (listener, curTarget) {
214
		if (typeof listener != "function") {
215
			dojo.raise("listener not a function: " + listener);
216
		}
217
		dojo.event.browser.currentEvent.currentTarget = curTarget;
218
		return listener.call(curTarget, dojo.event.browser.currentEvent);
219
	};
220
	this._stopPropagation = function () {
221
		dojo.event.browser.currentEvent.cancelBubble = true;
222
	};
223
	this._preventDefault = function () {
224
		dojo.event.browser.currentEvent.returnValue = false;
225
	};
226
	this.keys = {KEY_BACKSPACE:8, KEY_TAB:9, KEY_CLEAR:12, KEY_ENTER:13, KEY_SHIFT:16, KEY_CTRL:17, KEY_ALT:18, KEY_PAUSE:19, KEY_CAPS_LOCK:20, KEY_ESCAPE:27, KEY_SPACE:32, KEY_PAGE_UP:33, KEY_PAGE_DOWN:34, KEY_END:35, KEY_HOME:36, KEY_LEFT_ARROW:37, KEY_UP_ARROW:38, KEY_RIGHT_ARROW:39, KEY_DOWN_ARROW:40, KEY_INSERT:45, KEY_DELETE:46, KEY_HELP:47, KEY_LEFT_WINDOW:91, KEY_RIGHT_WINDOW:92, KEY_SELECT:93, KEY_NUMPAD_0:96, KEY_NUMPAD_1:97, KEY_NUMPAD_2:98, KEY_NUMPAD_3:99, KEY_NUMPAD_4:100, KEY_NUMPAD_5:101, KEY_NUMPAD_6:102, KEY_NUMPAD_7:103, KEY_NUMPAD_8:104, KEY_NUMPAD_9:105, KEY_NUMPAD_MULTIPLY:106, KEY_NUMPAD_PLUS:107, KEY_NUMPAD_ENTER:108, KEY_NUMPAD_MINUS:109, KEY_NUMPAD_PERIOD:110, KEY_NUMPAD_DIVIDE:111, KEY_F1:112, KEY_F2:113, KEY_F3:114, KEY_F4:115, KEY_F5:116, KEY_F6:117, KEY_F7:118, KEY_F8:119, KEY_F9:120, KEY_F10:121, KEY_F11:122, KEY_F12:123, KEY_F13:124, KEY_F14:125, KEY_F15:126, KEY_NUM_LOCK:144, KEY_SCROLL_LOCK:145};
227
	this.revKeys = [];
228
	for (var key in this.keys) {
229
		this.revKeys[this.keys[key]] = key;
230
	}
231
	this.fixEvent = function (evt, sender) {
232
		if (!evt) {
233
			if (window["event"]) {
234
				evt = window.event;
235
			}
236
		}
237
		if ((evt["type"]) && (evt["type"].indexOf("key") == 0)) {
238
			evt.keys = this.revKeys;
239
			for (var key in this.keys) {
240
				evt[key] = this.keys[key];
241
			}
242
			if (evt["type"] == "keydown" && dojo.render.html.ie) {
243
				switch (evt.keyCode) {
244
				  case evt.KEY_SHIFT:
245
				  case evt.KEY_CTRL:
246
				  case evt.KEY_ALT:
247
				  case evt.KEY_CAPS_LOCK:
248
				  case evt.KEY_LEFT_WINDOW:
249
				  case evt.KEY_RIGHT_WINDOW:
250
				  case evt.KEY_SELECT:
251
				  case evt.KEY_NUM_LOCK:
252
				  case evt.KEY_SCROLL_LOCK:
253
				  case evt.KEY_NUMPAD_0:
254
				  case evt.KEY_NUMPAD_1:
255
				  case evt.KEY_NUMPAD_2:
256
				  case evt.KEY_NUMPAD_3:
257
				  case evt.KEY_NUMPAD_4:
258
				  case evt.KEY_NUMPAD_5:
259
				  case evt.KEY_NUMPAD_6:
260
				  case evt.KEY_NUMPAD_7:
261
				  case evt.KEY_NUMPAD_8:
262
				  case evt.KEY_NUMPAD_9:
263
				  case evt.KEY_NUMPAD_PERIOD:
264
					break;
265
				  case evt.KEY_NUMPAD_MULTIPLY:
266
				  case evt.KEY_NUMPAD_PLUS:
267
				  case evt.KEY_NUMPAD_ENTER:
268
				  case evt.KEY_NUMPAD_MINUS:
269
				  case evt.KEY_NUMPAD_DIVIDE:
270
					break;
271
				  case evt.KEY_PAUSE:
272
				  case evt.KEY_TAB:
273
				  case evt.KEY_BACKSPACE:
274
				  case evt.KEY_ENTER:
275
				  case evt.KEY_ESCAPE:
276
				  case evt.KEY_PAGE_UP:
277
				  case evt.KEY_PAGE_DOWN:
278
				  case evt.KEY_END:
279
				  case evt.KEY_HOME:
280
				  case evt.KEY_LEFT_ARROW:
281
				  case evt.KEY_UP_ARROW:
282
				  case evt.KEY_RIGHT_ARROW:
283
				  case evt.KEY_DOWN_ARROW:
284
				  case evt.KEY_INSERT:
285
				  case evt.KEY_DELETE:
286
				  case evt.KEY_F1:
287
				  case evt.KEY_F2:
288
				  case evt.KEY_F3:
289
				  case evt.KEY_F4:
290
				  case evt.KEY_F5:
291
				  case evt.KEY_F6:
292
				  case evt.KEY_F7:
293
				  case evt.KEY_F8:
294
				  case evt.KEY_F9:
295
				  case evt.KEY_F10:
296
				  case evt.KEY_F11:
297
				  case evt.KEY_F12:
298
				  case evt.KEY_F12:
299
				  case evt.KEY_F13:
300
				  case evt.KEY_F14:
301
				  case evt.KEY_F15:
302
				  case evt.KEY_CLEAR:
303
				  case evt.KEY_HELP:
304
					evt.key = evt.keyCode;
305
					break;
306
				  default:
307
					if (evt.ctrlKey || evt.altKey) {
308
						var unifiedCharCode = evt.keyCode;
309
						if (unifiedCharCode >= 65 && unifiedCharCode <= 90 && evt.shiftKey == false) {
310
							unifiedCharCode += 32;
311
						}
312
						if (unifiedCharCode >= 1 && unifiedCharCode <= 26 && evt.ctrlKey) {
313
							unifiedCharCode += 96;
314
						}
315
						evt.key = String.fromCharCode(unifiedCharCode);
316
					}
317
				}
318
			} else {
319
				if (evt["type"] == "keypress") {
320
					if (dojo.render.html.opera) {
321
						if (evt.which == 0) {
322
							evt.key = evt.keyCode;
323
						} else {
324
							if (evt.which > 0) {
325
								switch (evt.which) {
326
								  case evt.KEY_SHIFT:
327
								  case evt.KEY_CTRL:
328
								  case evt.KEY_ALT:
329
								  case evt.KEY_CAPS_LOCK:
330
								  case evt.KEY_NUM_LOCK:
331
								  case evt.KEY_SCROLL_LOCK:
332
									break;
333
								  case evt.KEY_PAUSE:
334
								  case evt.KEY_TAB:
335
								  case evt.KEY_BACKSPACE:
336
								  case evt.KEY_ENTER:
337
								  case evt.KEY_ESCAPE:
338
									evt.key = evt.which;
339
									break;
340
								  default:
341
									var unifiedCharCode = evt.which;
342
									if ((evt.ctrlKey || evt.altKey || evt.metaKey) && (evt.which >= 65 && evt.which <= 90 && evt.shiftKey == false)) {
343
										unifiedCharCode += 32;
344
									}
345
									evt.key = String.fromCharCode(unifiedCharCode);
346
								}
347
							}
348
						}
349
					} else {
350
						if (dojo.render.html.ie) {
351
							if (!evt.ctrlKey && !evt.altKey && evt.keyCode >= evt.KEY_SPACE) {
352
								evt.key = String.fromCharCode(evt.keyCode);
353
							}
354
						} else {
355
							if (dojo.render.html.safari) {
356
								switch (evt.keyCode) {
357
								  case 25:
358
									evt.key = evt.KEY_TAB;
359
									evt.shift = true;
360
									break;
361
								  case 63232:
362
									evt.key = evt.KEY_UP_ARROW;
363
									break;
364
								  case 63233:
365
									evt.key = evt.KEY_DOWN_ARROW;
366
									break;
367
								  case 63234:
368
									evt.key = evt.KEY_LEFT_ARROW;
369
									break;
370
								  case 63235:
371
									evt.key = evt.KEY_RIGHT_ARROW;
372
									break;
373
								  case 63236:
374
									evt.key = evt.KEY_F1;
375
									break;
376
								  case 63237:
377
									evt.key = evt.KEY_F2;
378
									break;
379
								  case 63238:
380
									evt.key = evt.KEY_F3;
381
									break;
382
								  case 63239:
383
									evt.key = evt.KEY_F4;
384
									break;
385
								  case 63240:
386
									evt.key = evt.KEY_F5;
387
									break;
388
								  case 63241:
389
									evt.key = evt.KEY_F6;
390
									break;
391
								  case 63242:
392
									evt.key = evt.KEY_F7;
393
									break;
394
								  case 63243:
395
									evt.key = evt.KEY_F8;
396
									break;
397
								  case 63244:
398
									evt.key = evt.KEY_F9;
399
									break;
400
								  case 63245:
401
									evt.key = evt.KEY_F10;
402
									break;
403
								  case 63246:
404
									evt.key = evt.KEY_F11;
405
									break;
406
								  case 63247:
407
									evt.key = evt.KEY_F12;
408
									break;
409
								  case 63250:
410
									evt.key = evt.KEY_PAUSE;
411
									break;
412
								  case 63272:
413
									evt.key = evt.KEY_DELETE;
414
									break;
415
								  case 63273:
416
									evt.key = evt.KEY_HOME;
417
									break;
418
								  case 63275:
419
									evt.key = evt.KEY_END;
420
									break;
421
								  case 63276:
422
									evt.key = evt.KEY_PAGE_UP;
423
									break;
424
								  case 63277:
425
									evt.key = evt.KEY_PAGE_DOWN;
426
									break;
427
								  case 63302:
428
									evt.key = evt.KEY_INSERT;
429
									break;
430
								  case 63248:
431
								  case 63249:
432
								  case 63289:
433
									break;
434
								  default:
435
									evt.key = evt.charCode >= evt.KEY_SPACE ? String.fromCharCode(evt.charCode) : evt.keyCode;
436
								}
437
							} else {
438
								evt.key = evt.charCode > 0 ? String.fromCharCode(evt.charCode) : evt.keyCode;
439
							}
440
						}
441
					}
442
				}
443
			}
444
		}
445
		if (dojo.render.html.ie) {
446
			if (!evt.target) {
447
				evt.target = evt.srcElement;
448
			}
449
			if (!evt.currentTarget) {
450
				evt.currentTarget = (sender ? sender : evt.srcElement);
451
			}
452
			if (!evt.layerX) {
453
				evt.layerX = evt.offsetX;
454
			}
455
			if (!evt.layerY) {
456
				evt.layerY = evt.offsetY;
457
			}
458
			var doc = (evt.srcElement && evt.srcElement.ownerDocument) ? evt.srcElement.ownerDocument : document;
459
			var docBody = ((dojo.render.html.ie55) || (doc["compatMode"] == "BackCompat")) ? doc.body : doc.documentElement;
460
			if (!evt.pageX) {
461
				evt.pageX = evt.clientX + (docBody.scrollLeft || 0);
462
			}
463
			if (!evt.pageY) {
464
				evt.pageY = evt.clientY + (docBody.scrollTop || 0);
465
			}
466
			if (evt.type == "mouseover") {
467
				evt.relatedTarget = evt.fromElement;
468
			}
469
			if (evt.type == "mouseout") {
470
				evt.relatedTarget = evt.toElement;
471
			}
472
			this.currentEvent = evt;
473
			evt.callListener = this.callListener;
474
			evt.stopPropagation = this._stopPropagation;
475
			evt.preventDefault = this._preventDefault;
476
		}
477
		return evt;
478
	};
479
	this.stopEvent = function (evt) {
480
		if (window.event) {
481
			evt.cancelBubble = true;
482
			evt.returnValue = false;
483
		} else {
484
			evt.preventDefault();
485
			evt.stopPropagation();
486
		}
487
	};
488
};
489