On 2/27/06, Bob Ippolito <[EMAIL PROTECTED]> wrote:
>
>
> On Feb 27, 2006, at 8:26 AM, Lee McFadden wrote:
>
> > I've been writing some fairly complex JS for inline editing of text
> > using http://trac.mochikit.com/wiki/HowtoSimpleAjax as a basis for
> > making my links ajax enabled rather than using the
> > href="javascript:someFunction()" nastyness.
> >
> > It all seems to work beautifully on FF, however IE is a different
> > matter altogether.
> >
> > Here is the shortest of the functions that I'm using, but it is
> > typical of the functions i've created:
> >
> > var clickNameEdit = function () {
> >     return function (evt) {
> >         //prevent the normal 'click' action for a link
> >         evt.stopPropagation();
> >         evt.preventDefault();
>
> ,.. this is broken on IE because IE does events in an entirely
> different way than Firefox does.  The ajax tables and sortable tables
> examples in the MochiKit distribution have examples of correct cross-
> browser onclick handling.  Wiki content isn't really reputable until
> proven otherwise -- in this case, that page is not (unless you only
> care about FF, of course).
>
> In MochiKit 1.3, there's the signal module that makes it easier to
> write correct cross-browser event code, but it doesn't seem to be
> quite finished yet in SVN trunk (still fails plenty of tests).
>
> -bob


Until 1.3 includes an actual Mochikit events module, you'll need to
use object detection to account for IE's events. Here are the relevant
functions in context (untested, for demonstration purposes only, etc):

var addListener = function(obj, type, func, cap)
{
 if(obj.addEventListener){
   obj.addEventListener(type, func, cap);
 } else if(obj.attachEvent){               // ie event model
   type = "on" + type;
   obj.attachEvent(type, func);
   obj.setCapture();
 }
}

var remListener = function(obj, type, func, cap)
{
 if(obj.removeEventListener){
   obj.removeEventListener(type, func, cap);
 } else if(obj.detachEvent) {
   type = "on" + type;
   obj.detachEvent(type, func)
   obj.releaseCapture();
 }
}

function handler(evt)
{
 evt = (evt) ? evt : ((window.event) ? window.event : null);
 var elem = (evt.target) ? evt.target : ((evt.srcElement) ?
evt.srcElement : null);

 if(evt.stopPropagation){
   evt.stopPropagation();
 } else {
   evt.cancelBubble = true;
 }
 if(evt.preventDefault){
   evt.preventDefault();
 } else {
   evt.returnValue = false;
 }
}

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"MochiKit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/mochikit
-~----------~----~----~----~------~----~------~--~---

Reply via email to