[ Index ] |
|
Code source de PRADO 3.0.6 |
1 /** 2 * @class Event extensions. 3 */ 4 Object.extend(Event, 5 { 6 /** 7 * Register a function to be executed when the page is loaded. 8 * Note that the page is only loaded if all resources (e.g. images) 9 * are loaded. 10 * 11 * Example: Show an alert box with message "Page Loaded!" when the 12 * page finished loading. 13 * <code> 14 * Event.OnLoad(function(){ alert("Page Loaded!"); }); 15 * </code> 16 * 17 * @param {Function} function to execute when page is loaded. 18 */ 19 OnLoad : function (fn) 20 { 21 // opera onload is in document, not window 22 var w = document.addEventListener && 23 !window.addEventListener ? document : window; 24 Event.observe(w,'load',fn); 25 }, 26 27 /** 28 * @param {Event} a keyboard event 29 * @return {Number} the Unicode character code generated by the key 30 * that was struck. 31 */ 32 keyCode : function(e) 33 { 34 return e.keyCode != null ? e.keyCode : e.charCode 35 }, 36 37 /** 38 * @param {String} event type or event name. 39 * @return {Boolean} true if event type is of HTMLEvent, false 40 * otherwise 41 */ 42 isHTMLEvent : function(type) 43 { 44 var events = ['abort', 'blur', 'change', 'error', 'focus', 45 'load', 'reset', 'resize', 'scroll', 'select', 46 'submit', 'unload']; 47 return events.include(type); 48 }, 49 50 /** 51 * @param {String} event type or event name 52 * @return {Boolean} true if event type is of MouseEvent, 53 * false otherwise 54 */ 55 isMouseEvent : function(type) 56 { 57 var events = ['click', 'mousedown', 'mousemove', 'mouseout', 58 'mouseover', 'mouseup']; 59 return events.include(type); 60 }, 61 62 /** 63 * Dispatch the DOM event of a given <tt>type</tt> on a DOM 64 * <tt>element</tt>. Only HTMLEvent and MouseEvent can be 65 * dispatched, keyboard events or UIEvent can not be dispatch 66 * via javascript consistently. 67 * For the "submit" event the submit() method is called. 68 * @param {Object} element id string or a DOM element. 69 * @param {String} event type to dispatch. 70 */ 71 fireEvent : function(element,type) 72 { 73 element = $(element); 74 if(type == "submit") 75 return element.submit(); 76 if(document.createEvent) 77 { 78 if(Event.isHTMLEvent(type)) 79 { 80 var event = document.createEvent('HTMLEvents'); 81 event.initEvent(type, true, true); 82 } 83 else if(Event.isMouseEvent(type)) 84 { 85 var event = document.createEvent('MouseEvents'); 86 if (event.initMouseEvent) 87 { 88 event.initMouseEvent(type,true,true, 89 document.defaultView, 1, 0, 0, 0, 0, false, 90 false, false, false, 0, null); 91 } 92 else 93 { 94 // Safari 95 // TODO we should be initialising other mouse-event related attributes here 96 event.initEvent(type, true, true); 97 } 98 } 99 element.dispatchEvent(event); 100 } 101 else if(document.createEventObject) 102 { 103 var evObj = document.createEventObject(); 104 element.fireEvent('on'+type, evObj); 105 } 106 else if(typeof(element['on'+type]) == "function") 107 element['on'+type](); 108 } 109 });
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 21:07:04 2007 | par Balluche grâce à PHPXref 0.7 |