From 05a84c6630c0abe2e4f8343fdf83d6a443ce2cba Mon Sep 17 00:00:00 2001 From: "T. Thiery" Date: Sat, 10 Oct 2015 23:38:05 +0200 Subject: [PATCH] Add removeHook method. - Removes a previously attached hook. - Must be the SAME function to unregister. --- code/hooks.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/code/hooks.js b/code/hooks.js index 9cdd428d..44c6826c 100644 --- a/code/hooks.js +++ b/code/hooks.js @@ -104,3 +104,12 @@ window.addHook = function(event, callback) { else _hooks[event].push(callback); } + +// callback must the SAME function to be unregistered. +window.removeHook = function(event, callback) { + if (typeof callback !== 'function') throw('Callback must be a function.'); + + if (_hooks[event]) { + _hooks[event].splice(_hooks[event].indexOf(callback), 1); + } +}