1 rizwank 1.1 /* Copyright (c) 2005 Tim Taylor Consulting (see LICENSE.txt) */
2
3 ToolMan._eventsFactory = {
4 fix : function(event) {
5 if (!event) event = window.event
6
7 if (event.target) {
8 if (event.target.nodeType == 3) event.target = event.target.parentNode
9 } else if (event.srcElement) {
10 event.target = event.srcElement
11 }
12
13 return event
14 },
15
16 register : function(element, type, func) {
17 if (element.addEventListener) {
18 element.addEventListener(type, func, false)
19 } else if (element.attachEvent) {
20 if (!element._listeners) element._listeners = new Array()
21 if (!element._listeners[type]) element._listeners[type] = new Array()
22 rizwank 1.1 var workaroundFunc = function() {
23 func.apply(element, new Array())
24 }
25 element._listeners[type][func] = workaroundFunc
26 element.attachEvent('on' + type, workaroundFunc)
27 }
28 },
29
30 unregister : function(element, type, func) {
31 if (element.removeEventListener) {
32 element.removeEventListener(type, func, false)
33 } else if (element.detachEvent) {
34 if (element._listeners
35 && element._listeners[type]
36 && element._listeners[type][func]) {
37
38 element.detachEvent('on' + type,
39 element._listeners[type][func])
40 }
41 }
42 }
43 rizwank 1.1 }
|