forked from jquery/jquery-migrate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcss.js
171 lines (141 loc) · 4.34 KB
/
css.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
QUnit.module( "css" );
QUnit.test( "jQuery.swap()", function( assert ) {
assert.expect( 6 );
var div = document.createElement( "div" );
div.style.borderWidth = "4px";
expectWarning( assert, "External swap() call", function() {
jQuery.swap( div, { borderRightWidth: "5px" }, function( arg ) {
assert.equal( this.style.borderRightWidth, "5px", "style was changed" );
assert.equal( arg, 42, "arg was passed" );
}, [ 42 ] );
} );
assert.equal( div.style.borderRightWidth, "4px", "style was restored" );
expectNoWarning( assert, "Internal swap() call", function() {
var $fp = jQuery( "#firstp" ).width( "10em" ),
width = $fp.width();
assert.equal( $fp.hide().width(), width, "correct width" );
} );
} );
QUnit[ ( jQueryVersionSince( "3.4.0" ) && typeof Proxy !== "undefined" ) ? "test" : "skip"
]( "jQuery.cssProps", function( assert ) {
assert.expect( 2 );
expectWarning( assert, "Write to cssProps", function() {
jQuery.cssProps.devoHat = "awesomeHat";
} );
expectNoWarning( assert, "Read from cssProps", function() {
// eslint-disable-next-line no-unused-expressions
jQuery.cssProps.devoHat;
// eslint-disable-next-line no-unused-expressions
jQuery.cssProps.unknownProp;
} );
delete jQuery.cssProps.devoHat;
} );
QUnit.test( "jQuery.css with arrays", function( assert ) {
assert.expect( 2 );
expectNoWarning( assert, "String value direct", function() {
var cssValues = jQuery( "<div />" )
.css( {
"z-index": "2",
fontSize: "16px"
} )
.css( [ "font-size", "zIndex" ] );
assert.deepEqual( cssValues, { "font-size": "16px", zIndex: "2" },
".css( array ) works" );
} );
} );
QUnit[
typeof Proxy !== "undefined" ? "test" : "skip"
]( "jQuery.css with numbers", function( assert ) {
var jQuery3OrOlder = compareVersions( jQuery.fn.jquery, "4.0.0" ) < 0,
allowlist = [
"margin",
"marginTop",
"marginRight",
"marginBottom",
"marginLeft",
"padding",
"paddingTop",
"paddingRight",
"paddingBottom",
"paddingLeft",
"top",
"right",
"bottom",
"left",
"width",
"height",
"minWidth",
"minHeight",
"maxWidth",
"maxHeight",
"border",
"borderWidth",
"borderTop",
"borderTopWidth",
"borderRight",
"borderRightWidth",
"borderBottom",
"borderBottomWidth",
"borderLeft",
"borderLeftWidth"
];
assert.expect( jQuery3OrOlder ? 8 : 7 );
function kebabCase( string ) {
return string.replace( /[A-Z]/g, function( match ) {
return "-" + match.toLowerCase();
} );
}
expectWarning( assert, "Number value direct", function() {
jQuery( "<div />" ).css( "fake-property", 10 );
} );
expectWarning( assert, "Number in an object", 1, function() {
jQuery( "<div />" ).css( {
"width": 14,
"height": "10px",
"fake-property": 2
} );
} );
expectNoWarning( assert, "String value direct", function() {
jQuery( "<div />" ).css( "fake-property", "10px" );
} );
expectNoWarning( assert, "String in an object", function() {
jQuery( "<div />" ).css( {
"width": "14em",
"height": "10px",
"fake-property": "2"
} );
} );
expectNoWarning( assert, "Number value (allowlisted props)", function() {
allowlist.forEach( function( prop ) {
jQuery( "<div />" ).css( prop, 1 );
jQuery( "<div />" ).css( kebabCase( prop ), 1 );
} );
} );
expectNoWarning( assert, "Props from jQuery.cssNumber", function() {
var prop,
assertionFired = false;
for ( prop in jQuery.cssNumber ) {
assertionFired = true;
jQuery( "<div />" ).css( prop, 1 );
jQuery( "<div />" ).css( kebabCase( prop ), 1 );
}
if ( jQuery3OrOlder ) {
assert.strictEqual( assertionFired, true, "jQuery.cssNumber property was accessed" );
}
} );
// z-index is tested explicitly as raw jQuery 4.0 will not have `jQuery.cssNumber`
// so iterating over it won't find anything and we'd like to ensure number values
// are not warned against for safe CSS props like z-index (gh-438).
expectNoWarning( assert, "z-index", function() {
jQuery( "<div />" ).css( "z-index", 1 );
jQuery( "<div />" ).css( kebabCase( "zIndex" ), 1 );
} );
} );
QUnit.test( "jQuery.cssNumber", function( assert ) {
assert.expect( 1 );
assert.ok( jQuery.cssNumber, "jQuery.cssNumber exists" );
} );
QUnit.test( "An unsupported jQuery.fn.css(Object,Number) signature", function( assert ) {
assert.expect( 1 );
assert.ok( ( jQuery( "<div/>" ).css( { left: "100%" }, 300 ), "No crash" ) );
} );