[ This discussion is continued from DynAPI-Help. The last thread name was "NS4
link/event cancelling [Was: (no subject)]" ]
These are the changes I suggest to mouse.js/DynMouseEvent.EventMethod().
Tested on: IE5.5 SP1, NS4.77 & Mozilla 0.9.2, all on Win2000 SP2
At the top:
--------------------------------------------------------------------------------
DynMouseEvent.EventMethod=function(e) {
var dynobject=this.lyrobj;
if(is.def) {
if(is.ie) var e = dynobject.frame.event
e.cancelBubble = true;
if (DynAPI.wasDragging && e.type=="click") {
DynAPI.wasDragging=false;
return false; // <- was true before
}
}
--------------------------------------------------------------------------------
At the bottom it ended like this:
--------------------------------------------------------------------------------
// Click on links and form elements
if (e && e.target.handleEvent && e.target!=this)
e.target.handleEvent(e);
}
return evt.browserReturn;
}
--------------------------------------------------------------------------------
Change that to read this instead:
--------------------------------------------------------------------------------
// Click on links and form elements
if(e && e.target.handleEvent && e.target!=this && (e.target.handleEvent(e) ==
false))
evt.browserReturn = false;
}
else {
if(e.preventDefault && !evt.browserReturn)
e.preventDefault();
}
// If Internet Explorer AND evt.browserReturn is false,
// OR _any other browser_, THEN return evt.browserReturn.
// [So in IE either return false or nothing at all. This allows user
// code (<A onclick> for example) to set e.returnValue (in IE) or return
// true/false. If evt.browserReturn is false it means we're to
// disable the default action, no matter what.]
if(!is.ie || evt.browserReturn==false)
return evt.browserReturn;
}
--------------------------------------------------------------------------------
These changes would allow event handlers (the "A onclick"-handler in the example) to
cancel following the link, regardless of whether it's draggable or not.
Example webpage (please check the non-draggable case too by commenting the
DragEvent.enableDragEvents line):
--------------------------------------------------------------------------------
DynAPI.setLibraryPath("/dynapi/src/lib/");
DynAPI.include("dynapi.api.*");
DynAPI.include("dynapi.event.*")
var num=0;
DynAPI.onLoad = function() {
myLayer = new DynLayer(null, 0,50,100,100,"red");
DragEvent.enableDragEvents(myLayer);
myLayer.setHTML('<A href="misc.html" onclick="alert(1);return
false">click</A>');
myListener = new EventListener();
myListener.onclick = function(e) {
DynAPI.document.setBgColor("#808080");
window.status = ++num;
}
myLayer.addEventListener(myListener);
DynAPI.document.addChild(myLayer)
}
--------------------------------------------------------------------------------
Note: The results of dragging the link isn't consistant among the browsers. The
changes above doesn't fix this. It can be solved, but the easiest work-around I think
would be to use a cover-layer on top of the link.
/Lunna
_______________________________________________
Dynapi-Dev mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/dynapi-dev