Changeset 927 for trunk/jquery/src
- Timestamp:
- 01/08/07 02:39:10 (2 years ago)
- Files:
-
- 1 modified
-
trunk/jquery/src/jquery/jquery.js (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/jquery/src/jquery/jquery.js
r926 r927 431 431 */ 432 432 attr: function( key, value, type ) { 433 var obj = key; 434 435 // Look for the case where we're accessing a style value 436 if ( key.constructor == String ) 437 if ( value == undefined ) 438 return jQuery[ type || "attr" ]( this[0], key ); 439 else { 440 obj = {}; 441 obj[ key ] = value; 442 } 443 433 444 // Check to see if we're setting style values 434 return typeof key != "string" || value != undefined ? 435 this.each(function(){ 436 // See if we're setting a hash of styles 437 if ( value == undefined ) 438 // Set all the styles 439 for ( var prop in key ) 440 jQuery.attr( 441 type ? this.style : this, 442 prop, jQuery.prop(this, prop, key[prop], type) 443 ); 444 445 // See if we're setting a single key/value style 446 else 447 jQuery.attr( 448 type ? this.style : this, 449 key, jQuery.prop(this, key, value, type) 450 ); 451 }) : 452 453 // Look for the case where we're accessing a style value 454 jQuery[ type || "attr" ]( this[0], key ); 445 return this.each(function(){ 446 // Set all the styles 447 for ( var prop in obj ) 448 jQuery.attr( 449 type ? this.style : this, 450 prop, jQuery.prop(this, prop, obj[prop], type) 451 ); 452 }); 455 453 }, 456 454 … … 1046 1044 return val == undefined ? 1047 1045 ( this.length ? this[0].innerHTML : null ) : 1048 this. attr( "innerHTML",val );1046 this.empty().append( val ); 1049 1047 }, 1050 1048 … … 1314 1312 prop = jQuery.browser.msie ? "styleFloat" : "cssFloat"; 1315 1313 1316 if (!force && elem.style[prop]) { 1317 1314 if (!force && elem.style[prop]) 1318 1315 ret = elem.style[prop]; 1319 1316 1320 }else if (document.defaultView && document.defaultView.getComputedStyle) {1317 else if (document.defaultView && document.defaultView.getComputedStyle) { 1321 1318 1322 1319 if (prop == "cssFloat" || prop == "styleFloat") … … 1348 1345 clean: function(a) { 1349 1346 var r = []; 1347 1350 1348 for ( var i = 0, al = a.length; i < al; i++ ) { 1351 1349 var arg = a[i]; 1352 if ( typeof arg == "string" ) { // Convert html string into DOM nodes 1350 1351 // Convert html string into DOM nodes 1352 if ( typeof arg == "string" ) { 1353 1353 // Trim whitespace, otherwise indexOf won't work as expected 1354 var s = jQuery.trim(arg), s3 = s.substring(0,3), s6 = s.substring(0,6), 1355 div = document.createElement("div"), wrap = [0,"",""]; 1356 1357 if ( s.substring(0,4) == "<opt" ) // option or optgroup 1358 wrap = [1, "<select>", "</select>"]; 1359 else if ( s6 == "<thead" || s6 == "<tbody" || s6 == "<tfoot" ) 1360 wrap = [1, "<table>", "</table>"]; 1361 else if ( s3 == "<tr" ) 1362 wrap = [2, "<table><tbody>", "</tbody></table>"]; 1363 else if ( s3 == "<td" || s3 == "<th" ) // <thead> matched above 1364 wrap = [3, "<table><tbody><tr>", "</tr></tbody></table>"]; 1354 var s = jQuery.trim(arg), div = document.createElement("div"), tb = []; 1355 1356 var wrap = 1357 // option or optgroup 1358 !s.indexOf("<opt") && [1, "<select>", "</select>"] || 1359 1360 !s.indexOf("<thead") || !s.indexOf("<tbody") || !s.indexOf("<tfoot") && 1361 [1, "<table>", "</table>"] || 1362 1363 !s.indexOf("<tr") && 1364 [2, "<table><tbody>", "</tbody></table>"] || 1365 1366 // <thead> matched above 1367 !s.indexOf("<td") || !s.indexOf("<th") && 1368 [3, "<table><tbody><tr>", "</tr></tbody></table>"] || 1369 1370 [0,"",""]; 1365 1371 1366 1372 // Go to html and back, then peel off extra wrappers 1367 1373 div.innerHTML = wrap[1] + s + wrap[2]; 1368 while ( wrap[0]-- ) div = div.firstChild; 1374 1375 // Move to the right depth 1376 while ( wrap[0]-- ) 1377 div = div.firstChild; 1369 1378 1370 1379 // Remove IE's autoinserted <tbody> from table fragments 1371 1380 if ( jQuery.browser.msie ) { 1372 var tb = null;1381 1373 1382 // String was a <table>, *may* have spurious <tbody> 1374 if ( s6 == "<table"&& s.indexOf("<tbody") < 0 )1383 if ( !s.indexOf("<table") && s.indexOf("<tbody") < 0 ) 1375 1384 tb = div.firstChild && div.firstChild.childNodes; 1385 1376 1386 // String was a bare <thead> or <tfoot> 1377 1387 else if ( wrap[1] == "<table>" && s.indexOf("<tbody") < 0 ) 1378 1388 tb = div.childNodes; 1379 if ( tb ) { 1380 for ( var n = tb.length-1; n >= 0 ; --n )1381 if ( tb[n].nodeName.toUpperCase() == "TBODY" && !tb[n].childNodes.length )1382 tb[n].parentNode.removeChild(tb[n]);1383 }1389 1390 for ( var n = tb.length-1; n >= 0 ; --n ) 1391 if ( tb[n].nodeName.toUpperCase() == "TBODY" && !tb[n].childNodes.length ) 1392 tb[n].parentNode.removeChild(tb[n]); 1393 1384 1394 } 1385 1395 1386 1396 arg = div.childNodes; 1387 } 1397 } 1388 1398 1389 1390 if ( arg.length != undefined && ( (jQuery.browser.safari && typeof arg == 'function') || !arg.nodeType ) ) // Safari reports typeof on a DOM NodeList to be a function 1391 for ( var n = 0, argl = arg.length; n < argl; n++ ) // Handles Array, jQuery, DOM NodeList collections 1392 r.push(arg[n]); 1399 if ( arg.nodeType ) 1400 r.push( arg ); 1393 1401 else 1394 r .push( arg.nodeType ? arg : document.createTextNode(arg.toString()));1402 r = jQuery.merge( r, arg ); 1395 1403 } 1396 1404 … … 1423 1431 ( value == 1 ? "" : "alpha(opacity=" + value * 100 + ")" ); 1424 1432 1425 } else if ( name == "opacity" && jQuery.browser.msie ) {1433 } else if ( name == "opacity" && jQuery.browser.msie ) 1426 1434 return elem.filter ? 1427 1435 parseFloat( elem.filter.match(/alpha\(opacity=(.*)\)/)[1] ) / 100 : 1; 1428 }1429 1436 1430 1437 // Mozilla doesn't play well with opacity 1 … … 1437 1444 return elem[fix[name]]; 1438 1445 1439 } else if ( value == undefined && jQuery.browser.msie && elem.nodeName && elem.nodeName.toUpperCase() == 'FORM' && (name == 'action' || name == 'method') ) {1446 } else if ( value == undefined && jQuery.browser.msie && elem.nodeName && elem.nodeName.toUpperCase() == 'FORM' && (name == 'action' || name == 'method') ) 1440 1447 return elem.getAttributeNode(name).nodeValue; 1441 1448 1442 1449 // IE elem.getAttribute passes even for style 1443 }else if ( elem.tagName ) {1450 else if ( elem.tagName ) { 1444 1451 if ( value != undefined ) elem.setAttribute( name, value ); 1445 1452 return elem.getAttribute( name ); … … 1470 1477 var r = []; 1471 1478 1472 if ( a.constructor != Array ) {1479 if ( a.constructor != Array ) 1473 1480 for ( var i = 0, al = a.length; i < al; i++ ) 1474 1481 r.push( a[i] ); 1475 }else1482 else 1476 1483 r = a.slice( 0 ); 1477 1484 … … 1511 1518 // Now check for duplicates between the two arrays 1512 1519 // and only add the unique items 1513 for ( var i = 0, sl = second.length; i < sl; i++ ) {1520 for ( var i = 0, sl = second.length; i < sl; i++ ) 1514 1521 // Check for duplicates 1515 1522 if ( jQuery.inArray( second[i], r ) == -1 ) 1516 1523 // The item is unique, add it 1517 1524 first.push( second[i] ); 1518 }1519 1525 1520 1526 return first;
