root/colbrowser/mouseevent.js
| Revision 22, 1.6 kB (checked in by brettz9, 2 years ago) |
|---|
| Line | |
|---|---|
| 1 | // This code is from the book JavaScript: The Definitive Guide, 5th Edition, |
| 2 | // by David Flanagan. Copyright 2006 O'Reilly Media, Inc. (ISBN #0596101996) |
| 3 | // but it has been altered without comment (to be used for a mouse event) by Brett Zamir |
| 4 | |
| 5 | var MouseEvent = {}; |
| 6 | |
| 7 | MouseEvent.send = function(target) { |
| 8 | if (typeof target == "string") { |
| 9 | target = document.getElementById(target); |
| 10 | } |
| 11 | |
| 12 | // Create an event object. If we can't create one, return silently |
| 13 | var e; |
| 14 | if (document.createEvent) { // DOM event model |
| 15 | // Create the event, specifying the name of the event module. |
| 16 | // For a mouse event, we'd use "MouseEvents". |
| 17 | e = document.createEvent("MouseEvents"); |
| 18 | // Initialize the event object, using a module-specific init method. |
| 19 | // Here we specify the event type, bubbling, and noncancelable. |
| 20 | // See Event.initEvent, MouseEvent.initMouseEvent, and UIEvent.initUIEvent |
| 21 | // Brett: needed to change 2nd argument to false since was getting triggered unintentionally |
| 22 | e.initMouseEvent("click", false, false, null, null, null, null, null, null, null, null, null, null, null, null); |
| 23 | } |
| 24 | else if (document.createEventObject) { // IE event model |
| 25 | // In the IE event model, we just call this simple method |
| 26 | e = document.createEventObject( ); |
| 27 | } |
| 28 | else { |
| 29 | return; // Do nothing in other browsers |
| 30 | } |
| 31 | |
| 32 | // Dispatch the event to the specified target. |
| 33 | if (target.dispatchEvent) { |
| 34 | target.dispatchEvent(e); // DOM |
| 35 | } |
| 36 | else if (target.fireEvent) { |
| 37 | target.fireEvent("onclick", e); // IE |
| 38 | } |
| 39 | }; |
Note: See TracBrowser for help on using the browser.