//====== //====== // // Template- EVENT_JS.IHT by T.Hughes 31-JUL-2006 / 6-MAR-07 // // Purpose- // // Generic event handling routines. // // Examples- // // // Define the handler. // function form_submit_handler() { // // do something on form submit // } // // Define a function to attach the handler to all associated // // form elements. // function attach_form_submit_handler(form_submit_handler) { // Dym.attach_element_event("form","submit",form_submit_handler); // } // // Setup the function to be called when the page loads. // Dym.attachOnloadEvent(attach_form_submit_handler); // // Modifications- // // 10-AUG-06 TH / BH / TH 12=18564 // - Created. // // 6-MAR-07 TH / BH / TH 17= // - Add documentation on demonstrating problem with catching // the return value of handlers added via addEventListener // or AttachEvent in Firefox. // // 6-MAR-07 TH / BH / TH 17= // - Allow functions to be accessed via the dymaxion namespace // rather than using the "dy_" prefix. Use standard // camelcase for new namespace protected names. // // 04-Jul-07 BG / BG / BG 12=18420 // - Converted to from .iht to .js. // //====== //====== /* Purpose: Attach an event to a given document element. Inputs: elem - The element object eventName - event name without "on", eg "load", "click" eventHandler - Name of function to call on event. Notes: - Supported on staff web minimum versions, except IE5 on the Mac (which is a discontinued product). Fails silently where not supported. - The return value of this event is currently ignored on some browsers (eg: Firefox/Opera). Attach events directly using assignment if the return value is desired (for example, when returning false to prevent a form submission). - To test see xrc_event_js.iht. - The production version uses Dym.attachOnloadEvent to call attach_alertMe_direct, which attaches an onsubmit handler via direct assignment. This correctly short circuits the submit. - If you comment this out and uncomment the call to Dym.attachOnloadEvent that calls attach_alertMe, the submit will not be short circiuted in Firefox (verified at version 1.5). Example: Dym.attachEvent(window,"load",onLoadEventHandler); */ function dy_attach_event(elem, eventName, eventHandler) { // W3C DOM2 if (elem.addEventListener) { elem.addEventListener(eventName,eventHandler,false); // Internet Explorer } else if (elem.attachEvent) { elem.attachEvent("on"+eventName,eventHandler); } } Dym.attachEvent = dy_attach_event; /* Purpose: Attach an event event to every element of the specified type on the page. */ function dy_attach_element_event(elemName, eventName, eventHandler) { if (document.getElementsByTagName) { allElem = document.getElementsByTagName(elemName); if (allElem) { for (var i=0; i