Added tests for 193 and 170.
[jquery.git] / src / jquery / jquery.js
index a4ba11f..686c20d 100644 (file)
@@ -28,7 +28,7 @@ window.undefined = window.undefined;
  * @name jQuery
  * @cat Core
  */
-jQuery = function(a,c) {
+var jQuery = function(a,c) {
 
        // Shortcut for document ready (because $(document).each() is silly)
        if ( a && typeof a == "function" && jQuery.fn.ready )
@@ -50,8 +50,10 @@ jQuery = function(a,c) {
                return new jQuery(a,c);
 
        // Handle HTML strings
-       var m = /^[^<]*(<.+>)[^>]*$/.exec(a);
-       if ( m ) a = jQuery.clean( [ m[1] ] );
+       if ( a.constructor == String ) {
+               var m = /^[^<]*(<.+>)[^>]*$/.exec(a);
+               if ( m ) a = jQuery.clean( [ m[1] ] );
+       }
 
        // Watch for when an array is passed in
        this.get( a.constructor == Array || a.length && !a.nodeType && a[0] != undefined && a[0].nodeType ?
@@ -61,12 +63,14 @@ jQuery = function(a,c) {
                // Find the matching elements and save them for later
                jQuery.find( a, c ) );
 
-  // See if an extra function was provided
+       // See if an extra function was provided
        var fn = arguments[ arguments.length - 1 ];
 
        // If so, execute it in context
        if ( fn && typeof fn == "function" )
                this.each(fn);
+
+       return this;
 };
 
 // Map over the $ in case of overwrite
@@ -446,6 +450,17 @@ jQuery.fn = jQuery.prototype = {
         * $("#check2").attr('checked', false);
         * ok( document.getElementById('check2').checked == false, 'Set checked attribute' );
         *
+        * @test stop();
+        * $.get('data/dashboard.xml', function(xml) { 
+        *   var titles = [];
+        *   $('tab', xml).each(function() {
+        *     titles.push($(this).attr('title'));
+        *   });
+        *   ok( titles[0] == 'Location', 'attr() in XML context: Check first title' );
+        *   ok( titles[1] == 'Users', 'attr() in XML context: Check second title' );
+        *   start();
+        * });
+        *
         * @name attr
         * @type jQuery
         * @param String key The name of the property to set.
@@ -519,6 +534,14 @@ jQuery.fn = jQuery.prototype = {
         * ok( !$('#foo').is(':visible'), 'Modified CSS display: Assert element is hidden');
         * $('#foo').css({display: 'block'});
         * ok( $('#foo').is(':visible'), 'Modified CSS display: Assert element is visible');
+        * $('#floatTest').css({styleFloat: 'right'});
+        * ok( $('#floatTest').css('styleFloat') == 'right', 'Modified CSS float using "styleFloat": Assert float is right');
+        * $('#floatTest').css({cssFloat: 'left'});
+        * ok( $('#floatTest').css('cssFloat') == 'left', 'Modified CSS float using "cssFloat": Assert float is left');
+        * $('#floatTest').css({'float': 'right'});
+        * ok( $('#floatTest').css('cssFloat') == 'right', 'Modified CSS float using "cssFloat": Assert float is right');
+        * $('#floatTest').css({'font-size': '30px'});
+        * ok( $('#floatTest').css('font-size') == '30px', 'Modified CSS font-size: Assert font-size is 30px');
         * 
         * @name css
         * @type jQuery
@@ -540,6 +563,14 @@ jQuery.fn = jQuery.prototype = {
         * ok( !$('#foo').is(':visible'), 'Modified CSS display: Assert element is hidden');
         * $('#foo').css('display', 'block');
         * ok( $('#foo').is(':visible'), 'Modified CSS display: Assert element is visible');
+        * $('#floatTest').css('styleFloat', 'left');
+        * ok( $('#floatTest').css('styleFloat') == 'left', 'Modified CSS float using "styleFloat": Assert float is left');
+        * $('#floatTest').css('cssFloat', 'right');
+        * ok( $('#floatTest').css('cssFloat') == 'right', 'Modified CSS float using "cssFloat": Assert float is right');
+        * $('#floatTest').css('float', 'left');
+        * ok( $('#floatTest').css('cssFloat') == 'left', 'Modified CSS float using "cssFloat": Assert float is left');
+        * $('#floatTest').css('font-size', '20px');
+        * ok( $('#floatTest').css('font-size') == '20px', 'Modified CSS font-size: Assert font-size is 20px');
         *
         * @name css
         * @type jQuery
@@ -1018,6 +1049,7 @@ jQuery.fn = jQuery.prototype = {
                                for ( var i = 0; i < t.length; i++ )
                                        if ( jQuery.filter(t[i],[a]).r.length )
                                                return a;
+                               return false;
                        }) ||
 
                        t.constructor == Boolean &&
@@ -1281,8 +1313,17 @@ jQuery.fn = jQuery.prototype = {
  * @cat Javascript
  */
 jQuery.extend = jQuery.fn.extend = function(obj,prop) {
+       // Watch for the case where null or undefined gets passed in by accident
+       if ( arguments.length > 1 && (prop === null || prop == undefined) )
+               return obj;
+
+       // If no property object was provided, then we're extending jQuery
        if ( !prop ) { prop = obj; obj = this; }
+
+       // Extend the base object
        for ( var i in prop ) obj[i] = prop[i];
+
+       // Return the modified object
        return obj;
 };
 
@@ -1374,7 +1415,7 @@ jQuery.extend({
                                fn.apply( obj[i], args || [i, obj[i]] );
                else
                        for ( var i = 0; i < obj.length; i++ )
-                               fn.apply( obj[i], args || [i, obj[i]] );
+                               if ( fn.apply( obj[i], args || [i, obj[i]] ) === false ) break;
                return obj;
        },
 
@@ -1461,6 +1502,9 @@ jQuery.extend({
                
                if (prop == 'opacity' && jQuery.browser.msie)
                        return jQuery.attr(elem.style, 'opacity');
+                       
+               if (prop == "float" || prop == "cssFloat")
+                   prop = jQuery.browser.msie ? "styleFloat" : "cssFloat";
 
                if (!force && elem.style[prop]) {
 
@@ -1473,6 +1517,9 @@ jQuery.extend({
 
                } else if (document.defaultView && document.defaultView.getComputedStyle) {
 
+                       if (prop == "cssFloat" || prop == "styleFloat")
+                               prop = "float";
+
                        prop = prop.replace(/([A-Z])/g,"-$1").toLowerCase();
                        var cur = document.defaultView.getComputedStyle(elem, null);
 
@@ -1555,7 +1602,7 @@ jQuery.extend({
                        empty: "!a.childNodes.length",
 
                        // Text Check
-                       contains: "(a.innerText||a.innerHTML).indexOf(m[3])>=0",
+                       contains: "jQuery.fn.text.apply([a]).indexOf(m[3])>=0",
 
                        // Visibility
                        visible: "a.type!='hidden'&&jQuery.css(a,'display')!='none'&&jQuery.css(a,'visibility')!='hidden'",
@@ -1645,9 +1692,9 @@ jQuery.extend({
         * t( "Attribute Exists", "*[@title]", ["google"] );
         * t( "Attribute Exists", "[@title]", ["google"] );
         * 
-        * t( "Non-existing part of attribute [@name*=bla]", "[@name*=bla]", [] ); 
-        * t( "Non-existing start of attribute [@name^=bla]", "[@name^=bla]", [] ); 
-        * t( "Non-existing end of attribute [@name$=bla]", "[@name$=bla]", [] ); 
+        * t( "Non-existing part of attribute", "[@name*=bla]", [] ); 
+        * t( "Non-existing start of attribute", "[@name^=bla]", [] ); 
+        * t( "Non-existing end of attribute", "[@name$=bla]", [] ); 
         *
         * t( "Attribute Equals", "a[@rel='bookmark']", ["simon1"] );
         * t( "Attribute Equals", 'a[@rel="bookmark"]', ["simon1"] );
@@ -1824,7 +1871,8 @@ jQuery.extend({
                var fix = {
                        "for": "htmlFor",
                        "class": "className",
-                       "float": "cssFloat",
+                       "float": jQuery.browser.msie ? "styleFloat" : "cssFloat",
+                       cssFloat: jQuery.browser.msie ? "styleFloat" : "cssFloat",
                        innerHTML: "innerHTML",
                        className: "className",
                        value: "value",
@@ -1855,7 +1903,7 @@ jQuery.extend({
                        return elem.getAttributeNode(name).nodeValue;
                } else if ( elem.getAttribute != undefined && elem.tagName ) { // IE elem.getAttribute passes even for style
                        if ( value != undefined ) elem.setAttribute( name, value );
-                       return elem.getAttribute( name, 2 );
+                       return elem.getAttribute( name );
                } else {
                        name = name.replace(/-([a-z])/ig,function(z,b){return b.toUpperCase();});
                        if ( value != undefined ) elem[name] = value;
@@ -2216,12 +2264,12 @@ jQuery.extend({
                },
 
                handle: function(event) {
-                       if ( typeof jQuery == "undefined" ) return;
+                       if ( typeof jQuery == "undefined" ) return false;
 
                        event = event || jQuery.event.fix( window.event );
 
                        // If no correct event was found, fail
-                       if ( !event ) return;
+                       if ( !event ) return false;
 
                        var returnValue = true;
 
@@ -2677,7 +2725,7 @@ jQuery.macros = {
                /**
                 * Set the value of every matched element.
                 *
-                * @example $("input").value("test");
+                * @example $("input").val("test");
                 * @before <input type="text" value="some text"/>
                 * @result <input type="text" value="test"/>
                 *