diff mgallery.js @ 154:0b87e7c1675c

Improve the JavaScript event hook functions.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 07 Nov 2017 14:40:14 +0200
parents 606b05c31d5e
children ba02d12cb4be
line wrap: on
line diff
--- a/mgallery.js	Wed Sep 06 18:21:17 2017 +0300
+++ b/mgallery.js	Tue Nov 07 14:40:14 2017 +0200
@@ -6,19 +6,28 @@
 //
 
 
-function mgalAddEvent(evobj, evtype, evcallback)
+function mgalAddEventOb(obname, evobj, evtype, evcallback)
 {
   if (evobj == null || typeof(evobj) == 'undefined')
+  {
+    console.log("Event object '"+ obname +"' == null.");
     return;
+  }
 
   if (evobj.addEventListener)
     evobj.addEventListener(evtype, evcallback, false);
   else
   if (evobj.attachEvent)
-    evobj.attachEvent("on" + evtype, evcallback);
+    evobj.attachEvent("on"+evtype, evcallback);
   else
     evobj["on"+evtype] = evcallback;
-};
+}
+
+
+function mgalAddEvent(obname, evtype, evcallback)
+{
+  mgalAddEventOb(obname, document.getElementById(obname), evtype, evcallback);
+}
 
 
 function mgalNavigateTo(url)