Query now throws no warnings under strict mode in Firefox (ticket #922). In fixing...
[jquery.git] / src / jquery / jquery.js
index cc89fff..d04aa61 100644 (file)
@@ -614,10 +614,13 @@ jQuery.fn = jQuery.prototype = {
         */
        wrap: function() {
                // The elements to wrap the target around
-               var a = jQuery.clean(arguments);
+               var a, args = arguments;
 
                // Wrap each of the matched elements individually
                return this.each(function(){
+                       if ( !a )
+                               a = jQuery.clean(args, this.ownerDocument);
+
                        // Clone the structure that we're using to wrap
                        var b = a[0].cloneNode(true);
 
@@ -814,9 +817,9 @@ jQuery.fn = jQuery.prototype = {
         * @cat DOM/Traversing
         */
        find: function(t) {
-               return this.pushStack( jQuery.map( this, function(a){
+               return this.pushStack( jQuery.unique( jQuery.map( this, function(a){
                        return jQuery.find(t,a);
-               }), t );
+               }) ), t );
        },
 
        /**
@@ -837,7 +840,7 @@ jQuery.fn = jQuery.prototype = {
         */
        clone: function(deep) {
                return this.pushStack( jQuery.map( this, function(a){
-                       var a = a.cloneNode( deep != undefined ? deep : true );
+                       a = a.cloneNode( deep != undefined ? deep : true );
                        a.$events = null; // drop $events expando to avoid firing incorrect events
                        return a;
                }) );
@@ -1038,7 +1041,7 @@ jQuery.fn = jQuery.prototype = {
         * @cat DOM/Traversing
         */
        is: function(expr) {
-               return expr ? jQuery.filter(expr,this).r.length > 0 : false;
+               return expr ? jQuery.multiFilter(expr,this).length > 0 : false;
        },
        
        /**
@@ -1121,12 +1124,15 @@ jQuery.fn = jQuery.prototype = {
         * @cat Core
         */
        domManip: function(args, table, dir, fn){
-               var clone = this.length > 1; 
-               var a = jQuery.clean(args);
-               if ( dir < 0 )
-                       a.reverse();
+               var clone = this.length > 1, a; 
 
                return this.each(function(){
+                       if ( !a ) {
+                               a = jQuery.clean(args, this.ownerDocument);
+                               if ( dir < 0 )
+                                       a.reverse();
+                       }
+
                        var obj = this;
 
                        if ( table && jQuery.nodeName(this, "table") && jQuery.nodeName(a[0], "tr") )
@@ -1193,8 +1199,7 @@ jQuery.fn = jQuery.prototype = {
  */
 jQuery.extend = jQuery.fn.extend = function() {
        // copy reference to target object
-       var target = arguments[0],
-               a = 1;
+       var target = arguments[0], a = 1;
 
        // extend jQuery itself if only one argument is passed
        if ( arguments.length == 1 ) {
@@ -1202,7 +1207,7 @@ jQuery.extend = jQuery.fn.extend = function() {
                a = 0;
        }
        var prop;
-       while (prop = arguments[a++])
+       while ( (prop = arguments[a++]) != null )
                // Extend the base object
                for ( var i in prop ) target[i] = prop[i];
 
@@ -1255,7 +1260,7 @@ jQuery.extend({
        // is the only cross-browser way to do this. --John
        isFunction: function( fn ) {
                return !!fn && typeof fn != "string" && !fn.nodeName && 
-                       typeof fn[0] == "undefined" && /function/i.test( fn + "" );
+                       fn.constructor != Array && /function/i.test( fn + "" );
        },
        
        // check if an element is in a XML document
@@ -1339,10 +1344,7 @@ jQuery.extend({
 
                // internal only, use is(".class")
                has: function( t, c ) {
-                       t = t.className || t;
-                       // escape regex characters
-                       c = c.replace(/([\.\\\+\*\?\[\^\]\$\(\)\{\}\=\!\<\>\|\:])/g, "\\$1");
-                       return t && new RegExp("(^|\\s)" + c + "(\\s|$)").test( t );
+                       return jQuery.inArray( c, (t.className || t).toString().split(/\s+/) ) > -1;
                }
        },
 
@@ -1370,7 +1372,7 @@ jQuery.extend({
                        });
 
                        jQuery.swap( e, old, function() {
-                               if (jQuery.css(e,"display") != "none") {
+                               if ( jQuery(e).is(':visible') ) {
                                        oHeight = e.offsetHeight;
                                        oWidth = e.offsetWidth;
                                } else {
@@ -1380,14 +1382,14 @@ jQuery.extend({
                                                        visibility: "hidden", position: "absolute", display: "block", right: "0", left: "0"
                                                }).appendTo(e.parentNode)[0];
 
-                                       var parPos = jQuery.css(e.parentNode,"position");
-                                       if ( parPos == "" || parPos == "static" )
+                                       var parPos = jQuery.css(e.parentNode,"position") || "static";
+                                       if ( parPos == "static" )
                                                e.parentNode.style.position = "relative";
 
                                        oHeight = e.clientHeight;
                                        oWidth = e.clientWidth;
 
-                                       if ( parPos == "" || parPos == "static" )
+                                       if ( parPos == "static" )
                                                e.parentNode.style.position = "static";
 
                                        e.parentNode.removeChild(e);
@@ -1402,12 +1404,14 @@ jQuery.extend({
 
        curCSS: function(elem, prop, force) {
                var ret;
+
+               if (prop == "opacity" && jQuery.browser.msie) {
+                       ret = jQuery.attr(elem.style, "opacity");
+                       return ret == "" ? "1" : ret;
+               }
                
-               if (prop == "opacity" && jQuery.browser.msie)
-                       return jQuery.attr(elem.style, "opacity");
-                       
                if (prop == "float" || prop == "cssFloat")
-                   prop = jQuery.browser.msie ? "styleFloat" : "cssFloat";
+                       prop = jQuery.browser.msie ? "styleFloat" : "cssFloat";
 
                if (!force && elem.style[prop])
                        ret = elem.style[prop];
@@ -1431,17 +1435,16 @@ jQuery.extend({
                                });
 
                } else if (elem.currentStyle) {
-
                        var newProp = prop.replace(/\-(\w)/g,function(m,c){return c.toUpperCase();});
                        ret = elem.currentStyle[prop] || elem.currentStyle[newProp];
-                       
                }
 
                return ret;
        },
        
-       clean: function(a) {
+       clean: function(a, doc) {
                var r = [];
+               doc = doc || document;
 
                jQuery.each( a, function(i,arg){
                        if ( !arg ) return;
@@ -1452,13 +1455,16 @@ jQuery.extend({
                         // Convert html string into DOM nodes
                        if ( typeof arg == "string" ) {
                                // Trim whitespace, otherwise indexOf won't work as expected
-                               var s = jQuery.trim(arg), div = document.createElement("div"), tb = [];
+                               var s = jQuery.trim(arg).toLowerCase(), div = doc.createElement("div"), tb = [];
 
                                var wrap =
                                         // option or optgroup
                                        !s.indexOf("<opt") &&
                                        [1, "<select>", "</select>"] ||
                                        
+                                       !s.indexOf("<leg") &&
+                                       [1, "<fieldset>", "</fieldset>"] ||
+                                       
                                        (!s.indexOf("<thead") || !s.indexOf("<tbody") || !s.indexOf("<tfoot")) &&
                                        [1, "<table>", "</table>"] ||
                                        
@@ -1498,10 +1504,10 @@ jQuery.extend({
                                arg = jQuery.makeArray( div.childNodes );
                        }
 
-                       if ( arg.length === 0 && !jQuery.nodeName(arg, "form") )
+                       if ( 0 === arg.length && !jQuery(arg).is("form, select") )
                                return;
-                       
-                       if ( arg[0] == undefined || jQuery.nodeName(arg, "form") )
+
+                       if ( arg[0] == undefined || jQuery(arg).is("form, select") )
                                r.push( arg );
                        else
                                r = jQuery.merge( r, arg );
@@ -1527,24 +1533,21 @@ jQuery.extend({
                };
                
                // IE actually uses filters for opacity ... elem is actually elem.style
-               if ( name == "opacity" && jQuery.browser.msie && value != undefined ) {
-                       // IE has trouble with opacity if it does not have layout
-                       // Force it by setting the zoom level
-                       elem.zoom = 1; 
-
-                       // Set the alpha filter to set the opacity
-                       return elem.filter = elem.filter.replace(/alpha\([^\)]*\)/gi,"") +
-                               ( value == 1 ? "" : "alpha(opacity=" + value * 100 + ")" );
+               if ( name == "opacity" && jQuery.browser.msie ) {
+                       if ( value != undefined ) {
+                               // IE has trouble with opacity if it does not have layout
+                               // Force it by setting the zoom level
+                               elem.zoom = 1; 
+
+                               // Set the alpha filter to set the opacity
+                               elem.filter = (elem.filter || "").replace(/alpha\([^)]*\)/,"") +
+                                       (parseFloat(value).toString() == "NaN" ? "" : "alpha(opacity=" + value * 100 + ")");
+                       }
 
-               } else if ( name == "opacity" && jQuery.browser.msie )
                        return elem.filter ? 
-                               parseFloat( elem.filter.match(/alpha\(opacity=(.*)\)/)[1] ) / 100 : 1;
+                               (parseFloat( elem.filter.match(/opacity=([^)]*)/)[1] ) / 100).toString() : "";
+               }
                
-               // Mozilla doesn't play well with opacity 1
-               if ( name == "opacity" && jQuery.browser.mozilla && value == 1 )
-                       value = 0.9999;
-                       
-
                // Certain attributes only work when accessed via the old DOM 0 way
                if ( fix[name] ) {
                        if ( value != undefined ) elem[fix[name]] = value;
@@ -1586,7 +1589,8 @@ jQuery.extend({
        makeArray: function( a ) {
                var r = [];
 
-               if ( a.constructor != Array )
+               // Need to use typeof to fight Safari childNodes crashes
+               if ( typeof a != "array" )
                        for ( var i = 0, al = a.length; i < al; i++ )
                                r.push( a[i] );
                else
@@ -1624,19 +1628,27 @@ jQuery.extend({
         * @cat JavaScript
         */
        merge: function(first, second) {
-               var r = [].slice.call( first, 0 );
+               // We have to loop this way because IE & Opera overwrite the length
+               // expando of getElementsByTagName
+               for ( var i = 0; second[i]; i++ )
+                       first.push(second[i]);
+               return first;
+       },
 
-               // Now check for duplicates between the two arrays
-               // and only add the unique items
-               for ( var i = 0, sl = second.length; i < sl; i++ )
-                       // Check for duplicates
-                       if ( jQuery.inArray( second[i], r ) == -1 )
-                               // The item is unique, add it
-                               first.push( second[i] );
+       unique: function(first) {
+               var r = [], num = jQuery.mergeNum++;
 
-               return first;
+               for ( var i = 0, fl = first.length; i < fl; i++ )
+                       if ( num != first[i].mergeNum ) {
+                               first[i].mergeNum = num;
+                               r.push(first[i]);
+                       }
+
+               return r;
        },
 
+       mergeNum: 0,
+
        /**
         * Filter items out of an array, by using a filter function.
         *
@@ -1730,17 +1742,7 @@ jQuery.extend({
                        }
                }
 
-               var r = result.length ? [ result[0] ] : [];
-
-               check: for ( var i = 1, rl = result.length; i < rl; i++ ) {
-                       for ( var j = 0; j < i; j++ )
-                               if ( result[i] == r[j] )
-                                       continue check;
-
-                       r.push( result[i] );
-               }
-
-               return r;
+               return result;
        }
 });
 
@@ -1781,6 +1783,7 @@ new function() {
 
        // Figure out what browser is being used
        jQuery.browser = {
+               version: b.match(/.+[xiae][\/ ]([\d.]+)/)[1],
                safari: /webkit/.test(b),
                opera: /opera/.test(b),
                msie: /msie/.test(b) && !/opera/.test(b),