decoupling styles retrieval from the attr method
This commit is contained in:
parent
9476530fa1
commit
d7d908b05a
1
Makefile
1
Makefile
|
@ -16,6 +16,7 @@ BASE_FILES = ${SRC_DIR}/core.js\
|
||||||
${SRC_DIR}/manipulation.js\
|
${SRC_DIR}/manipulation.js\
|
||||||
${SRC_DIR}/event.js\
|
${SRC_DIR}/event.js\
|
||||||
${SRC_DIR}/support.js\
|
${SRC_DIR}/support.js\
|
||||||
|
${SRC_DIR}/css.js\
|
||||||
${SRC_DIR}/ajax.js\
|
${SRC_DIR}/ajax.js\
|
||||||
${SRC_DIR}/fx.js\
|
${SRC_DIR}/fx.js\
|
||||||
${SRC_DIR}/offset.js\
|
${SRC_DIR}/offset.js\
|
||||||
|
|
|
@ -60,6 +60,7 @@
|
||||||
<fileset dir="${SRC_DIR}" includes="manipulation.js" />
|
<fileset dir="${SRC_DIR}" includes="manipulation.js" />
|
||||||
<fileset dir="${SRC_DIR}" includes="event.js" />
|
<fileset dir="${SRC_DIR}" includes="event.js" />
|
||||||
<fileset dir="${SRC_DIR}" includes="support.js" />
|
<fileset dir="${SRC_DIR}" includes="support.js" />
|
||||||
|
<fileset dir="${SRC_DIR}" includes="css.js" />
|
||||||
<fileset dir="${SRC_DIR}" includes="ajax.js" />
|
<fileset dir="${SRC_DIR}" includes="ajax.js" />
|
||||||
<fileset dir="${SRC_DIR}" includes="fx.js" />
|
<fileset dir="${SRC_DIR}" includes="fx.js" />
|
||||||
<fileset dir="${SRC_DIR}" includes="offset.js" />
|
<fileset dir="${SRC_DIR}" includes="offset.js" />
|
||||||
|
|
65
speed/benchmarker.css
Executable file
65
speed/benchmarker.css
Executable file
|
@ -0,0 +1,65 @@
|
||||||
|
|
||||||
|
.dialog {
|
||||||
|
margin-bottom: 1em;
|
||||||
|
}
|
||||||
|
a.expand {
|
||||||
|
background: #e3e3e3;
|
||||||
|
}
|
||||||
|
|
||||||
|
div#time-test {
|
||||||
|
font-family: Arial, Helvetica, sans-serif;
|
||||||
|
font-size: 62.5%;
|
||||||
|
}
|
||||||
|
|
||||||
|
td.test button {
|
||||||
|
float: right;
|
||||||
|
}
|
||||||
|
|
||||||
|
table {
|
||||||
|
border: 1px solid #000;
|
||||||
|
}
|
||||||
|
|
||||||
|
table td, table th {
|
||||||
|
border: 1px solid #000;
|
||||||
|
padding: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
td.winner {
|
||||||
|
background-color: #cfc;
|
||||||
|
}
|
||||||
|
|
||||||
|
td.tie {
|
||||||
|
background-color: #ffc;
|
||||||
|
}
|
||||||
|
|
||||||
|
td.fail {
|
||||||
|
background-color: #f99;
|
||||||
|
font-weight: bold;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
tfoot td {
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
#time-test {
|
||||||
|
margin: 1em 0;
|
||||||
|
padding: .5em;
|
||||||
|
background: #e3e3e3;
|
||||||
|
}
|
||||||
|
#time-taken {
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
span.wins {
|
||||||
|
color: #330;
|
||||||
|
}
|
||||||
|
|
||||||
|
span.fails {
|
||||||
|
color: #900;
|
||||||
|
}
|
||||||
|
|
||||||
|
div.buttons {
|
||||||
|
margin-top: 10px;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
}
|
181
speed/benchmarker.js
Executable file
181
speed/benchmarker.js
Executable file
|
@ -0,0 +1,181 @@
|
||||||
|
jQuery.benchmarker.tests = [
|
||||||
|
// Selectors from:
|
||||||
|
// http://ejohn.org/blog/selectors-that-people-actually-use/
|
||||||
|
/*
|
||||||
|
// For Amazon.com
|
||||||
|
"#navAmazonLogo", "#navSwmSkedPop",
|
||||||
|
".navbar", ".navGreeting",
|
||||||
|
"div", "table",
|
||||||
|
"img.navCrossshopTabCap", "span.navGreeting",
|
||||||
|
"#navbar table", "#navidWelcomeMsg span",
|
||||||
|
"div#navbar", "ul#navAmazonLogo",
|
||||||
|
"#navAmazonLogo .navAmazonLogoGatewayPanel", "#navidWelcomeMsg .navGreeting",
|
||||||
|
".navbar .navAmazonLogoGatewayPanel", ".navbar .navGreeting",
|
||||||
|
"*",
|
||||||
|
"#navAmazonLogo li.navAmazonLogoGatewayPanel", "#navidWelcomeMsg span.navGreeting",
|
||||||
|
"a[name=top]", "form[name=site-search]",
|
||||||
|
".navbar li", ".navbar span",
|
||||||
|
"[name=top]", "[name=site-search]",
|
||||||
|
"ul li", "a img",
|
||||||
|
"#navbar #navidWelcomeMsg", "#navbar #navSwmDWPop",
|
||||||
|
"#navbar ul li", "#navbar a img"
|
||||||
|
*/
|
||||||
|
// For Yahoo.com
|
||||||
|
"#page", "#masthead", "#mastheadhd",
|
||||||
|
".mastheadbd", ".first", ".on",
|
||||||
|
"div", "li", "a",
|
||||||
|
"div.mastheadbd", "li.first", "li.on",
|
||||||
|
"#page div", "#dtba span",
|
||||||
|
"div#page", "div#masthead",
|
||||||
|
"#page .mastheadbd", "#page .first",
|
||||||
|
".outer_search_container .search_container", ".searchbox_container .inputtext",
|
||||||
|
"*",
|
||||||
|
"#page div.mastheadbd", "#page li.first",
|
||||||
|
"input[name=p]", "a[name=marketplace]",
|
||||||
|
".outer_search_container div", ".searchbox_container span",
|
||||||
|
"[name=p]", "[name=marketplace]",
|
||||||
|
"ul li", "form input",
|
||||||
|
"#page #e2econtent", "#page #e2e"
|
||||||
|
];
|
||||||
|
|
||||||
|
jQuery.fn.benchmark = function() {
|
||||||
|
this.each(function() {
|
||||||
|
try {
|
||||||
|
jQuery(this).parent().children("*:gt(1)").remove();
|
||||||
|
} catch(e) { }
|
||||||
|
})
|
||||||
|
// set # times to run the test in index.html
|
||||||
|
var times = parseInt(jQuery("#times").val());
|
||||||
|
jQuery.benchmarker.startingList = this.get();
|
||||||
|
benchmark(this.get(), times, jQuery.benchmarker.libraries);
|
||||||
|
}
|
||||||
|
|
||||||
|
jQuery(function() {
|
||||||
|
for(i = 0; i < jQuery.benchmarker.tests.length; i++) {
|
||||||
|
jQuery("tbody").append("<tr><td class='test'>" + jQuery.benchmarker.tests[i] + "</td></tr>");
|
||||||
|
}
|
||||||
|
jQuery("tbody tr:first-child").remove();
|
||||||
|
jQuery("td.test").before("<td><input type='checkbox' checked='checked' /></td>");
|
||||||
|
jQuery("button.runTests").bind("click", function() {
|
||||||
|
jQuery('td:has(input:checked) + td.test').benchmark();
|
||||||
|
});
|
||||||
|
|
||||||
|
jQuery("button.retryTies").bind("click", function() { jQuery("tr:has(td.tie) td.test").benchmark() })
|
||||||
|
|
||||||
|
jQuery("button.selectAll").bind("click", function() { jQuery("input[type=checkbox]").each(function() { this.checked = true }) })
|
||||||
|
jQuery("button.deselectAll").bind("click", function() { jQuery("input[type=checkbox]").each(function() { this.checked = false }) })
|
||||||
|
|
||||||
|
jQuery("#addTest").bind("click", function() {
|
||||||
|
jQuery("table").append("<tr><td><input type='checkbox' /></td><td><input type='text' /><button>Add</button></td></tr>");
|
||||||
|
jQuery("div#time-test > button").each(function() { this.disabled = true; })
|
||||||
|
jQuery("tbody tr:last button").bind("click", function() {
|
||||||
|
var td = jQuery(this).parent();
|
||||||
|
td.html("<button>-</button>" + jQuery(this).prev().val()).addClass("test");
|
||||||
|
jQuery("div#time-test > button").each(function() { this.disabled = false; })
|
||||||
|
jQuery("button", td).bind("click", function() { jQuery(this).parents("tr").remove(); })
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
var headers = jQuery.map(jQuery.benchmarker.libraries, function(i,n) {
|
||||||
|
var extra = n == 0 ? "basis - " : "";
|
||||||
|
return "<th>" + extra + i + "</th>"
|
||||||
|
}).join("");
|
||||||
|
|
||||||
|
jQuery("thead tr").append(headers);
|
||||||
|
|
||||||
|
var footers = "";
|
||||||
|
for(i = 0; i < jQuery.benchmarker.libraries.length; i++)
|
||||||
|
footers += "<th></th>"
|
||||||
|
|
||||||
|
var wlfooters = "";
|
||||||
|
for(i = 0; i < jQuery.benchmarker.libraries.length; i++)
|
||||||
|
wlfooters += "<td><span class='wins'>W</span> / <span class='fails'>F</span></th>"
|
||||||
|
|
||||||
|
jQuery("tfoot tr:first").append(footers);
|
||||||
|
jQuery("tfoot tr:last").append(wlfooters);
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
benchmark = function(list, times, libraries) {
|
||||||
|
if(list[0]) {
|
||||||
|
var times = times || 50;
|
||||||
|
var el = list[0];
|
||||||
|
var code = jQuery(el).text().replace(/^-/, "");
|
||||||
|
var timeArr = []
|
||||||
|
for(i = 0; i < times + 2; i++) {
|
||||||
|
var time = new Date()
|
||||||
|
try {
|
||||||
|
window[libraries[0]](code);
|
||||||
|
} catch(e) { }
|
||||||
|
timeArr.push(new Date() - time);
|
||||||
|
}
|
||||||
|
var diff = Math.sum(timeArr) - Math.max.apply( Math, timeArr )
|
||||||
|
- Math.min.apply( Math, timeArr );
|
||||||
|
try {
|
||||||
|
var libRes = window[libraries[0]](code);
|
||||||
|
var jqRes = jQuery(code);
|
||||||
|
if(((jqRes.length == 0) && (libRes.length != 0)) ||
|
||||||
|
(libRes.length > 0 && (jqRes.length == libRes.length)) ||
|
||||||
|
((libraries[0] == "cssQuery" || libraries[0] == "jQuery") && code.match(/nth\-child/) && (libRes.length > 0)) ||
|
||||||
|
((libraries[0] == "jQold") && jqRes.length > 0)) {
|
||||||
|
jQuery(el).parent().append("<td>" + Math.round(diff / times * 100) / 100 + "ms</td>");
|
||||||
|
} else {
|
||||||
|
jQuery(el).parent().append("<td class='fail'>FAIL</td>");
|
||||||
|
}
|
||||||
|
} catch(e) {
|
||||||
|
jQuery(el).parent().append("<td class='fail'>FAIL</td>");
|
||||||
|
}
|
||||||
|
setTimeout(benchmarkList(list, times, libraries), 100);
|
||||||
|
} else if(libraries[1]) {
|
||||||
|
benchmark(jQuery.benchmarker.startingList, times, libraries.slice(1));
|
||||||
|
} else {
|
||||||
|
jQuery("tbody tr").each(function() {
|
||||||
|
var winners = jQuery("td:gt(1)", this).min(2);
|
||||||
|
if(winners.length == 1) winners.addClass("winner");
|
||||||
|
else winners.addClass("tie");
|
||||||
|
});
|
||||||
|
setTimeout(count, 100);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function benchmarkList(list, times, libraries) {
|
||||||
|
return function() {
|
||||||
|
benchmark(list.slice(1), times, libraries);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function count() {
|
||||||
|
for(i = 3; i <= jQuery.benchmarker.libraries.length + 2 ; i++) {
|
||||||
|
var fails = jQuery("td:nth-child(" + i + ").fail").length;
|
||||||
|
var wins = jQuery("td:nth-child(" + i + ").winner").length;
|
||||||
|
jQuery("tfoot tr:first th:eq(" + (i - 1) + ")")
|
||||||
|
.html("<span class='wins'>" + wins + "</span> / <span class='fails'>" + fails + "</span>");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
jQuery.fn.maxmin = function(tolerance, maxmin, percentage) {
|
||||||
|
tolerance = tolerance || 0;
|
||||||
|
var target = Math[maxmin].apply(Math, jQuery.map(this, function(i) {
|
||||||
|
var parsedNum = parseFloat(i.innerHTML.replace(/[^\.\d]/g, ""));
|
||||||
|
if(parsedNum || (parsedNum == 0)) return parsedNum;
|
||||||
|
}));
|
||||||
|
return this.filter(function() {
|
||||||
|
if( withinTolerance(parseFloat(this.innerHTML.replace(/[^\.\d]/g, "")), target, tolerance, percentage) ) return true;
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
jQuery.fn.max = function(tolerance, percentage) { return this.maxmin(tolerance, "max", percentage) }
|
||||||
|
jQuery.fn.min = function(tolerance, percentage) { return this.maxmin(tolerance, "min", percentage) }
|
||||||
|
|
||||||
|
function withinTolerance(number, target, tolerance, percentage) {
|
||||||
|
if(percentage) { var high = target + ((tolerance / 100) * target); var low = target - ((tolerance / 100) * target); }
|
||||||
|
else { var high = target + tolerance; var low = target - tolerance; }
|
||||||
|
if(number >= low && number <= high) return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Math.sum = function(arr) {
|
||||||
|
var sum = 0;
|
||||||
|
for(i = 0; i < arr.length; i++) sum += arr[i];
|
||||||
|
return sum;
|
||||||
|
}
|
72
speed/index.html
Executable file
72
speed/index.html
Executable file
File diff suppressed because one or more lines are too long
3549
speed/jquery-basis.js
vendored
Normal file
3549
speed/jquery-basis.js
vendored
Normal file
File diff suppressed because it is too large
Load diff
|
@ -1,30 +1,26 @@
|
||||||
// exclude the following css properties to add px
|
|
||||||
var exclude = /z-?index|font-?weight|opacity|zoom|line-?height/i,
|
|
||||||
// cache defaultView
|
|
||||||
defaultView = document.defaultView || {};
|
|
||||||
|
|
||||||
jQuery.fn.extend({
|
jQuery.fn.extend({
|
||||||
attr: function( name, value, type ) {
|
attr: function( name, value ) {
|
||||||
var options = name, isFunction = jQuery.isFunction( value );
|
var options = name, isFunction = jQuery.isFunction( value );
|
||||||
|
|
||||||
// Look for the case where we're accessing a style value
|
|
||||||
if ( typeof name === "string" ) {
|
if ( typeof name === "string" ) {
|
||||||
|
// Are we setting the attribute?
|
||||||
if ( value === undefined ) {
|
if ( value === undefined ) {
|
||||||
return this.length ?
|
return this.length ?
|
||||||
jQuery[ type || "attr" ]( this[0], name ) :
|
jQuery.attr( this[0], name ) :
|
||||||
null;
|
null;
|
||||||
|
|
||||||
|
// Convert name, value params to options hash format
|
||||||
} else {
|
} else {
|
||||||
options = {};
|
options = {};
|
||||||
options[ name ] = value;
|
options[ name ] = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check to see if we're setting style values
|
// For each element...
|
||||||
for ( var i = 0, l = this.length; i < l; i++ ) {
|
for ( var i = 0, l = this.length; i < l; i++ ) {
|
||||||
var elem = this[i];
|
var elem = this[i];
|
||||||
|
|
||||||
// Set all the styles
|
// Set all the attributes
|
||||||
for ( var prop in options ) {
|
for ( var prop in options ) {
|
||||||
value = options[prop];
|
value = options[prop];
|
||||||
|
|
||||||
|
@ -32,24 +28,13 @@ jQuery.fn.extend({
|
||||||
value = value.call( elem, i );
|
value = value.call( elem, i );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( typeof value === "number" && type === "curCSS" && !exclude.test(prop) ) {
|
jQuery.attr( elem, prop, value );
|
||||||
value = value + "px";
|
|
||||||
}
|
|
||||||
|
|
||||||
jQuery.attr( type ? elem.style : elem, prop, value );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
|
||||||
css: function( key, value ) {
|
|
||||||
// ignore negative width and height values
|
|
||||||
if ( (key == 'width' || key == 'height') && parseFloat(value) < 0 )
|
|
||||||
value = undefined;
|
|
||||||
return this.attr( key, value, "curCSS" );
|
|
||||||
},
|
|
||||||
|
|
||||||
hasClass: function( selector ) {
|
hasClass: function( selector ) {
|
||||||
return !!selector && this.is( "." + selector );
|
return !!selector && this.is( "." + selector );
|
||||||
},
|
},
|
||||||
|
@ -181,119 +166,6 @@ jQuery.extend({
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
// A method for quickly swapping in/out CSS properties to get correct calculations
|
|
||||||
swap: function( elem, options, callback ) {
|
|
||||||
var old = {};
|
|
||||||
// Remember the old values, and insert the new ones
|
|
||||||
for ( var name in options ) {
|
|
||||||
old[ name ] = elem.style[ name ];
|
|
||||||
elem.style[ name ] = options[ name ];
|
|
||||||
}
|
|
||||||
|
|
||||||
callback.call( elem );
|
|
||||||
|
|
||||||
// Revert the old values
|
|
||||||
for ( var name in options )
|
|
||||||
elem.style[ name ] = old[ name ];
|
|
||||||
},
|
|
||||||
|
|
||||||
css: function( elem, name, force, extra ) {
|
|
||||||
if ( name == "width" || name == "height" ) {
|
|
||||||
var val, props = { position: "absolute", visibility: "hidden", display:"block" }, which = name == "width" ? [ "Left", "Right" ] : [ "Top", "Bottom" ];
|
|
||||||
|
|
||||||
function getWH() {
|
|
||||||
val = name == "width" ? elem.offsetWidth : elem.offsetHeight;
|
|
||||||
|
|
||||||
if ( extra === "border" )
|
|
||||||
return;
|
|
||||||
|
|
||||||
jQuery.each( which, function() {
|
|
||||||
if ( !extra )
|
|
||||||
val -= parseFloat(jQuery.curCSS( elem, "padding" + this, true)) || 0;
|
|
||||||
if ( extra === "margin" )
|
|
||||||
val += parseFloat(jQuery.curCSS( elem, "margin" + this, true)) || 0;
|
|
||||||
else
|
|
||||||
val -= parseFloat(jQuery.curCSS( elem, "border" + this + "Width", true)) || 0;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( elem.offsetWidth !== 0 )
|
|
||||||
getWH();
|
|
||||||
else
|
|
||||||
jQuery.swap( elem, props, getWH );
|
|
||||||
|
|
||||||
return Math.max(0, Math.round(val));
|
|
||||||
}
|
|
||||||
|
|
||||||
return jQuery.curCSS( elem, name, force );
|
|
||||||
},
|
|
||||||
|
|
||||||
curCSS: function( elem, name, force ) {
|
|
||||||
var ret, style = elem.style;
|
|
||||||
|
|
||||||
// We need to handle opacity special in IE
|
|
||||||
if ( name == "opacity" && !jQuery.support.opacity ) {
|
|
||||||
ret = jQuery.attr( style, "opacity" );
|
|
||||||
|
|
||||||
return ret == "" ?
|
|
||||||
"1" :
|
|
||||||
ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Make sure we're using the right name for getting the float value
|
|
||||||
if ( name.match( /float/i ) )
|
|
||||||
name = styleFloat;
|
|
||||||
|
|
||||||
if ( !force && style && style[ name ] )
|
|
||||||
ret = style[ name ];
|
|
||||||
|
|
||||||
else if ( defaultView.getComputedStyle ) {
|
|
||||||
|
|
||||||
// Only "float" is needed here
|
|
||||||
if ( name.match( /float/i ) )
|
|
||||||
name = "float";
|
|
||||||
|
|
||||||
name = name.replace( /([A-Z])/g, "-$1" ).toLowerCase();
|
|
||||||
|
|
||||||
var computedStyle = defaultView.getComputedStyle( elem, null );
|
|
||||||
|
|
||||||
if ( computedStyle )
|
|
||||||
ret = computedStyle.getPropertyValue( name );
|
|
||||||
|
|
||||||
// We should always get a number back from opacity
|
|
||||||
if ( name == "opacity" && ret == "" )
|
|
||||||
ret = "1";
|
|
||||||
|
|
||||||
} else if ( elem.currentStyle ) {
|
|
||||||
var camelCase = name.replace(/\-(\w)/g, function(all, letter){
|
|
||||||
return letter.toUpperCase();
|
|
||||||
});
|
|
||||||
|
|
||||||
ret = elem.currentStyle[ name ] || elem.currentStyle[ camelCase ];
|
|
||||||
|
|
||||||
// From the awesome hack by Dean Edwards
|
|
||||||
// http://erik.eae.net/archives/2007/07/27/18.54.15/#comment-102291
|
|
||||||
|
|
||||||
// If we're not dealing with a regular pixel number
|
|
||||||
// but a number that has a weird ending, we need to convert it to pixels
|
|
||||||
if ( !/^\d+(px)?$/i.test( ret ) && /^\d/.test( ret ) ) {
|
|
||||||
// Remember the original values
|
|
||||||
var left = style.left, rsLeft = elem.runtimeStyle.left;
|
|
||||||
|
|
||||||
// Put in the new values to get a computed value out
|
|
||||||
elem.runtimeStyle.left = elem.currentStyle.left;
|
|
||||||
style.left = ret || 0;
|
|
||||||
ret = style.pixelLeft + "px";
|
|
||||||
|
|
||||||
// Revert the changed values
|
|
||||||
style.left = left;
|
|
||||||
elem.runtimeStyle.left = rsLeft;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
},
|
|
||||||
|
|
||||||
attr: function( elem, name, value ) {
|
attr: function( elem, name, value ) {
|
||||||
// don't set attributes on text and comment nodes
|
// don't set attributes on text and comment nodes
|
||||||
if (!elem || elem.nodeType == 3 || elem.nodeType == 8)
|
if (!elem || elem.nodeType == 3 || elem.nodeType == 8)
|
||||||
|
@ -307,7 +179,6 @@ jQuery.extend({
|
||||||
name = notxml && jQuery.props[ name ] || name;
|
name = notxml && jQuery.props[ name ] || name;
|
||||||
|
|
||||||
// Only do all the following if this is a node (faster for style)
|
// Only do all the following if this is a node (faster for style)
|
||||||
// IE elem.getAttribute passes even for style
|
|
||||||
if ( elem.tagName ) {
|
if ( elem.tagName ) {
|
||||||
|
|
||||||
// These attributes require special treatment
|
// These attributes require special treatment
|
||||||
|
@ -348,8 +219,12 @@ jQuery.extend({
|
||||||
return elem[ name ];
|
return elem[ name ];
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !jQuery.support.style && notxml && name == "style" )
|
if ( !jQuery.support.style && notxml && name == "style" ) {
|
||||||
return jQuery.attr( elem.style, "cssText", value );
|
if ( set )
|
||||||
|
elem.style.cssText = "" + value;
|
||||||
|
|
||||||
|
return elem.style.cssText;
|
||||||
|
}
|
||||||
|
|
||||||
if ( set )
|
if ( set )
|
||||||
// convert the value to a string (all browsers do this but IE) see #1070
|
// convert the value to a string (all browsers do this but IE) see #1070
|
||||||
|
@ -365,31 +240,7 @@ jQuery.extend({
|
||||||
}
|
}
|
||||||
|
|
||||||
// elem is actually elem.style ... set the style
|
// elem is actually elem.style ... set the style
|
||||||
|
// Using attr for specific style information is now deprecated. Use style insead.
|
||||||
// IE uses filters for opacity
|
return jQuery.style(elem, name, value);
|
||||||
if ( !jQuery.support.opacity && name == "opacity" ) {
|
|
||||||
if ( set ) {
|
|
||||||
// IE has trouble with opacity if it does not have layout
|
|
||||||
// Force it by setting the zoom level
|
|
||||||
elem.zoom = 1;
|
|
||||||
|
|
||||||
// Set the alpha filter to set the opacity
|
|
||||||
elem.filter = (elem.filter || "").replace( /alpha\([^)]*\)/, "" ) +
|
|
||||||
(parseInt( value ) + '' == "NaN" ? "" : "alpha(opacity=" + value * 100 + ")");
|
|
||||||
}
|
|
||||||
|
|
||||||
return elem.filter && elem.filter.indexOf("opacity=") >= 0 ?
|
|
||||||
(parseFloat( elem.filter.match(/opacity=([^)]*)/)[1] ) / 100) + '':
|
|
||||||
"";
|
|
||||||
}
|
|
||||||
|
|
||||||
name = name.replace(/-([a-z])/ig, function(all, letter){
|
|
||||||
return letter.toUpperCase();
|
|
||||||
});
|
|
||||||
|
|
||||||
if ( set )
|
|
||||||
elem[ name ] = value;
|
|
||||||
|
|
||||||
return elem[ name ];
|
|
||||||
}
|
}
|
||||||
});
|
});
|
205
src/css.js
Normal file
205
src/css.js
Normal file
|
@ -0,0 +1,205 @@
|
||||||
|
// exclude the following css properties to add px
|
||||||
|
var exclude = /z-?index|font-?weight|opacity|zoom|line-?height/i,
|
||||||
|
// cache defaultView
|
||||||
|
defaultView = document.defaultView || {},
|
||||||
|
// normalize float css property
|
||||||
|
styleFloat = jQuery.support.cssFloat ? "cssFloat" : "styleFloat";
|
||||||
|
|
||||||
|
jQuery.fn.css = function( name, value ) {
|
||||||
|
var options = name, isFunction = jQuery.isFunction( value );
|
||||||
|
|
||||||
|
// ignore negative width and height values
|
||||||
|
if ( (name == 'width' || name == 'height') && parseFloat(value) < 0 )
|
||||||
|
value = undefined;
|
||||||
|
|
||||||
|
if ( typeof name === "string" ) {
|
||||||
|
// Are we setting the style?
|
||||||
|
if ( value === undefined ) {
|
||||||
|
return this.length ?
|
||||||
|
jQuery.css( this[0], name ) :
|
||||||
|
null;
|
||||||
|
|
||||||
|
// Convert name, value params to options hash format
|
||||||
|
} else {
|
||||||
|
options = {};
|
||||||
|
options[ name ] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// For each element...
|
||||||
|
for ( var i = 0, l = this.length; i < l; i++ ) {
|
||||||
|
var elem = this[i];
|
||||||
|
|
||||||
|
// Set all the styles
|
||||||
|
for ( var prop in options ) {
|
||||||
|
value = options[prop];
|
||||||
|
|
||||||
|
if ( isFunction ) {
|
||||||
|
value = value.call( elem, i );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( typeof value === "number" && !exclude.test(prop) ) {
|
||||||
|
value = value + "px";
|
||||||
|
}
|
||||||
|
|
||||||
|
jQuery.style( elem, prop, value );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return this;
|
||||||
|
};
|
||||||
|
|
||||||
|
jQuery.extend({
|
||||||
|
style: function( elem, name, value ) {
|
||||||
|
// don't set styles on text and comment nodes
|
||||||
|
if (!elem || elem.nodeType == 3 || elem.nodeType == 8)
|
||||||
|
return undefined;
|
||||||
|
|
||||||
|
var style = elem.style || elem, set = value !== undefined;
|
||||||
|
|
||||||
|
// IE uses filters for opacity
|
||||||
|
if ( !jQuery.support.opacity && name == "opacity" ) {
|
||||||
|
if ( set ) {
|
||||||
|
// IE has trouble with opacity if it does not have layout
|
||||||
|
// Force it by setting the zoom level
|
||||||
|
style.zoom = 1;
|
||||||
|
|
||||||
|
// Set the alpha filter to set the opacity
|
||||||
|
style.filter = (style.filter || "").replace( /alpha\([^)]*\)/, "" ) +
|
||||||
|
(parseInt( value ) + '' == "NaN" ? "" : "alpha(opacity=" + value * 100 + ")");
|
||||||
|
}
|
||||||
|
|
||||||
|
return style.filter && style.filter.indexOf("opacity=") >= 0 ?
|
||||||
|
(parseFloat( style.filter.match(/opacity=([^)]*)/)[1] ) / 100) + '':
|
||||||
|
"";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make sure we're using the right name for getting the float value
|
||||||
|
if ( /float/i.test( name ) )
|
||||||
|
name = styleFloat;
|
||||||
|
|
||||||
|
name = name.replace(/-([a-z])/ig, function(all, letter){
|
||||||
|
return letter.toUpperCase();
|
||||||
|
});
|
||||||
|
|
||||||
|
if ( set )
|
||||||
|
style[ name ] = value;
|
||||||
|
|
||||||
|
return style[ name ];
|
||||||
|
},
|
||||||
|
|
||||||
|
css: function( elem, name, force, extra ) {
|
||||||
|
if ( name == "width" || name == "height" ) {
|
||||||
|
var val, props = { position: "absolute", visibility: "hidden", display:"block" }, which = name == "width" ? [ "Left", "Right" ] : [ "Top", "Bottom" ];
|
||||||
|
|
||||||
|
function getWH() {
|
||||||
|
val = name == "width" ? elem.offsetWidth : elem.offsetHeight;
|
||||||
|
|
||||||
|
if ( extra === "border" )
|
||||||
|
return;
|
||||||
|
|
||||||
|
jQuery.each( which, function() {
|
||||||
|
if ( !extra )
|
||||||
|
val -= parseFloat(jQuery.curCSS( elem, "padding" + this, true)) || 0;
|
||||||
|
if ( extra === "margin" )
|
||||||
|
val += parseFloat(jQuery.curCSS( elem, "margin" + this, true)) || 0;
|
||||||
|
else
|
||||||
|
val -= parseFloat(jQuery.curCSS( elem, "border" + this + "Width", true)) || 0;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( elem.offsetWidth !== 0 )
|
||||||
|
getWH();
|
||||||
|
else
|
||||||
|
jQuery.swap( elem, props, getWH );
|
||||||
|
|
||||||
|
return Math.max(0, Math.round(val));
|
||||||
|
}
|
||||||
|
|
||||||
|
return jQuery.curCSS( elem, name, force );
|
||||||
|
},
|
||||||
|
|
||||||
|
curCSS: function( elem, name, force ) {
|
||||||
|
var ret, style = elem.style;
|
||||||
|
|
||||||
|
// IE uses filters for opacity
|
||||||
|
if ( !jQuery.support.opacity && name == "opacity" ) {
|
||||||
|
ret = style.filter && style.filter.indexOf("opacity=") >= 0 ?
|
||||||
|
(parseFloat( style.filter.match(/opacity=([^)]*)/)[1] ) / 100) + '':
|
||||||
|
"";
|
||||||
|
|
||||||
|
return ret === "" ?
|
||||||
|
"1" :
|
||||||
|
ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make sure we're using the right name for getting the float value
|
||||||
|
if ( /float/i.test( name ) )
|
||||||
|
name = styleFloat;
|
||||||
|
|
||||||
|
if ( !force && style && style[ name ] ) {
|
||||||
|
ret = style[ name ];
|
||||||
|
|
||||||
|
} else if ( defaultView.getComputedStyle ) {
|
||||||
|
|
||||||
|
// Only "float" is needed here
|
||||||
|
if ( /float/i.test( name ) )
|
||||||
|
name = "float";
|
||||||
|
|
||||||
|
name = name.replace( /([A-Z])/g, "-$1" ).toLowerCase();
|
||||||
|
|
||||||
|
var computedStyle = defaultView.getComputedStyle( elem, null );
|
||||||
|
|
||||||
|
if ( computedStyle )
|
||||||
|
ret = computedStyle.getPropertyValue( name );
|
||||||
|
|
||||||
|
// We should always get a number back from opacity
|
||||||
|
if ( name == "opacity" && ret == "" )
|
||||||
|
ret = "1";
|
||||||
|
|
||||||
|
} else if ( elem.currentStyle ) {
|
||||||
|
var camelCase = name.replace(/\-(\w)/g, function(all, letter){
|
||||||
|
return letter.toUpperCase();
|
||||||
|
});
|
||||||
|
|
||||||
|
ret = elem.currentStyle[ name ] || elem.currentStyle[ camelCase ];
|
||||||
|
|
||||||
|
// From the awesome hack by Dean Edwards
|
||||||
|
// http://erik.eae.net/archives/2007/07/27/18.54.15/#comment-102291
|
||||||
|
|
||||||
|
// If we're not dealing with a regular pixel number
|
||||||
|
// but a number that has a weird ending, we need to convert it to pixels
|
||||||
|
if ( !/^\d+(px)?$/i.test( ret ) && /^\d/.test( ret ) ) {
|
||||||
|
// Remember the original values
|
||||||
|
var left = style.left, rsLeft = elem.runtimeStyle.left;
|
||||||
|
|
||||||
|
// Put in the new values to get a computed value out
|
||||||
|
elem.runtimeStyle.left = elem.currentStyle.left;
|
||||||
|
style.left = ret || 0;
|
||||||
|
ret = style.pixelLeft + "px";
|
||||||
|
|
||||||
|
// Revert the changed values
|
||||||
|
style.left = left;
|
||||||
|
elem.runtimeStyle.left = rsLeft;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
},
|
||||||
|
|
||||||
|
// A method for quickly swapping in/out CSS properties to get correct calculations
|
||||||
|
swap: function( elem, options, callback ) {
|
||||||
|
var old = {};
|
||||||
|
// Remember the old values, and insert the new ones
|
||||||
|
for ( var name in options ) {
|
||||||
|
old[ name ] = elem.style[ name ];
|
||||||
|
elem.style[ name ] = options[ name ];
|
||||||
|
}
|
||||||
|
|
||||||
|
callback.call( elem );
|
||||||
|
|
||||||
|
// Revert the old values
|
||||||
|
for ( var name in options )
|
||||||
|
elem.style[ name ] = old[ name ];
|
||||||
|
}
|
||||||
|
});
|
|
@ -305,7 +305,7 @@ jQuery.fx.prototype = {
|
||||||
// Simple 'show' function
|
// Simple 'show' function
|
||||||
show: function(){
|
show: function(){
|
||||||
// Remember where we started, so that we can go back to it later
|
// Remember where we started, so that we can go back to it later
|
||||||
this.options.orig[this.prop] = jQuery.attr( this.elem.style, this.prop );
|
this.options.orig[this.prop] = jQuery.style( this.elem, this.prop );
|
||||||
this.options.show = true;
|
this.options.show = true;
|
||||||
|
|
||||||
// Begin the animation
|
// Begin the animation
|
||||||
|
@ -320,7 +320,7 @@ jQuery.fx.prototype = {
|
||||||
// Simple 'hide' function
|
// Simple 'hide' function
|
||||||
hide: function(){
|
hide: function(){
|
||||||
// Remember where we started, so that we can go back to it later
|
// Remember where we started, so that we can go back to it later
|
||||||
this.options.orig[this.prop] = jQuery.attr( this.elem.style, this.prop );
|
this.options.orig[this.prop] = jQuery.style( this.elem, this.prop );
|
||||||
this.options.hide = true;
|
this.options.hide = true;
|
||||||
|
|
||||||
// Begin the animation
|
// Begin the animation
|
||||||
|
@ -361,7 +361,7 @@ jQuery.fx.prototype = {
|
||||||
// Reset the properties, if the item has been hidden or shown
|
// Reset the properties, if the item has been hidden or shown
|
||||||
if ( this.options.hide || this.options.show )
|
if ( this.options.hide || this.options.show )
|
||||||
for ( var p in this.options.curAnim )
|
for ( var p in this.options.curAnim )
|
||||||
jQuery.attr(this.elem.style, p, this.options.orig[p]);
|
jQuery.style(this.elem, p, this.options.orig[p]);
|
||||||
|
|
||||||
// Execute the complete function
|
// Execute the complete function
|
||||||
this.options.complete.call( this.elem );
|
this.options.complete.call( this.elem );
|
||||||
|
@ -395,7 +395,7 @@ jQuery.extend( jQuery.fx, {
|
||||||
step: {
|
step: {
|
||||||
|
|
||||||
opacity: function(fx){
|
opacity: function(fx){
|
||||||
jQuery.attr(fx.elem.style, "opacity", fx.now);
|
jQuery.style(fx.elem, "opacity", fx.now);
|
||||||
},
|
},
|
||||||
|
|
||||||
_default: function(fx){
|
_default: function(fx){
|
||||||
|
|
|
@ -91,14 +91,9 @@
|
||||||
});
|
});
|
||||||
})();
|
})();
|
||||||
|
|
||||||
var styleFloat = jQuery.support.cssFloat ? "cssFloat" : "styleFloat";
|
|
||||||
|
|
||||||
jQuery.props = {
|
jQuery.props = {
|
||||||
"for": "htmlFor",
|
"for": "htmlFor",
|
||||||
"class": "className",
|
"class": "className",
|
||||||
"float": styleFloat,
|
|
||||||
cssFloat: styleFloat,
|
|
||||||
styleFloat: styleFloat,
|
|
||||||
readonly: "readOnly",
|
readonly: "readOnly",
|
||||||
maxlength: "maxLength",
|
maxlength: "maxLength",
|
||||||
cellspacing: "cellSpacing",
|
cellspacing: "cellSpacing",
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
<script type="text/javascript" src="unit/core.js"></script>
|
<script type="text/javascript" src="unit/core.js"></script>
|
||||||
<script type="text/javascript" src="unit/data.js"></script>
|
<script type="text/javascript" src="unit/data.js"></script>
|
||||||
<script type="text/javascript" src="unit/attributes.js"></script>
|
<script type="text/javascript" src="unit/attributes.js"></script>
|
||||||
|
<script type="text/javascript" src="unit/css.js"></script>
|
||||||
<script type="text/javascript" src="unit/traversing.js"></script>
|
<script type="text/javascript" src="unit/traversing.js"></script>
|
||||||
<script type="text/javascript" src="unit/manipulation.js"></script>
|
<script type="text/javascript" src="unit/manipulation.js"></script>
|
||||||
<script type="text/javascript" src="unit/dimensions.js"></script>
|
<script type="text/javascript" src="unit/dimensions.js"></script>
|
||||||
|
|
|
@ -232,89 +232,6 @@ test("attr('tabindex', value)", function() {
|
||||||
equals(element.attr('tabindex'), -1, 'set negative tabindex');
|
equals(element.attr('tabindex'), -1, 'set negative tabindex');
|
||||||
});
|
});
|
||||||
|
|
||||||
test("css(String|Hash)", function() {
|
|
||||||
expect(19);
|
|
||||||
|
|
||||||
equals( jQuery('#main').css("display"), 'none', 'Check for css property "display"');
|
|
||||||
|
|
||||||
ok( jQuery('#nothiddendiv').is(':visible'), 'Modifying CSS display: Assert element is visible');
|
|
||||||
jQuery('#nothiddendiv').css({display: 'none'});
|
|
||||||
ok( !jQuery('#nothiddendiv').is(':visible'), 'Modified CSS display: Assert element is hidden');
|
|
||||||
jQuery('#nothiddendiv').css({display: 'block'});
|
|
||||||
ok( jQuery('#nothiddendiv').is(':visible'), 'Modified CSS display: Assert element is visible');
|
|
||||||
|
|
||||||
jQuery('#floatTest').css({styleFloat: 'right'});
|
|
||||||
equals( jQuery('#floatTest').css('styleFloat'), 'right', 'Modified CSS float using "styleFloat": Assert float is right');
|
|
||||||
jQuery('#floatTest').css({cssFloat: 'left'});
|
|
||||||
equals( jQuery('#floatTest').css('cssFloat'), 'left', 'Modified CSS float using "cssFloat": Assert float is left');
|
|
||||||
jQuery('#floatTest').css({'float': 'right'});
|
|
||||||
equals( jQuery('#floatTest').css('float'), 'right', 'Modified CSS float using "float": Assert float is right');
|
|
||||||
jQuery('#floatTest').css({'font-size': '30px'});
|
|
||||||
equals( jQuery('#floatTest').css('font-size'), '30px', 'Modified CSS font-size: Assert font-size is 30px');
|
|
||||||
|
|
||||||
jQuery.each("0,0.25,0.5,0.75,1".split(','), function(i, n) {
|
|
||||||
jQuery('#foo').css({opacity: n});
|
|
||||||
equals( jQuery('#foo').css('opacity'), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a String" );
|
|
||||||
jQuery('#foo').css({opacity: parseFloat(n)});
|
|
||||||
equals( jQuery('#foo').css('opacity'), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a Number" );
|
|
||||||
});
|
|
||||||
jQuery('#foo').css({opacity: ''});
|
|
||||||
equals( jQuery('#foo').css('opacity'), '1', "Assert opacity is 1 when set to an empty String" );
|
|
||||||
});
|
|
||||||
|
|
||||||
test("css(String, Object)", function() {
|
|
||||||
expect(21);
|
|
||||||
ok( jQuery('#nothiddendiv').is(':visible'), 'Modifying CSS display: Assert element is visible');
|
|
||||||
jQuery('#nothiddendiv').css("display", 'none');
|
|
||||||
ok( !jQuery('#nothiddendiv').is(':visible'), 'Modified CSS display: Assert element is hidden');
|
|
||||||
jQuery('#nothiddendiv').css("display", 'block');
|
|
||||||
ok( jQuery('#nothiddendiv').is(':visible'), 'Modified CSS display: Assert element is visible');
|
|
||||||
|
|
||||||
jQuery('#floatTest').css('styleFloat', 'left');
|
|
||||||
equals( jQuery('#floatTest').css('styleFloat'), 'left', 'Modified CSS float using "styleFloat": Assert float is left');
|
|
||||||
jQuery('#floatTest').css('cssFloat', 'right');
|
|
||||||
equals( jQuery('#floatTest').css('cssFloat'), 'right', 'Modified CSS float using "cssFloat": Assert float is right');
|
|
||||||
jQuery('#floatTest').css('float', 'left');
|
|
||||||
equals( jQuery('#floatTest').css('float'), 'left', 'Modified CSS float using "float": Assert float is left');
|
|
||||||
jQuery('#floatTest').css('font-size', '20px');
|
|
||||||
equals( jQuery('#floatTest').css('font-size'), '20px', 'Modified CSS font-size: Assert font-size is 20px');
|
|
||||||
|
|
||||||
jQuery.each("0,0.25,0.5,0.75,1".split(','), function(i, n) {
|
|
||||||
jQuery('#foo').css('opacity', n);
|
|
||||||
equals( jQuery('#foo').css('opacity'), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a String" );
|
|
||||||
jQuery('#foo').css('opacity', parseFloat(n));
|
|
||||||
equals( jQuery('#foo').css('opacity'), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a Number" );
|
|
||||||
});
|
|
||||||
jQuery('#foo').css('opacity', '');
|
|
||||||
equals( jQuery('#foo').css('opacity'), '1', "Assert opacity is 1 when set to an empty String" );
|
|
||||||
// for #1438, IE throws JS error when filter exists but doesn't have opacity in it
|
|
||||||
if (jQuery.browser.msie) {
|
|
||||||
jQuery('#foo').css("filter", "progid:DXImageTransform.Microsoft.Chroma(color='red');");
|
|
||||||
}
|
|
||||||
equals( jQuery('#foo').css('opacity'), '1', "Assert opacity is 1 when a different filter is set in IE, #1438" );
|
|
||||||
|
|
||||||
// using contents will get comments regular, text, and comment nodes
|
|
||||||
var j = jQuery("#nonnodes").contents();
|
|
||||||
j.css("padding-left", "1px");
|
|
||||||
equals( j.css("padding-left"), "1px", "Check node,textnode,comment css works" );
|
|
||||||
|
|
||||||
// opera sometimes doesn't update 'display' correctly, see #2037
|
|
||||||
jQuery("#t2037")[0].innerHTML = jQuery("#t2037")[0].innerHTML
|
|
||||||
equals( jQuery("#t2037 .hidden").css("display"), "none", "Make sure browser thinks it is hidden" );
|
|
||||||
});
|
|
||||||
|
|
||||||
test("jQuery.css(elem, 'height') doesn't clear radio buttons (bug #1095)", function () {
|
|
||||||
expect(4);
|
|
||||||
|
|
||||||
var $checkedtest = jQuery("#checkedtest");
|
|
||||||
// IE6 was clearing "checked" in jQuery.css(elem, "height");
|
|
||||||
jQuery.css($checkedtest[0], "height");
|
|
||||||
ok( !! jQuery(":radio:first", $checkedtest).attr("checked"), "Check first radio still checked." );
|
|
||||||
ok( ! jQuery(":radio:last", $checkedtest).attr("checked"), "Check last radio still NOT checked." );
|
|
||||||
ok( !! jQuery(":checkbox:first", $checkedtest).attr("checked"), "Check first checkbox still checked." );
|
|
||||||
ok( ! jQuery(":checkbox:last", $checkedtest).attr("checked"), "Check last checkbox still NOT checked." );
|
|
||||||
});
|
|
||||||
|
|
||||||
test("width()", function() {
|
test("width()", function() {
|
||||||
expect(6);
|
expect(6);
|
||||||
|
|
||||||
|
|
82
test/unit/css.js
Normal file
82
test/unit/css.js
Normal file
|
@ -0,0 +1,82 @@
|
||||||
|
test("css(String|Hash)", function() {
|
||||||
|
expect(19);
|
||||||
|
|
||||||
|
equals( jQuery('#main').css("display"), 'none', 'Check for css property "display"');
|
||||||
|
|
||||||
|
ok( jQuery('#nothiddendiv').is(':visible'), 'Modifying CSS display: Assert element is visible');
|
||||||
|
jQuery('#nothiddendiv').css({display: 'none'});
|
||||||
|
ok( !jQuery('#nothiddendiv').is(':visible'), 'Modified CSS display: Assert element is hidden');
|
||||||
|
jQuery('#nothiddendiv').css({display: 'block'});
|
||||||
|
ok( jQuery('#nothiddendiv').is(':visible'), 'Modified CSS display: Assert element is visible');
|
||||||
|
|
||||||
|
jQuery('#floatTest').css({styleFloat: 'right'});
|
||||||
|
equals( jQuery('#floatTest').css('styleFloat'), 'right', 'Modified CSS float using "styleFloat": Assert float is right');
|
||||||
|
jQuery('#floatTest').css({cssFloat: 'left'});
|
||||||
|
equals( jQuery('#floatTest').css('cssFloat'), 'left', 'Modified CSS float using "cssFloat": Assert float is left');
|
||||||
|
jQuery('#floatTest').css({'float': 'right'});
|
||||||
|
equals( jQuery('#floatTest').css('float'), 'right', 'Modified CSS float using "float": Assert float is right');
|
||||||
|
jQuery('#floatTest').css({'font-size': '30px'});
|
||||||
|
equals( jQuery('#floatTest').css('font-size'), '30px', 'Modified CSS font-size: Assert font-size is 30px');
|
||||||
|
|
||||||
|
jQuery.each("0,0.25,0.5,0.75,1".split(','), function(i, n) {
|
||||||
|
jQuery('#foo').css({opacity: n});
|
||||||
|
equals( jQuery('#foo').css('opacity'), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a String" );
|
||||||
|
jQuery('#foo').css({opacity: parseFloat(n)});
|
||||||
|
equals( jQuery('#foo').css('opacity'), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a Number" );
|
||||||
|
});
|
||||||
|
jQuery('#foo').css({opacity: ''});
|
||||||
|
equals( jQuery('#foo').css('opacity'), '1', "Assert opacity is 1 when set to an empty String" );
|
||||||
|
});
|
||||||
|
|
||||||
|
test("css(String, Object)", function() {
|
||||||
|
expect(21);
|
||||||
|
ok( jQuery('#nothiddendiv').is(':visible'), 'Modifying CSS display: Assert element is visible');
|
||||||
|
jQuery('#nothiddendiv').css("display", 'none');
|
||||||
|
ok( !jQuery('#nothiddendiv').is(':visible'), 'Modified CSS display: Assert element is hidden');
|
||||||
|
jQuery('#nothiddendiv').css("display", 'block');
|
||||||
|
ok( jQuery('#nothiddendiv').is(':visible'), 'Modified CSS display: Assert element is visible');
|
||||||
|
|
||||||
|
jQuery('#floatTest').css('styleFloat', 'left');
|
||||||
|
equals( jQuery('#floatTest').css('styleFloat'), 'left', 'Modified CSS float using "styleFloat": Assert float is left');
|
||||||
|
jQuery('#floatTest').css('cssFloat', 'right');
|
||||||
|
equals( jQuery('#floatTest').css('cssFloat'), 'right', 'Modified CSS float using "cssFloat": Assert float is right');
|
||||||
|
jQuery('#floatTest').css('float', 'left');
|
||||||
|
equals( jQuery('#floatTest').css('float'), 'left', 'Modified CSS float using "float": Assert float is left');
|
||||||
|
jQuery('#floatTest').css('font-size', '20px');
|
||||||
|
equals( jQuery('#floatTest').css('font-size'), '20px', 'Modified CSS font-size: Assert font-size is 20px');
|
||||||
|
|
||||||
|
jQuery.each("0,0.25,0.5,0.75,1".split(','), function(i, n) {
|
||||||
|
jQuery('#foo').css('opacity', n);
|
||||||
|
equals( jQuery('#foo').css('opacity'), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a String" );
|
||||||
|
jQuery('#foo').css('opacity', parseFloat(n));
|
||||||
|
equals( jQuery('#foo').css('opacity'), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a Number" );
|
||||||
|
});
|
||||||
|
jQuery('#foo').css('opacity', '');
|
||||||
|
equals( jQuery('#foo').css('opacity'), '1', "Assert opacity is 1 when set to an empty String" );
|
||||||
|
// for #1438, IE throws JS error when filter exists but doesn't have opacity in it
|
||||||
|
if (jQuery.browser.msie) {
|
||||||
|
jQuery('#foo').css("filter", "progid:DXImageTransform.Microsoft.Chroma(color='red');");
|
||||||
|
}
|
||||||
|
equals( jQuery('#foo').css('opacity'), '1', "Assert opacity is 1 when a different filter is set in IE, #1438" );
|
||||||
|
|
||||||
|
// using contents will get comments regular, text, and comment nodes
|
||||||
|
var j = jQuery("#nonnodes").contents();
|
||||||
|
j.css("padding-left", "1px");
|
||||||
|
equals( j.css("padding-left"), "1px", "Check node,textnode,comment css works" );
|
||||||
|
|
||||||
|
// opera sometimes doesn't update 'display' correctly, see #2037
|
||||||
|
jQuery("#t2037")[0].innerHTML = jQuery("#t2037")[0].innerHTML
|
||||||
|
equals( jQuery("#t2037 .hidden").css("display"), "none", "Make sure browser thinks it is hidden" );
|
||||||
|
});
|
||||||
|
|
||||||
|
test("jQuery.css(elem, 'height') doesn't clear radio buttons (bug #1095)", function () {
|
||||||
|
expect(4);
|
||||||
|
|
||||||
|
var $checkedtest = jQuery("#checkedtest");
|
||||||
|
// IE6 was clearing "checked" in jQuery.css(elem, "height");
|
||||||
|
jQuery.css($checkedtest[0], "height");
|
||||||
|
ok( !! jQuery(":radio:first", $checkedtest).attr("checked"), "Check first radio still checked." );
|
||||||
|
ok( ! jQuery(":radio:last", $checkedtest).attr("checked"), "Check last radio still NOT checked." );
|
||||||
|
ok( !! jQuery(":checkbox:first", $checkedtest).attr("checked"), "Check first checkbox still checked." );
|
||||||
|
ok( ! jQuery(":checkbox:last", $checkedtest).attr("checked"), "Check last checkbox still NOT checked." );
|
||||||
|
});
|
|
@ -365,7 +365,7 @@ jQuery.each( {
|
||||||
if ( t_h == "hide"||t_h == "show" )
|
if ( t_h == "hide"||t_h == "show" )
|
||||||
equals(this.style.height.indexOf(f_h), 0, "Height must be reset to " + f_h + ": " + this.style.height);
|
equals(this.style.height.indexOf(f_h), 0, "Height must be reset to " + f_h + ": " + this.style.height);
|
||||||
|
|
||||||
var cur_o = jQuery.attr(this.style, "opacity");
|
var cur_o = jQuery.style(this, "opacity");
|
||||||
if ( cur_o !== "" ) cur_o = parseFloat( cur_o );
|
if ( cur_o !== "" ) cur_o = parseFloat( cur_o );
|
||||||
|
|
||||||
if ( t_o == "hide"||t_o == "show" )
|
if ( t_o == "hide"||t_o == "show" )
|
||||||
|
|
Loading…
Reference in a new issue