home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 2002 April
/
PCWorld_2002-04_cd.bin
/
Software
/
Komercni
/
abra
/
html
/
sluzby
/
sluzby_cbe_event.js
< prev
next >
Wrap
Text File
|
2001-11-09
|
11KB
|
325 lines
/*******
cbe_event.js
CrossBrowserElement v3b15 (Events)
Cross-Browser DHTML for IE 4+, NN 4+, Gecko, and Opera 4+
Download the latest version at cross-browser.com
Copyright (c) 2001 Michael Foster (mfoster@cybrtyme.com)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details, at www.gnu.org.
A copy of the GNU LGPL has been included with this distribution.
*******/
var cbeEventJsLoaded = true;
function CrossBrowserEvent()
{
////// Methods
this.init = cbeInitEvent;
this.stopPropagation = cbeStopPropagation;
this.preventDefault = cbePreventDefault;
////// Properties
//// from DOM2 Interface Event
this.type = "";
this.target = null;
this.currentTarget = null;
this.eventPhase = 0;
this.bubbles = true;
this.cancelable = true;
this.timeStamp = 0;
// eventPhase masks
this.AT_TARGET = 1;
this.BUBBLING_PHASE = 2;
this.CAPTURING_PHASE = 3;
//// from DOM2 Interface MouseEvent : UIEvent
this.screenX = 0;
this.screenY = 0;
this.clientX = 0;
this.clientY = 0;
this.ctrlKey = false;
this.shiftKey = false;
this.altKey = false;
this.metaKey = false;
this.button = 0;
this.relatedTarget = null;
// button masks
this.LEFT = 0;
this.MIDDLE = 1;
this.RIGHT = 2;
////// from IE4+ Object Model
this.keyCode = 0;
this.offsetX = 0;
this.offsetY = 0;
////// from NN4.xx Object Model
this.pageX = 0;
this.pageY = 0; // pageX and pageY added in v3b15
}
function cbeStopPropagation()
{
// stub
return;
}
function cbePreventDefault()
{
// stub
return;
}
function cbeInitEvent(e)
{
if (is.ie) {
// from DOM2 Interface Event
cbeEvent.type = window.event.type;
cbeEvent.target = window.event.srcElement;
cbeEvent.currentTarget = window.event.toElement; //?
// cbeEvent.eventPhase = 0;
cbeEvent.bubbles = window.event.cancelBubble;
// cbeEvent.cancelable = false;
// cbeEvent.timeStamp = 0;
// from DOM2 Interface MouseEvent : UIEvent
cbeEvent.screenX = window.event.screenX;
cbeEvent.screenY = window.event.screenY;
cbeEvent.clientX = window.event.clientX;
cbeEvent.clientY = window.event.clientY;
cbeEvent.ctrlKey = window.event.ctrlKey;
cbeEvent.shiftKey = window.event.shiftKey;
cbeEvent.altKey = window.event.altKey;
// cbeEvent.metaKey = 0;
if (window.event.button == 1)
cbeEvent.button = cbeEvent.LEFT;
else if (window.event.button == 4)
cbeEvent.button = cbeEvent.MIDDLE;
else if (window.event.button == 2)
cbeEvent.button = cbeEvent.RIGHT;
cbeEvent.relatedTarget = window.event.fromElement; //?
// from IE4+ Object Model
cbeEvent.keyCode = window.event.keyCode;
cbeEvent.offsetX = window.event.offsetX;
cbeEvent.offsetY = window.event.offsetY;
// from NN4.xx Object Model
cbeEvent.pageX = cbeEvent.clientX + document.body.cbe.scrollLeft();
cbeEvent.pageY = cbeEvent.clientY + document.body.cbe.scrollTop();
}
else if (is.gecko) {
// from DOM2 Interface Event
cbeEvent.type = e.type;
cbeEvent.target = e.target;
cbeEvent.currentTarget = e.currentTarget;
cbeEvent.eventPhase = e.eventPhase;
cbeEvent.bubbles = e.bubbles;
cbeEvent.cancelable = e.cancelable;
cbeEvent.timeStamp = e.timeStamp;
// from DOM2 Interface MouseEvent : UIEvent
cbeEvent.screenX = e.screenX;
cbeEvent.screenY = e.screenY;
cbeEvent.clientX = e.clientX;
cbeEvent.clientY = e.clientY;
cbeEvent.ctrlKey = e.ctrlKey;
cbeEvent.shiftKey = e.shiftKey;
cbeEvent.altKey = e.altKey;
cbeEvent.metaKey = e.metaKey;
if (e.button == 1)
cbeEvent.button = cbeEvent.LEFT;
else if (e.button == 2)
cbeEvent.button = cbeEvent.MIDDLE;
else if (e.button == 3)
cbeEvent.button = cbeEvent.RIGHT;
cbeEvent.relatedTarget = e.relatedTarget;
// from IE4+ Object Model
cbeEvent.keyCode = e.which;
cbeEvent.offsetX = e.layerX;
cbeEvent.offsetY = e.layerY;
// from NN4.xx Object Model
cbeEvent.pageX = cbeEvent.clientX + document.body.cbe.scrollLeft();
cbeEvent.pageY = cbeEvent.clientY + document.body.cbe.scrollTop();
}
else if (is.nav) {
// from DOM2 Interface Event
cbeEvent.type = e.type;
cbeEvent.target = e.target;
// cbeEvent.currentTarget = e.currentTarget;
// cbeEvent.eventPhase = e.eventPhase;
// cbeEvent.bubbles = e.bubbles;
// cbeEvent.cancelable = e.cancelable;
// cbeEvent.timeStamp = 0;
// from DOM2 Interface MouseEvent : UIEvent
cbeEvent.screenX = e.screenX;
cbeEvent.screenY = e.screenY;
cbeEvent.clientX = e.pageX - document.body.cbe.scrollLeft();
cbeEvent.clientY = e.pageY - document.body.cbe.scrollTop();
cbeEvent.ctrlKey = (e.modifiers & Event.CONTROL_MASK) != 0;
cbeEvent.shiftKey = (e.modifiers & Event.SHIFT_MASK) != 0;
cbeEvent.altKey = (e.modifiers & Event.ALT_MASK) != 0;
// cbeEvent.metaKey = e.metaKey;
if (e.which == 1)
cbeEvent.button = cbeEvent.LEFT;
else if (e.which == 2)
cbeEvent.button = cbeEvent.MIDDLE;
else if (e.which == 3)
cbeEvent.button = cbeEvent.RIGHT;
// cbeEvent.relatedTarget = e.relatedTarget;
// from IE4+ Object Model
cbeEvent.keyCode = e.which;
cbeEvent.offsetX = e.layerX;
cbeEvent.offsetY = e.layerY;
// from NN4.xx Object Model
cbeEvent.pageX = e.pageX;
cbeEvent.pageY = e.pageY;
}
else if (is.opera) {
// from DOM2 Interface Event
cbeEvent.type = e.type;
cbeEvent.target = e.target;
cbeEvent.currentTarget = e.currentTarget;
// cbeEvent.eventPhase = e.eventPhase;
// cbeEvent.bubbles = e.bubbles;
// cbeEvent.cancelable = e.cancelable;
// cbeEvent.timeStamp = 0;
// from DOM2 Interface MouseEvent : UIEvent
cbeEvent.screenX = e.screenX;
cbeEvent.screenY = e.screenY;
cbeEvent.clientX = e.clientX - document.body.cbe.scrollLeft();
cbeEvent.clientY = e.clientY - document.body.cbe.scrollTop();
cbeEvent.ctrlKey = e.type=='mousemove' ? e.shiftKey : e.ctrlKey;
cbeEvent.shiftKey = e.type=='mousemove' ? e.ctrlKey : e.shiftKey;
cbeEvent.altKey = e.altKey;
// cbeEvent.metaKey = e.metaKey;
if ((e.type == 'click' && e.which == 0) || ((e.type == 'mousedown' || e.type == 'mouseup') && e.which == 1))
cbeEvent.button = cbeEvent.LEFT;
// cbeEvent.relatedTarget = e.relatedTarget; // this was crashing Opera, commented out in v3b12
// from IE4+ Object Model
cbeEvent.keyCode = e.which;
// cbeEvent.offsetX = e.offsetX;
// cbeEvent.offsetY = e.offsetY;
// from NN4.xx Object Model
cbeEvent.pageX = e.clientX;
cbeEvent.pageY = e.clientY;
}
}
function _cbeAddEventListener(type, listener, capture) // cbe method
{
cbeAddEventListener(this.ele, type, listener, capture);
}
function cbeWindowAddEventListener(type, listener, capture) // window method
{
cbeAddEventListener(window, type, listener, capture);
}
function cbeDocumentAddEventListener(type, listener, capture) // document method
{
cbeAddEventListener(document, type, listener, capture);
}
function cbeAddEventListener(obj, type, listener, capture) // global
{
var eh = "obj.on" + type.toLowerCase() + "=" + listener;
var uType = type.toUpperCase();
if (!capture) capture = false;
if (is.nav4 || is.opera) {
if (uType == 'SCROLL') {
window.cbeOldScrollTop = cbePageYOffset();
window.cbeOnScrollListener = listener;
cbeOnScrollEvent();
return;
}
else if (uType == 'RESIZE') {
window.cbeOldWidth = cbeInnerWidth();
window.cbeOldHeight = cbeInnerHeight();
window.cbeOnResizeListener = listener;
cbeOnResizeEvent();
return;
}
}
if (is.dom2events) {
obj.addEventListener(type, listener, capture);
}
else if (obj.captureEvents) {
if (capture) obj.captureEvents(eval("Event." + uType));
eval(eh);
}
else {
eval(eh);
}
}
function _cbeRemoveEventListener(type, listener, capture) // cbe method
{
cbeRemoveEventListener(this.ele, type, listener, capture);
}
function cbeWindowRemoveEventListener(type, listener, capture) // window method
{
cbeRemoveEventListener(window, type, listener, capture);
}
function cbeDocumentRemoveEventListener(type, listener, capture) // document method
{
cbeRemoveEventListener(document, type, listener, capture);
}
function cbeRemoveEventListener(obj, type, listener, capture) // global
{
var eh = "obj.on" + type.toLowerCase() + "=null";
var uType = type.toUpperCase();
if (!capture) capture = false;
if (is.nav || is.opera) {
if (uType == 'SCROLL') {
window.cbeOnScrollListener = null;
return;
}
else if (uType == 'RESIZE') {
window.cbeOnResizeListener = null;
return;
}
}
if (is.dom2events) {
obj.removeEventListener(type, listener, capture);
}
else if (obj.releaseEvents) {
if (capture) obj.releaseEvents(eval("Event." + uType));
eval(eh);
}
else {
eval(eh);
}
}
function cbeOnScrollEvent()
{
if (!window.cbeOnScrollListener) {
return;
}
if (cbePageYOffset() != window.cbeOldScrollTop) {
window.cbeOnScrollListener();
window.cbeOldScrollTop = cbePageYOffset();
}
setTimeout("cbeOnScrollEvent()", 250);
}
function cbeOnResizeEvent()
{
if (!window.cbeOnResizeListener) {
return;
}
if (cbeInnerWidth() != window.cbeOldWidth || cbeInnerHeight() != window.cbeOldHeight) {
window.cbeOnResizeListener();
window.cbeOldWidth = cbeInnerWidth();
window.cbeOldHeight = cbeInnerHeight();
}
setTimeout("cbeOnResizeEvent()", 250);
}
function cbeDefaultOnResizeListener()
{
if (is.opera) location.replace(location.href);
else history.go(0);
}
// End cbe_event.js