On Monday 11 December 2006 02:50, John Resig wrote:
> If object detection was completely feasible, that'd be great.
> Unfortunately, it doesn't work in many real-world instances. For
> example, how do you do an object detection for things that aren't
> objects? Object detection is used in jQuery, wherever possible, but
> for these other cases, it becomes necessary to use browser detection.

Yeah, that makes sense, use browser detection to catch those few hard to
detect bugs, but use object detection by default.

Wouldn't it be a good idea to re-write the event functions something like
this? (Just an example, not tested in jquery) :

                fix: function(event) {
                        // check IE, and get window event:
                        if (!event) event = window.event;
                        // fix target property:
                        if (event.target) targ = event.target;
                        else if (event.srcElement) targ = event.srcElement;
                        if (targ.nodeType == 3) // defeat Safari bug
                                targ = targ.parentNode;
                        if(!targ)return false;
                        event.cancelBubble = true;
                        if (event.stopPropagation) event.stopPropagation();
                        return event;
                }

        Instead of the current:
                fix: function(event) {
                        if(jQuery.browser.msie) {
                                // get real event from window.event
                                event = window.event;
                                // fix target property
                                event.target = event.srcElement;
                        // check safari and if target is a textnode
                        } else if(jQuery.browser.safari && 
event.target.nodeType == 3) {
                                // target is readonly, clone the event object
                                event = jQuery.extend({}, event);
                                // get parentnode from textnode
                                event.target = event.target.parentNode;
                        }
                        // fix preventDefault and stopPropagation
                        event.preventDefault = function() {
                                this.returnValue = false;
                        };
                        event.stopPropagation = function() {
                                this.cancelBubble = true;
                        };
                        return event;
                }

The code example might not be working in jQuery, it is just an example. It
seems to me it should be possible to reduce the use of browser-detection to a
bare minimum this way, which should make it much easier to maintain the code
as new browsers come out, and existing ones change their capabilities.

Cheers,

Richard.


_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

Reply via email to