Download the X Distribution File.
new xEvent(oEvent)
// xEvent r11, Copyright 2001-2007 Michael Foster (Cross-Browser.com) // Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL function xEvent(evt) // object prototype { var e = evt || window.event; if (!e) return; this.type = e.type; this.target = e.target || e.srcElement; this.relatedTarget = e.relatedTarget; /*@cc_on if (e.type == 'mouseover') this.relatedTarget = e.fromElement; else if (e.type == 'mouseout') this.relatedTarget = e.toElement; @*/ if (xDef(e.pageX)) { this.pageX = e.pageX; this.pageY = e.pageY; } else if (xDef(e.clientX)) { this.pageX = e.clientX + xScrollLeft(); this.pageY = e.clientY + xScrollTop(); } if (xDef(e.offsetX)) { this.offsetX = e.offsetX; this.offsetY = e.offsetY; } else if (xDef(e.layerX)) { this.offsetX = e.layerX; this.offsetY = e.layerY; } else { this.offsetX = this.pageX - xPageX(this.target); this.offsetY = this.pageY - xPageY(this.target); } this.keyCode = e.keyCode || e.which || 0; this.shiftKey = e.shiftKey; this.ctrlKey = e.ctrlKey; this.altKey = e.altKey; if (typeof e.type == 'string') { if (e.type.indexOf('click') != -1) {this.button = 0;} else if (e.type.indexOf('mouse') != -1) { this.button = e.button; /*@cc_on if (e.button & 1) this.button = 0; else if (e.button & 4) this.button = 1; else if (e.button & 2) this.button = 2; @*/ } } }
property_viewer.html - A good example of usage as well as a good page for testing xEvent.
toys - xEvent is used in many of the demos.
23May07viewtopic.php?id=22: Forum discussion on "xEvent.button".
function xEvent(evt) // object prototype { var e = evt || window.event; if(!e) return; if(e.type) this.type = e.type; if(e.target) this.target = e.target; else if(e.srcElement) this.target = e.srcElement; if (e.relatedTarget) this.relatedTarget = e.relatedTarget; else if (e.type == 'mouseover' && e.fromElement) this.relatedTarget = e.fromElement; else if (e.type == 'mouseout') this.relatedTarget = e.toElement; if(xDef(e.pageX,e.pageY)) { this.pageX = e.pageX; this.pageY = e.pageY; } else if(xDef(e.clientX,e.clientY)) { this.pageX = e.clientX + xScrollLeft(); this.pageY = e.clientY + xScrollTop(); } if (xDef(e.offsetX,e.offsetY)) { this.offsetX = e.offsetX; this.offsetY = e.offsetY; } else if (xDef(e.layerX,e.layerY)) { this.offsetX = e.layerX; this.offsetY = e.layerY; } else { this.offsetX = this.pageX - xPageX(this.target); this.offsetY = this.pageY - xPageY(this.target); } this.keyCode = e.keyCode || e.which || 0; this.shiftKey = e.shiftKey; this.ctrlKey = e.ctrlKey; this.altKey = e.altKey; // rev8 this.button = null; // 0=left, 1=middle, 2=right, null=none-mouse event if (e.type.indexOf('click') != -1) this.button = 0; else if (e.type.indexOf('mouse') != -1) { var ie = 0, v = navigator.vendor; /*@cc_on ie = 1; @*/ if (ie || (v && v.indexOf('Apple') != -1)) { // IE or Safari if (e.button & 1) this.button = 0; else if (e.button & 2) this.button = 2; else if (e.button & 4) this.button = 1; } else this.button = e.button; } }
By your use of X and/or CBE and/or any Javascript from this site you consent to the GNU LGPL - please read it. If you have any questions about the license, read the FAQ and/or come to the forums.
Forum support is available at the X Library Support Forums.
Cross-Browser.com is the home of X - a cross-browser Javascript library, and many demos, applications, articles and documentation.
If you are using X, XC or anything from this site, show off your work by posting a link in the X Showcase forum.