[ Index ] |
|
Code source de Horde 3.1.3 |
1 /** 2 * Generic function to add an event handler to any DOM element. 3 * 4 * $Horde: horde/js/addEvent.php,v 1.1.2.2 2006/01/01 21:29:02 jan Exp $ 5 * 6 * Copyright 2005-2006 Chuck Hagenbuch <chuck@horde.org> 7 * 8 * See the enclosed file COPYING for license information (LGPL). If you 9 * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. 10 */ 11 12 /** 13 * Adds the given event to an element. If the element already has 14 * handlers for the event, the new event is appended. 15 * 16 * @param object element The element to add the event to. 17 * @param string event The name of the event. 18 * @param string|function function The javascript to execute. 19 */ 20 function addEvent(element, event, code) 21 { 22 if (!element) { 23 return false; 24 } 25 26 // Assign new anonymous function if we're passed a js string 27 // instead of a function reference. 28 if (typeof code == 'string') { 29 code = new Function(code); 30 } 31 32 if (element.addEventListener) { 33 element.addEventListener(event.replace(/on/, ''), code, false); 34 } else if (element.attachEvent) { 35 element.attachEvent(event, code); 36 } else if (element.onload != null) { 37 eval('var OldEvent = element.' + event); 38 newCode = Function(e) 39 { 40 oldEvent(e); 41 code(); 42 }; 43 eval('element.' + event + ' = newCode'); 44 } else { 45 eval('element.' + event + ' = code'); 46 } 47 48 return true; 49 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 18:01:28 2007 | par Balluche grâce à PHPXref 0.7 |