]> source.dussan.org Git - jquery.git/commitdiff
Fixed some bugs with the test suite and fixed a bug with setting attributes.
authorJohn Resig <jeresig@gmail.com>
Fri, 25 Aug 2006 18:38:24 +0000 (18:38 +0000)
committerJohn Resig <jeresig@gmail.com>
Fri, 25 Aug 2006 18:38:24 +0000 (18:38 +0000)
build/test/js/test.js
build/test/test.js
src/jquery/jquery.js

index e4da77b36294da255c1c216bdd6bdf4360e49121..44a405fdbf4407c2ce900e62638e8f3bdd608b74 100644 (file)
@@ -4,7 +4,7 @@ function runTests(files) {
 
 function runTest( files, num ) {
        $.get(files[num],function(js){
-               js = js.replace(/&lt;/g, "<").replace(/&gt;/g, ">");
+               js = js.replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&amp;/g, "&");
 
                try {
                        eval(js);
index 453eb5db79744bf8c15ed741f7547d82949734f5..6aeeb6b97f324a2620c90f55bb34ae73cde88f86 100644 (file)
@@ -4,16 +4,15 @@ var dir = arguments[1];
 
 var indexFile = readFile( "build/test/index.html" );
 var testFile = readFile( "build/test/test.html" );
-var files = {};
 
 var jq = parse( readFile( arguments[0] ) );
 
+var fileList = [];
+var count = 1;
+
 for ( var i = 0; i < jq.length; i++ ) {
        if ( jq[i].tests.length > 0 ) {
-
-               var count = 1;
-               while ( files[ jq[i].name + count ] ) { count++; }
-               var name = jq[i].name + count;
+               var name = count + "-" + jq[i].name;
                
                var myFile = testFile
                        .replace( /{TITLE}/g, jq[i].name )
@@ -22,17 +21,18 @@ for ( var i = 0; i < jq.length; i++ ) {
 
                var fileName = "tests/" + name + ".js";
 
-               //writeFile( dir + "/" + fileName, myFile );
                writeFile( dir + "/" + fileName, jq[i].tests.join("\n") );
 
-               files[ fileName ] = 1;
+               fileList.push( fileName );
+
+               count++;
        }
 }
 
 var fileString = "";
-for ( var i in files ) {
+for ( var i = 0; i < fileList.length; i++ ) {
        if ( fileString ) fileString += ", ";
-       fileString += "'" + i + "'";
+       fileString += "'" + fileList[i] + "'";
 }
 
 writeFile( dir + "/index.html", indexFile.replace( /{FILES}/g, fileString ) );
index 08f325c34a8c1af2d1c0bb77b495587090cfca2a..017d9ad07c2166dfc7850b9767611f6f8060e263 100644 (file)
@@ -265,12 +265,10 @@ jQuery.fn = jQuery.prototype = {
         * @before <img/>
         * @result <img src="test.jpg" alt="Test Image"/>
         *
-        * @test var div = $("div");
-        * div.attr({foo: 'baz', zoo: 'ping'});
-        * var pass = true;
-        * for ( var i = 0; i < div.size(); i++ ) {
-        *   if ( div.get(i).foo != "baz" && div.get(i).zoo != "ping" ) pass = false;
-        * }
+        * @test var pass = true;
+        * $("div").attr({foo: 'baz', zoo: 'ping'}).each(function(){
+        *   if ( this.getAttribute('foo') != "baz" && this.getAttribute('zoo') != "ping" ) pass = false;
+        * });
         * ok( pass, "Set Multiple Attributes" );
         *
         * @name attr
@@ -290,7 +288,7 @@ jQuery.fn = jQuery.prototype = {
         * div.attr("foo", "bar");
         * var pass = true;
         * for ( var i = 0; i < div.size(); i++ ) {
-        *   if ( div.get(i).foo != "bar" ) pass = false;
+        *   if ( div.get(i).getAttribute('foo') != "bar" ) pass = false;
         * }
         * ok( pass, "Set Attribute" );
         *
@@ -1255,28 +1253,26 @@ jQuery.extend({
                return r;
        },
        
-       attr: function(o,a,v){
-               if ( a && a.constructor == String ) {
-                       var fix = {
-                               "for": "htmlFor",
-                               "class": "className",
-                               "float": "cssFloat"
-                       };
-                       
-                       a = (fix[a] && fix[a].replace && fix[a] || a)
-                               .replace(/-([a-z])/ig,function(z,b){
-                                       return b.toUpperCase();
-                               });
-                       
-                       if ( v != undefined ) {
-                               o[a] = v;
-                               if ( o.setAttribute && a != "disabled" )
-                                       o.setAttribute(a,v);
-                       }
-                       
-                       return o[a] || o.getAttribute && o.getAttribute(a) || "";
-               } else
-                       return "";
+       attr: function(elem, name, value){
+               var fix = {
+                       "for": "htmlFor",
+                       "class": "className",
+                       "float": "cssFloat",
+                       innerHTML: "innerHTML",
+                       className: "className"
+               };
+
+               if ( fix[name] ) {
+                       if ( value != undefined ) elem[fix[name]] = value;
+                       return elem[fix[name]];
+               } else if ( elem.getAttribute ) {
+                       if ( value != undefined ) elem.setAttribute( name, value );
+                       return elem.getAttribute( name, 2 );
+               } else {
+                       name = name.replace(/-([a-z])/ig,function(z,b){return b.toUpperCase();});
+                       if ( value != undefined ) elem[name] = value;
+                       return elem[name];
+               }
        },
 
        // The regular expressions that power the parsing engine