From ffc13b73fc8aeb33209bfb189fc5b68ba6dec875 Mon Sep 17 00:00:00 2001 From: Rob Church Date: Sun, 29 Jul 2007 19:53:50 +0000 Subject: [PATCH] Refactor addClickHandler() and introduce addHandler() --- skins/common/wikibits.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/skins/common/wikibits.js b/skins/common/wikibits.js index fd2d212cfc..1e37e3c2fb 100644 --- a/skins/common/wikibits.js +++ b/skins/common/wikibits.js @@ -1303,19 +1303,29 @@ function runOnloadHook() { } /** - * Add a click event handler to an element + * Add an event handler to an element * * @param Element element Element to add handler to + * @param String attach Event to attach to * @param callable handler Event handler callback */ -function addClickHandler( element, handler ) { +function addHandler( element, attach, handler ) { if( window.addEventListener ) { - element.addEventListener( 'click', handler, false ); + element.addEventListener( attach, handler, false ); } else if( window.attachEvent ) { - element.attachEvent( 'onclick', handler ); + element.attachEvent( 'on' + attach, handler ); } } +/** + * Add a click event handler to an element + * + * @param Element element Element to add handler to + * @param callable handler Event handler callback + */ +function addClickHandler( element, handler ) { + addHandler( element, 'click', handler ); +} //note: all skins should call runOnloadHook() at the end of html output, // so the below should be redundant. It's there just in case. hookEvent("load", runOnloadHook); -- 2.20.1