Module: check_mk
Branch: master
Commit: 0afc4f103b55e1bfb89f46609bc51c8dc9e2e687
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=0afc4f103b55e1…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Tue Apr 14 08:46:38 2015 +0200
js: hndler register helper now support other objects than window
---
web/htdocs/js/checkmk.js | 28 ++++++++++++++++------------
1 file changed, 16 insertions(+), 12 deletions(-)
diff --git a/web/htdocs/js/checkmk.js b/web/htdocs/js/checkmk.js
index f074eef..6e7a09c 100644
--- a/web/htdocs/js/checkmk.js
+++ b/web/htdocs/js/checkmk.js
@@ -155,31 +155,35 @@ function getButton(event) {
}
// Adds document/window global event handlers
-function add_event_handler(type, func) {
- if (window.addEventListener) {
+function add_event_handler(type, func, obj) {
+ var obj = (typeof(obj) === 'undefined') ? window : obj;
+
+ if (obj.addEventListener) {
// W3 standard browsers
- window.addEventListener(type, func, false);
+ obj.addEventListener(type, func, false);
}
- else if (window.attachEvent) {
+ else if (obj.attachEvent) {
// IE<9
- document.documentElement.attachEvent("on" + type, func);
+ obj.attachEvent("on" + type, func);
}
else {
- window["on" + type] = func;
+ obj["on" + type] = func;
}
}
-function del_event_handler(type, func) {
- if (window.removeEventListener) {
+function del_event_handler(type, func, obj) {
+ var obj = (typeof(obj) === 'undefined') ? window : obj;
+
+ if (obj.removeEventListener) {
// W3 stadnard browsers
- window.removeEventListener(type, func, false);
+ obj.removeEventListener(type, func, false);
}
- else if (window.detachEvent) {
+ else if (obj.detachEvent) {
// IE<9
- document.documentElement.detachEvent("on"+type, func);
+ obj.detachEvent("on"+type, func);
}
else {
- window["on" + type] = null;
+ obj["on" + type] = null;
}
}