More clean up on jQuery.clean
[jquery.git] / src / jquery / jquery.js
index 2ddb919..3816296 100644 (file)
@@ -449,6 +449,10 @@ jQuery.fn = jQuery.prototype = {
         * ok( document.getElementById('check2').checked == true, 'Set checked attribute' );
         * $("#check2").attr('checked', false);
         * ok( document.getElementById('check2').checked == false, 'Set checked attribute' );
+        * $("#text1").attr('readonly', true);
+        * ok( document.getElementById('text1').readOnly == true, 'Set readonly attribute' );
+        * $("#text1").attr('readonly', false);
+        * ok( document.getElementById('text1').readOnly == false, 'Set readonly attribute' );
         *
         * @test stop();
         * $.get('data/dashboard.xml', function(xml) { 
@@ -534,6 +538,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 +567,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 +705,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 +769,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
@@ -1457,9 +1479,11 @@ jQuery.extend({
                                        oHeight = e.offsetHeight;
                                        oWidth = e.offsetWidth;
                                } else {
-                                       e = jQuery(e.cloneNode(true)).css({
-                                               visibility: "hidden", position: "absolute", display: "block", right: "0", left: "0"
-                                       }).appendTo(e.parentNode)[0];
+                                       e = jQuery(e.cloneNode(true))
+                                               .find(":radio").removeAttr("checked").end()
+                                               .css({
+                                                       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" )
@@ -1520,44 +1544,37 @@ jQuery.extend({
 
                return ret;
        },
-
+       
        clean: function(a) {
                var r = [];
                for ( var i = 0; i < a.length; i++ ) {
-                       if ( a[i].constructor == String ) {
-                               // trim whitespace, otherwise indexOf won't work as expected
-                               a[i] = jQuery.trim(a[i]);
-                               
-                               var table = "";
-
-                               if ( !a[i].indexOf("<thead") || !a[i].indexOf("<tbody") ) {
-                                       table = "thead";
-                                       a[i] = "<table>" + a[i] + "</table>";
-                               } else if ( !a[i].indexOf("<tr") ) {
-                                       table = "tr";
-                                       a[i] = "<table>" + a[i] + "</table>";
-                               } else if ( !a[i].indexOf("<td") || !a[i].indexOf("<th") ) {
-                                       table = "td";
-                                       a[i] = "<table><tbody><tr>" + a[i] + "</tr></tbody></table>";
-                               }
-
-                               var div = document.createElement("div");
-                               div.innerHTML = a[i];
-
-                               if ( table ) {
-                                       div = div.firstChild;
-                                       if ( table != "thead" ) div = div.firstChild;
-                                       if ( table == "td" ) div = div.firstChild;
-                               }
+                       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;
+                       }
 
-                               for ( var j = 0; j < div.childNodes.length; j++ )
-                                       r.push( div.childNodes[j] );
-                               } else if ( a[i].jquery || a[i].length && !a[i].nodeType )
-                                       for ( var k = 0; k < a[i].length; k++ )
-                                               r.push( a[i][k] );
-                               else if ( a[i] !== null )
-                                       r.push( a[i].nodeType ? a[i] : document.createTextNode(a[i].toString()) );
+                       if ( arg.length != undefined && !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;
        },
 
@@ -1861,7 +1878,8 @@ jQuery.extend({
                        className: "className",
                        value: "value",
                        disabled: "disabled",
-                       checked: "checked"
+                       checked: "checked",
+                       readonly: "readOnly"
                };
                
                // IE actually uses filters for opacity ... elem is actually elem.style