I should mention that I tested this in Safari 1.3, 2.0.4 and the
latest webkit along with Firefox 1.0.4 and 1.5 and IE 6 and 7. Even
though it shouldn't affect anything but Safari.

--
Brandon Aaron

On 11/2/06, Brandon Aaron <[EMAIL PROTECTED]> wrote:
> Okay ... so here is the deal. Safari reports typeof on a nodeList as a
> function. So I used that and fixed the issue. Here is the link to the
> example/test: http://brandon.jquery.com/testing/clean_safari_node_lists/
>
> The new clean method:
>
> clean: function(a) {
>     var r = [];
>     for ( var i = 0; i < a.length; i++ ) {
>         var arg = a[i];
>         if ( arg.constructor == String ) { // Convert html string into DOM 
> nodes
>             // Trim whitespace, otherwise indexOf won't work as expected
>             var s = jQuery.trim(arg), div =
> document.createElement("div"), wrap = [0,"",""];
>
>             if ( !s.indexOf("<opt") ) // option or optgroup
>                 wrap = [1, "<select>", "</select>"];
>             else if ( !s.indexOf("<thead") || !s.indexOf("<tbody") )
>                 wrap = [1, "<table>", "</table>"];
>             else if ( !s.indexOf("<tr") )
>                 wrap = [2, "<table>", "</table>"];  // tbody auto-inserted
>             else if ( !s.indexOf("<td") || !s.indexOf("<th") )
>                 wrap = [3, "<table><tbody><tr>", "</tr></tbody></table>"];
>
>             // Go to html and back, then peel off extra wrappers
>             div.innerHTML = wrap[1] + s + wrap[2];
>             while ( wrap[0]-- ) div = div.firstChild;
>             arg = div.childNodes;
>         }
>
>         if ( arg.length != undefined && ( (jQuery.browser.safari &&
> typeof arg == 'function') || !arg.nodeType ) ) // Handles Array,
> jQuery, DOM NodeList collections
>             for ( var n = 0; n < arg.length; n++ )
>                 r.push(arg[n]);
>         else
>             r.push( arg.nodeType ? arg :
> document.createTextNode(arg.toString()) );
>     }
>
>     return r;
> }
>
> I'm going to go ahead and commit ... unless anyone has some improvements.
>
> --
> Brandon Aaron
>
>
> On 11/2/06, Brandon Aaron <[EMAIL PROTECTED]> wrote:
> > On 11/2/06, Dave Methvin <[EMAIL PROTECTED]> wrote:
> > > Something just occurred to me, maybe Safari is upset trying to convert the
> > > nodeType to a boolean with the "!" operator. It's saying the value is
> > > undefined, and that is correct, so maybe we can check directly for
> > > undefined. Perhaps you could try this instead?
> > >
> > > Change
> > >
> > >    else if ( arg.length != undefined && !arg.nodeType ) // Handles Array,
> > > jQuery, DOM NodeList collections
> > >
> > > to
> > >
> > >    else if ( arg.length != undefined && arg.nodeType == undefined ) //
> > > Handles Array, jQuery, DOM NodeList collections
> >
> > I'm going to try this out. I'll post up my findings/test pages/etc as
> > soon as I have them.
> >
> > --
> > Brandon Aaron
> >
>

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

Reply via email to