diff options
Diffstat (limited to 'itjs')
-rw-r--r-- | itjs/it.js | 65 |
1 files changed, 65 insertions, 0 deletions
@@ -103,6 +103,71 @@ function it_event(p) p.element["on" + p.event].oldhandler = oldhandler; } +function it_add_event(p) +{ + if (!p.object || !p.method) // not enough arguments + return; + if (!p.element) + p.element = document; + + if (!p.object._it_events) + p.object._it_events = []; + + var evt = p.event; + var key = p.event + '*' + p.method; + var p_closure = p; // Needed for Konqueror 3.4.2 as p is (wrongly) shadowed by global input element named p + if (!p.object._it_events[key]) + p.object._it_events[key] = function(e){ return p_closure.object[p_closure.method](e, p_closure); }; + + if (p.element.addEventListener) + p.element.addEventListener(evt, p.object._it_events[key], false); + else if (p.element.attachEvent) + p.element.attachEvent('on'+evt, p.object._it_events[key]); + else + { + p.element['on'+evt] = function(e) + { + var ret = true; + for (var k in p_closure.object._it_events) + if (p_closure.object._it_events[k] && k.indexOf(evt) == 0) + ret = p_closure.object._it_events[k](e); + return ret; + }; + } +} + +function it_remove_event(p) +{ + if (!p.element) + p.element = document; + + var key = p.event + '*' + p.method; + if (p.object && p.object._it_events && p.object._it_events[key]) { + if (p.element.removeEventListener) + p.element.removeEventListener(p.event, p.object._it_events[key], false); + else if (p.element.detachEvent) + p.element.detachEvent('on'+p.event, p.object._it_events[key]); + + p.object._it_events[key] = null; + } +} + +/** + * Prevent event propagation and bubbeling + */ +function it_event_void(evt) +{ + var e = evt ? evt : window.event; + if (e.preventDefault) + e.preventDefault(); + if (e.stopPropagation) + e.stopPropagation(); + + e.cancelBubble = true; + e.returnValue = false; + return false; +} + /* Get object pixel position. Based on quirksmode.org's code */ function it_get_obj_x(obj) { |