🌐 AI搜索 & 代理 主页
Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
CSS: workaround trim whitespace #4926
  • Loading branch information
fecore1 committed Sep 13, 2021
commit 04d7e47aeddf48e9ee84ace3a5798c147a0ac70f
5 changes: 4 additions & 1 deletion src/css/curCSS.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ function curCSS( elem, name, computed ) {

// getPropertyValue is needed for `.css('--customProperty')` (gh-3144)
if ( computed ) {
ret = computed.getPropertyValue( name ) || computed[ name ];
ret = computed.getPropertyValue( name );

// trim whitespace (issue #4926)
ret = ( ret && ret.trim() ) || computed[ name ];

if ( ret === "" && !isAttached( elem ) ) {
ret = jQuery.style( elem, name );
Expand Down
16 changes: 9 additions & 7 deletions test/unit/css.js
Original file line number Diff line number Diff line change
Expand Up @@ -1739,8 +1739,9 @@ QUnit.testUnlessIE( "css(--customProperty)", function( assert ) {
" --prop1:val1;\n" +
" --prop2: val2;\n" +
" --prop3:val3 ;\n" +
" --prop4:\"val4\";\n" +
" --prop5:'val5';\n" +
" --prop4: val4 ;\n" +
" --prop5:\"val5\";\n" +
" --prop6:'val6';\n" +
" }\n" +
"</style>"
);
Expand All @@ -1749,7 +1750,7 @@ QUnit.testUnlessIE( "css(--customProperty)", function( assert ) {
$elem = jQuery( "<div>" ).addClass( "test__customProperties" )
.appendTo( "#qunit-fixture" ),
webkitOrBlink = /\bsafari\b/i.test( navigator.userAgent ),
expected = 10;
expected = 11;

if ( webkitOrBlink ) {
expected -= 2;
Expand Down Expand Up @@ -1777,15 +1778,16 @@ QUnit.testUnlessIE( "css(--customProperty)", function( assert ) {

assert.equal( $elem.css( "--prop1" ), "val1", "Basic CSS custom property" );

assert.equal( $elem.css( "--prop2" ), " val2", "Preceding whitespace maintained" );
assert.equal( $elem.css( "--prop3" ), "val3 ", "Following whitespace maintained" );
assert.equal( $elem.css( "--prop2" ), "val2", "Preceding whitespace trimmed" );
assert.equal( $elem.css( "--prop3" ), "val3", "Following whitespace trimmed" );
assert.equal( $elem.css( "--prop4" ), "val4", "Preceding and Following whitespace trimmed" );

// Support: Chrome <=49 - 73+, Safari <=9.1 - 12.1+
// Chrome treats single quotes as double ones.
// Safari treats double quotes as single ones.
if ( !webkitOrBlink ) {
assert.equal( $elem.css( "--prop4" ), "\"val4\"", "Works with double quotes" );
assert.equal( $elem.css( "--prop5" ), "'val5'", "Works with single quotes" );
assert.equal( $elem.css( "--prop5" ), "\"val5\"", "Works with double quotes" );
assert.equal( $elem.css( "--prop6" ), "'val6'", "Works with single quotes" );
}
} );

Expand Down