Fix and tests for appending HTML options to select elements.
[jquery.git] / src / jquery / jquery.js
index 31dde99..9768eee 100644 (file)
@@ -28,7 +28,7 @@ window.undefined = window.undefined;
  * @name jQuery
  * @cat Core
  */
-function jQuery(a,c) {
+var jQuery = function(a,c) {
 
        // Shortcut for document ready (because $(document).each() is silly)
        if ( a && typeof a == "function" && jQuery.fn.ready )
@@ -71,7 +71,7 @@ function jQuery(a,c) {
                this.each(fn);
 
        return this;
-}
+};
 
 // Map over the $ in case of overwrite
 if ( typeof $ != "undefined" )
@@ -534,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('float') == 'right', 'Modified CSS float using "float": 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
@@ -555,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('float') == 'left', 'Modified CSS float using "float": 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
@@ -685,6 +701,7 @@ jQuery.fn = jQuery.prototype = {
         * @test var defaultText = 'Try them out:'
         * var result = $('#first').append('<b>buga</b>');
         * ok( result.text() == defaultText + 'buga', 'Check if text appending works' );
+        * ok( $('#select3').append('<option value="appendTest">Append Test</option>').find('option:last-child').attr('value') == 'appendTest', 'Appending html options to select element');
         *
         * @name append
         * @type jQuery
@@ -748,6 +765,7 @@ jQuery.fn = jQuery.prototype = {
         * @test var defaultText = 'Try them out:'
         * var result = $('#first').prepend('<b>buga</b>');
         * ok( result.text() == 'buga' + defaultText, 'Check if text prepending works' );
+        * ok( $('#select3').prepend('<option value="prependTest">Prepend Test</option>').find('option:first-child').attr('value') == 'prependTest', 'Prepending html options to select element');
         *
         * @name prepend
         * @type jQuery
@@ -1297,8 +1315,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;
 };
 
@@ -1492,6 +1519,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);
 
@@ -1518,7 +1548,10 @@ jQuery.extend({
                                
                                var table = "";
 
-                               if ( !a[i].indexOf("<thead") || !a[i].indexOf("<tbody") ) {
+                               if ( !a[i].indexOf("<opt") ) {
+                                  table = "thead";
+                                  a[i] = "<select>" + a[i] + "</select>";
+                               } else if ( !a[i].indexOf("<thead") || !a[i].indexOf("<tbody") ) {
                                        table = "thead";
                                        a[i] = "<table>" + a[i] + "</table>";
                                } else if ( !a[i].indexOf("<tr") ) {