Skip to content
Permalink
Browse files

js: hndler register helper now support other objects than window

  • Loading branch information
LarsMichelsen committed Apr 14, 2015
1 parent a5fb5c8 commit 0afc4f103b55e1bfb89f46609bc51c8dc9e2e687
Showing with 16 additions and 12 deletions.
  1. +16 −12 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;
}
}

0 comments on commit 0afc4f1

Please sign in to comment.
You can’t perform that action at this time.