|
From: labCoat <la...@xe...> - 2001-01-23 08:12:38
|
Hello all!
I recently revised the latest (CVS) version of events.js, and have events working properly in IE5, IE55, NS4, and NS6 (I don't have IE4, but I am almost positive that it will work in it).
It would be great if anyone would like to plug this into their version of the API and take it for a test drive! (Also, I would appriciate any feedback!)
Now, I made A LOT of modifications/optimizations, and I haven't commented everything, so please don't get angry for the lack of comments... ;-)
Here goes...
<!--//
/*
DynAPI Distribution
Event Classes
Modified: 2001.01.23
The DynAPI Distribution is distributed under the terms of the GNU LGPL license.
*/
/*----------------------------------------------------------------------
-- CLASS: DynEvent
-- ARGUMENTS: type,src,target
-- METHODS: getType(), getSource(), getTarget()
----------------------------------------------------------------------*/
DynEvent=function(type,src,target) {
this.type=type;
this.src=src;
this.target=target;
};
DynEvent.prototype.getType=function() {
return this.type;
};
DynEvent.prototype.getSource=function() {
return this.src;
};
DynEvent.prototype.getTarget=function() {
return this.target;
};
/*----------------------------------------------------------------------
-- CLASS: EventListener
-- ARGUMENTS: target
-- METHODS: handleEvent()
----------------------------------------------------------------------*/
EventListener=function(target) {
this.target=target;
}
EventListener.prototype.handleEvent=function(type,e) {
if ((e.button==2 || e.button==3) && (type=='mousedown' || type=='mouseup' || type=='click' || type=='dblclick')) {
if (e.button==2) type='md'+type;
if (e.button==3) type='rt'+type;
e.type=type; //ADDED:proteanman
}
if (this["on"+type]) {
if (is.ns5) {
var mse=(type.match(/mouse/) || type.match(/click/));
if (!mse || (!isNaN(e.eventPhase) && ((e.src.isDynLayer && (e.eventPhase==1 || e.eventPhase==2)) || (e.src.isDynDocument && e.eventPhase==3)))) this["on"+type](e);
} else this["on"+type](e);
}
};
/*----------------------------------------------------------------------
-- CLASS: MouseEvent
-- ARGUMENTS: none
-- METHODS: getType(), getSource(), getTarget(), setEvent(),
bubbleEvent(), getX(), getY(), getPageX(), getPageY(),
setBubble(), cancelBrowserEvent()
----------------------------------------------------------------------*/
MouseEvent=function() {};
MouseEvent.prototype.getType=function() {
return this.type;
};
MouseEvent.prototype.getSource=function() {
return this.src;
};
MouseEvent.prototype.getTarget=function() {
return this.target;
};
MouseEvent.prototype.setEvent=function(src,e) {
this.orig=e;
this.browserReturn=true;
this.bubble=true;
this.src=src;
this.type=e.type;
if (is.ie) {
//Set event's mouse's x/y & pageX/pageY coords
this.pageX=e.x+document.body.scrollLeft;
this.pageY=e.y+document.body.scrollTop;
this.x=e.offsetX;
this.y=e.offsetY;
//Set event mouse button
var b=e.button;
if (b==2) b=3;
else if (b==4) b=2;
this.button=b;
//Set mouse event's modifiers
this.altKey=(e.altKey || e.altLeft);
this.ctrlKey=(e.ctrlKey || e.ctrlLeft);
this.shiftKey=(e.shiftKey || e.shiftLeft);
} else {
//ADDED: proteanman -- adds events eventphase property for ns5
if (is.ns5) this.eventPhase=e.eventPhase;
//Set event's mouse's x/y & pageX/pageY coords
this.pageX=e.pageX-window.pageXOffset;
this.pageY=e.pageY-window.pageYOffset;
this.x=e.layerX;
this.y=e.layerY;
//Set event mouse button
this.button=e.which;
//Set mouse event's modifiers
var m=e.modifiers;
this.altKey=(m==1 || m==3 || m==5 || m==7);
this.ctrlKey=(m==2 || m==3 || m==6 || m==7);
this.shiftKey=(m==4 || m==5 || m==6 || m==7);
}
};
MouseEvent.prototype.bubbleEvent=function() {
if (!this.bubble || this.src.isDynDocument || this.src.parent==null) return;
this.x+=this.src.x;
this.y+=this.src.y;
this.src=this.src.parent;
this.src.invokeEvent(this.type,this);
this.bubbleEvent();
return;
};
MouseEvent.prototype.getX=function() {
return this.x;
};
MouseEvent.prototype.getY=function() {
return this.y;
};
MouseEvent.prototype.getPageX=function() {
return this.pageX;
};
MouseEvent.prototype.getPageY=function() {
return this.pageY;
};
MouseEvent.prototype.setBubble=function(b) {
this.bubble=b;
};
MouseEvent.prototype.cancelBrowserEvent=function(b) {
this.browserReturn=false;
};
/*----------------------------------------------------------------------
-- DynLayer Event Methods
----------------------------------------------------------------------*/
DynLayer.prototype.captureMouseEvents=function() {
if (this.isDynDocument && this.mouseEventsCaptured) return;
this.mouseEventsCaptured=true;
if (!this.eventListeners) this.eventListeners=[];
this.hasEventListeners=true;
if (this.isDynLayer && (!this.created || !this.elm)) return;
var o=(this.isDynDocument)?this.doc:this.elm;
if (is.ns4) {
if (this.isDynLayer) o.captureEvents(Event.MOUSEOVER | Event.MOUSEMOVE | Event.MOUSEDOWN | Event.MOUSEUP | Event.CLICK | Event.DBLCLICK | Event.MOUSEOUT);
else if (this.isDynDocument) o.captureEvents(Event.MOUSEMOVE | Event.MOUSEDOWN | Event.MOUSEUP | Event.CLICK | Event.DBLCLICK);
} else if (is.ie) {
o.oncontextmenu=function() {
return false;
};
}
if (is.ns5) {
if (this.isDynLayer) {
//true (bubble phase - from src to window): eventPhase = 1 to 2
o.addEventListener("mouseover",DynLayer.prototype.EventMethod,true);
o.addEventListener("mousemove",DynLayer.prototype.EventMethod,true);
o.addEventListener("mousedown",DynLayer.prototype.EventMethod,true);
o.addEventListener("mouseup",DynLayer.prototype.EventMethod,true);
o.addEventListener("click",DynLayer.prototype.EventMethod,true);
o.addEventListener("dblclick",DynLayer.prototype.EventMethod,true);
o.addEventListener("mouseout",DynLayer.prototype.EventMethod,true);
} else if (this.isDynDocument) {
//false (capture phase - from window to src): eventPhase = 3
o.addEventListener("mousemove",DynDocument.prototype.EventMethod,false);
o.addEventListener("mousedown",DynDocument.prototype.EventMethod,false);
o.addEventListener("mouseup",DynDocument.prototype.EventMethod,false);
o.addEventListener("click",DynDocument.prototype.EventMethod,false);
o.addEventListener("dblclick",DynDocument.prototype.EventMethod,false);
}
} else {
if (this.isDynLayer) o.onmouseover=o.onmousemove=o.onmousedown=o.onmouseup=o.onclick=o.ondblclick=o.onmouseout=DynLayer.prototype.EventMethod;
else if (this.isDynDocument) o.onmousemove=o.onmousedown=o.onmouseup=o.onclick=o.ondblclick=DynDocument.prototype.EventMethod;
}
};
DynLayer.prototype.releaseMouseEvents=function() {
this.mouseEventsCaptured=false;
if (this.isDynLayer) {
var o=this.elm;
o.onmouseover=o.onmousemove=o.onmousedown=o.onmouseup=o.onclick=o.ondblclick=o.onmouseout=function(e) {
return false;
};
} else if (this.isDynDocument) {
var o=this.doc;
o.onmousemove=o.onmousedown=o.onmouseup=o.onclick=o.ondblclick=function(e) {
return false;
};
}
};
DynLayer.prototype.EventMethod=function(e) {
var dyndoc=this.lyrobj.dyndoc;
if (is.ie) {
var e=dyndoc.elm.event;
e.cancelBubble=true;
if (e.type=="click" && DynAPI.wasDragging) {
DynAPI.wasDragging=false;
return true;
}
if ((e.type=="mouseout" && this.contains(e.toElement)) || (e.type=="mouseover" && this.contains(e.fromElement))) return true;
}
var realsrc=(is.ie)?e.srcElement:(is.ns5)?e.currentTarget:e.target;//var realsrc=(is.ie)?e.srcElement:e.target;
if (is.ie) while (!realsrc.lyrobj && realsrc.parentElement && realsrc.parentElement!=realsrc) realsrc=realsrc.parentElement;//for (; is.ie && !realsrc.lyrobj && realsrc.parentElement && realsrc.parentElement!=realsrc; realsrc=realsrc.parentElement);
else if (is.ns5) while (!realsrc.lyrobj && realsrc.parentNode && realsrc.parentNode!=realsrc) realsrc=realsrc.parentNode;
var src=realsrc.lyrobj||dyndoc;
if (!src) return true;
var evt=dyndoc._e;
evt.setEvent(src,e);
var type=evt.type;
src.invokeEvent(type,evt);
if (!this.isDynDocument && is.ns && (e.type=="mouseover" || e.type=="mouseout")) return false;
evt.bubbleEvent();
//returns false after double-click, so that the click event doesn't happen again (it happens before) after the double-click -- works all but ns5
if (type.match(/dblclick/)) return false;
//checks for mousedown so that clicks will get fired in ns4
else if (is.ns4 && evt.button!=3 && type.match(/mousedown/)) return true;
//checks if there is a right-mousedown(ns4) || right-mouseup(ns5) and prevents the right-mouse menu from popping up
else if ((is.ns4 && evt.button==3 && type.match(/mousedown/)) || (is.ns5 && evt.button==3 && type.match(/mouseup/))) return false;
else return evt.browserReturn;
};
DynLayer.prototype.addEventListener=function(listener) {
if (!this.hasEventListeners) this.captureMouseEvents();
for (var i in this.eventListeners) {
if (this.eventListeners[i]==listener) return;
}
this.eventListeners[this.eventListeners.length]=listener;
};
DynLayer.prototype.removeEventListener=function(listener) {
DynAPI.removeFromArray(this.eventListeners, listener, false);
};
DynLayer.prototype.removeAllEventListeners=function() {
if (!this.hasEventListeners) return;
for (var i in this.eventListeners) delete this.eventListeners[i];
this.eventListeners=[];
this.hasEventListeners=false;
};
DynLayer.prototype.invokeEvent=function(type,e) {
if (!this.hasEventListeners) return;
if (is.ie && this.isDynLayer && ((type=='mouseover' && this.elm.contains(e.orig.fromElement)) || (type=='mouseout' && this.elm.contains(e.orig.toElement)))) return;
var orig=null;
if (is.ns && e) {
orig=e.orig;
e.cancelBubble=false;
}
if (is.ns4 && is.platform=='other' && type.match(/mousedown/)) {
if (this.dbltimer!=null) {
type="dblclick";
if (e) e.type=type;
} else this.dbltimer=setTimeout(this+'.dbltimer=null',300);
}
for (var i=0; i<this.eventListeners.length; i++) {
if (e) e.target=this.eventListeners[i].target;
else {
e=new DynEvent(type,this);
e.target=this.eventListeners[i].target;
if (is.ns) e.cancelBubble=false;
}
this.eventListeners[i].handleEvent(type,e);
}
if (is.ns && ((this.isDynLayer && e) || (this.isDynDocument && (e || i!=0)))) {
if (e.cancelBubble) return;
if (orig && orig.target.handleEvent) {
if (this.isDynLayer && orig.target!=this.elm) orig.target.handleEvent(type,orig);
else if (this.isDynDocument && !orig.target.URL) orig.target.handleEvent(orig);
}
}
if (is.ns4 && is.platform=='other' && type=='mouseup') this.invokeEvent('click',e);
if (this.isDynLayer && this.parentComponent) {
if (e) e.src=this.parentComponent;
else e=new DynEvent(type,this);
this.parentComponent.invokeEvent(type,e);
}
};
/*----------------------------------------------------------------------
-- DynDocument Event Methods
----------------------------------------------------------------------*/
DynDocument.prototype._e=new MouseEvent();
DynDocument.prototype.captureMouseEvents=DynLayer.prototype.captureMouseEvents;
DynDocument.prototype.releaseMouseEvents=DynLayer.prototype.releaseMouseEvents;
DynDocument.prototype.EventMethod=DynLayer.prototype.EventMethod;
DynDocument.prototype.addEventListener=DynLayer.prototype.addEventListener;
DynDocument.prototype.removeEventListener=DynLayer.prototype.removeEventListener;
DynDocument.prototype.removeAllEventListeners=DynLayer.prototype.removeAllEventListeners;
DynDocument.prototype.invokeEvent=DynLayer.prototype.invokeEvent;
//-->
I have also made A LOT of modifications to dynlayer.js, which fixes some of the existing problems, including tge contentW/H (specifically in NS4 and NS6, in the createElement). But it is still undergoing evtensive testing.
I need to set up CVS on my computer, so that I can make these updates soon.
--proteanman
On Mon, 22 January 2001, ni...@pr... wrote:
>
> I tried your patch and still doubleclick on ns 6 doesn't work
> ciao
> Y
> On Mon, 22 January 2001, no...@so... wrote:
>
> >
> > Patch #103359 has been updated.
> >
> > Project: dynapi
> > Category: DynAPI-Event
> > Status: Open
> > Submitted by: camhart
> > Assigned to : nobody
> > Summary: NS6 event fixes
> >
> > Follow-Ups:
> >
> > Date: 2001-Jan-22 19:55
> > By: nobody
> >
> > Comment:
> > Tested and working
> > Richard Bennett
> > -------------------------------------------------------
> >
> > -------------------------------------------------------
> > For more info, visit:
> >
> > http://sourceforge.net/patch/?func=detailpatch&patch_id=103359&group_id=5757
> >
> > _______________________________________________
> > Dynapi-Dev mailing list
> > Dyn...@li...
> > http://lists.sourceforge.net/lists/listinfo/dynapi-dev
>
>
>
> _______________________________________________
> Dynapi-Dev mailing list
> Dyn...@li...
> http://lists.sourceforge.net/lists/listinfo/dynapi-dev
|