Merge "Add qtip job to pod zte-virtual6"
[releng.git] / utils / test / testapi / 3rd_party / static / testapi-ui / assets / lib / jquery / src / css.js
1 define( [
2         "./core",
3         "./var/pnum",
4         "./core/access",
5         "./css/var/rmargin",
6         "./var/document",
7         "./var/rcssNum",
8         "./css/var/rnumnonpx",
9         "./css/var/cssExpand",
10         "./css/var/getStyles",
11         "./css/var/swap",
12         "./css/curCSS",
13         "./css/adjustCSS",
14         "./css/addGetHookIf",
15         "./css/support",
16
17         "./core/init",
18         "./core/ready",
19         "./selector" // contains
20 ], function( jQuery, pnum, access, rmargin, document, rcssNum, rnumnonpx, cssExpand,
21         getStyles, swap, curCSS, adjustCSS, addGetHookIf, support ) {
22
23 "use strict";
24
25 var
26
27         // Swappable if display is none or starts with table
28         // except "table", "table-cell", or "table-caption"
29         // See here for display values: https://developer.mozilla.org/en-US/docs/CSS/display
30         rdisplayswap = /^(none|table(?!-c[ea]).+)/,
31         rcustomProp = /^--/,
32         cssShow = { position: "absolute", visibility: "hidden", display: "block" },
33         cssNormalTransform = {
34                 letterSpacing: "0",
35                 fontWeight: "400"
36         },
37
38         cssPrefixes = [ "Webkit", "Moz", "ms" ],
39         emptyStyle = document.createElement( "div" ).style;
40
41 // Return a css property mapped to a potentially vendor prefixed property
42 function vendorPropName( name ) {
43
44         // Shortcut for names that are not vendor prefixed
45         if ( name in emptyStyle ) {
46                 return name;
47         }
48
49         // Check for vendor prefixed names
50         var capName = name[ 0 ].toUpperCase() + name.slice( 1 ),
51                 i = cssPrefixes.length;
52
53         while ( i-- ) {
54                 name = cssPrefixes[ i ] + capName;
55                 if ( name in emptyStyle ) {
56                         return name;
57                 }
58         }
59 }
60
61 // Return a property mapped along what jQuery.cssProps suggests or to
62 // a vendor prefixed property.
63 function finalPropName( name ) {
64         var ret = jQuery.cssProps[ name ];
65         if ( !ret ) {
66                 ret = jQuery.cssProps[ name ] = vendorPropName( name ) || name;
67         }
68         return ret;
69 }
70
71 function setPositiveNumber( elem, value, subtract ) {
72
73         // Any relative (+/-) values have already been
74         // normalized at this point
75         var matches = rcssNum.exec( value );
76         return matches ?
77
78                 // Guard against undefined "subtract", e.g., when used as in cssHooks
79                 Math.max( 0, matches[ 2 ] - ( subtract || 0 ) ) + ( matches[ 3 ] || "px" ) :
80                 value;
81 }
82
83 function augmentWidthOrHeight( elem, name, extra, isBorderBox, styles ) {
84         var i,
85                 val = 0;
86
87         // If we already have the right measurement, avoid augmentation
88         if ( extra === ( isBorderBox ? "border" : "content" ) ) {
89                 i = 4;
90
91         // Otherwise initialize for horizontal or vertical properties
92         } else {
93                 i = name === "width" ? 1 : 0;
94         }
95
96         for ( ; i < 4; i += 2 ) {
97
98                 // Both box models exclude margin, so add it if we want it
99                 if ( extra === "margin" ) {
100                         val += jQuery.css( elem, extra + cssExpand[ i ], true, styles );
101                 }
102
103                 if ( isBorderBox ) {
104
105                         // border-box includes padding, so remove it if we want content
106                         if ( extra === "content" ) {
107                                 val -= jQuery.css( elem, "padding" + cssExpand[ i ], true, styles );
108                         }
109
110                         // At this point, extra isn't border nor margin, so remove border
111                         if ( extra !== "margin" ) {
112                                 val -= jQuery.css( elem, "border" + cssExpand[ i ] + "Width", true, styles );
113                         }
114                 } else {
115
116                         // At this point, extra isn't content, so add padding
117                         val += jQuery.css( elem, "padding" + cssExpand[ i ], true, styles );
118
119                         // At this point, extra isn't content nor padding, so add border
120                         if ( extra !== "padding" ) {
121                                 val += jQuery.css( elem, "border" + cssExpand[ i ] + "Width", true, styles );
122                         }
123                 }
124         }
125
126         return val;
127 }
128
129 function getWidthOrHeight( elem, name, extra ) {
130
131         // Start with computed style
132         var valueIsBorderBox,
133                 styles = getStyles( elem ),
134                 val = curCSS( elem, name, styles ),
135                 isBorderBox = jQuery.css( elem, "boxSizing", false, styles ) === "border-box";
136
137         // Computed unit is not pixels. Stop here and return.
138         if ( rnumnonpx.test( val ) ) {
139                 return val;
140         }
141
142         // Check for style in case a browser which returns unreliable values
143         // for getComputedStyle silently falls back to the reliable elem.style
144         valueIsBorderBox = isBorderBox &&
145                 ( support.boxSizingReliable() || val === elem.style[ name ] );
146
147         // Fall back to offsetWidth/Height when value is "auto"
148         // This happens for inline elements with no explicit setting (gh-3571)
149         if ( val === "auto" ) {
150                 val = elem[ "offset" + name[ 0 ].toUpperCase() + name.slice( 1 ) ];
151         }
152
153         // Normalize "", auto, and prepare for extra
154         val = parseFloat( val ) || 0;
155
156         // Use the active box-sizing model to add/subtract irrelevant styles
157         return ( val +
158                 augmentWidthOrHeight(
159                         elem,
160                         name,
161                         extra || ( isBorderBox ? "border" : "content" ),
162                         valueIsBorderBox,
163                         styles
164                 )
165         ) + "px";
166 }
167
168 jQuery.extend( {
169
170         // Add in style property hooks for overriding the default
171         // behavior of getting and setting a style property
172         cssHooks: {
173                 opacity: {
174                         get: function( elem, computed ) {
175                                 if ( computed ) {
176
177                                         // We should always get a number back from opacity
178                                         var ret = curCSS( elem, "opacity" );
179                                         return ret === "" ? "1" : ret;
180                                 }
181                         }
182                 }
183         },
184
185         // Don't automatically add "px" to these possibly-unitless properties
186         cssNumber: {
187                 "animationIterationCount": true,
188                 "columnCount": true,
189                 "fillOpacity": true,
190                 "flexGrow": true,
191                 "flexShrink": true,
192                 "fontWeight": true,
193                 "lineHeight": true,
194                 "opacity": true,
195                 "order": true,
196                 "orphans": true,
197                 "widows": true,
198                 "zIndex": true,
199                 "zoom": true
200         },
201
202         // Add in properties whose names you wish to fix before
203         // setting or getting the value
204         cssProps: {
205                 "float": "cssFloat"
206         },
207
208         // Get and set the style property on a DOM Node
209         style: function( elem, name, value, extra ) {
210
211                 // Don't set styles on text and comment nodes
212                 if ( !elem || elem.nodeType === 3 || elem.nodeType === 8 || !elem.style ) {
213                         return;
214                 }
215
216                 // Make sure that we're working with the right name
217                 var ret, type, hooks,
218                         origName = jQuery.camelCase( name ),
219                         isCustomProp = rcustomProp.test( name ),
220                         style = elem.style;
221
222                 // Make sure that we're working with the right name. We don't
223                 // want to query the value if it is a CSS custom property
224                 // since they are user-defined.
225                 if ( !isCustomProp ) {
226                         name = finalPropName( origName );
227                 }
228
229                 // Gets hook for the prefixed version, then unprefixed version
230                 hooks = jQuery.cssHooks[ name ] || jQuery.cssHooks[ origName ];
231
232                 // Check if we're setting a value
233                 if ( value !== undefined ) {
234                         type = typeof value;
235
236                         // Convert "+=" or "-=" to relative numbers (#7345)
237                         if ( type === "string" && ( ret = rcssNum.exec( value ) ) && ret[ 1 ] ) {
238                                 value = adjustCSS( elem, name, ret );
239
240                                 // Fixes bug #9237
241                                 type = "number";
242                         }
243
244                         // Make sure that null and NaN values aren't set (#7116)
245                         if ( value == null || value !== value ) {
246                                 return;
247                         }
248
249                         // If a number was passed in, add the unit (except for certain CSS properties)
250                         if ( type === "number" ) {
251                                 value += ret && ret[ 3 ] || ( jQuery.cssNumber[ origName ] ? "" : "px" );
252                         }
253
254                         // background-* props affect original clone's values
255                         if ( !support.clearCloneStyle && value === "" && name.indexOf( "background" ) === 0 ) {
256                                 style[ name ] = "inherit";
257                         }
258
259                         // If a hook was provided, use that value, otherwise just set the specified value
260                         if ( !hooks || !( "set" in hooks ) ||
261                                 ( value = hooks.set( elem, value, extra ) ) !== undefined ) {
262
263                                 if ( isCustomProp ) {
264                                         style.setProperty( name, value );
265                                 } else {
266                                         style[ name ] = value;
267                                 }
268                         }
269
270                 } else {
271
272                         // If a hook was provided get the non-computed value from there
273                         if ( hooks && "get" in hooks &&
274                                 ( ret = hooks.get( elem, false, extra ) ) !== undefined ) {
275
276                                 return ret;
277                         }
278
279                         // Otherwise just get the value from the style object
280                         return style[ name ];
281                 }
282         },
283
284         css: function( elem, name, extra, styles ) {
285                 var val, num, hooks,
286                         origName = jQuery.camelCase( name ),
287                         isCustomProp = rcustomProp.test( name );
288
289                 // Make sure that we're working with the right name. We don't
290                 // want to modify the value if it is a CSS custom property
291                 // since they are user-defined.
292                 if ( !isCustomProp ) {
293                         name = finalPropName( origName );
294                 }
295
296                 // Try prefixed name followed by the unprefixed name
297                 hooks = jQuery.cssHooks[ name ] || jQuery.cssHooks[ origName ];
298
299                 // If a hook was provided get the computed value from there
300                 if ( hooks && "get" in hooks ) {
301                         val = hooks.get( elem, true, extra );
302                 }
303
304                 // Otherwise, if a way to get the computed value exists, use that
305                 if ( val === undefined ) {
306                         val = curCSS( elem, name, styles );
307                 }
308
309                 // Convert "normal" to computed value
310                 if ( val === "normal" && name in cssNormalTransform ) {
311                         val = cssNormalTransform[ name ];
312                 }
313
314                 // Make numeric if forced or a qualifier was provided and val looks numeric
315                 if ( extra === "" || extra ) {
316                         num = parseFloat( val );
317                         return extra === true || isFinite( num ) ? num || 0 : val;
318                 }
319
320                 return val;
321         }
322 } );
323
324 jQuery.each( [ "height", "width" ], function( i, name ) {
325         jQuery.cssHooks[ name ] = {
326                 get: function( elem, computed, extra ) {
327                         if ( computed ) {
328
329                                 // Certain elements can have dimension info if we invisibly show them
330                                 // but it must have a current display style that would benefit
331                                 return rdisplayswap.test( jQuery.css( elem, "display" ) ) &&
332
333                                         // Support: Safari 8+
334                                         // Table columns in Safari have non-zero offsetWidth & zero
335                                         // getBoundingClientRect().width unless display is changed.
336                                         // Support: IE <=11 only
337                                         // Running getBoundingClientRect on a disconnected node
338                                         // in IE throws an error.
339                                         ( !elem.getClientRects().length || !elem.getBoundingClientRect().width ) ?
340                                                 swap( elem, cssShow, function() {
341                                                         return getWidthOrHeight( elem, name, extra );
342                                                 } ) :
343                                                 getWidthOrHeight( elem, name, extra );
344                         }
345                 },
346
347                 set: function( elem, value, extra ) {
348                         var matches,
349                                 styles = extra && getStyles( elem ),
350                                 subtract = extra && augmentWidthOrHeight(
351                                         elem,
352                                         name,
353                                         extra,
354                                         jQuery.css( elem, "boxSizing", false, styles ) === "border-box",
355                                         styles
356                                 );
357
358                         // Convert to pixels if value adjustment is needed
359                         if ( subtract && ( matches = rcssNum.exec( value ) ) &&
360                                 ( matches[ 3 ] || "px" ) !== "px" ) {
361
362                                 elem.style[ name ] = value;
363                                 value = jQuery.css( elem, name );
364                         }
365
366                         return setPositiveNumber( elem, value, subtract );
367                 }
368         };
369 } );
370
371 jQuery.cssHooks.marginLeft = addGetHookIf( support.reliableMarginLeft,
372         function( elem, computed ) {
373                 if ( computed ) {
374                         return ( parseFloat( curCSS( elem, "marginLeft" ) ) ||
375                                 elem.getBoundingClientRect().left -
376                                         swap( elem, { marginLeft: 0 }, function() {
377                                                 return elem.getBoundingClientRect().left;
378                                         } )
379                                 ) + "px";
380                 }
381         }
382 );
383
384 // These hooks are used by animate to expand properties
385 jQuery.each( {
386         margin: "",
387         padding: "",
388         border: "Width"
389 }, function( prefix, suffix ) {
390         jQuery.cssHooks[ prefix + suffix ] = {
391                 expand: function( value ) {
392                         var i = 0,
393                                 expanded = {},
394
395                                 // Assumes a single number if not a string
396                                 parts = typeof value === "string" ? value.split( " " ) : [ value ];
397
398                         for ( ; i < 4; i++ ) {
399                                 expanded[ prefix + cssExpand[ i ] + suffix ] =
400                                         parts[ i ] || parts[ i - 2 ] || parts[ 0 ];
401                         }
402
403                         return expanded;
404                 }
405         };
406
407         if ( !rmargin.test( prefix ) ) {
408                 jQuery.cssHooks[ prefix + suffix ].set = setPositiveNumber;
409         }
410 } );
411
412 jQuery.fn.extend( {
413         css: function( name, value ) {
414                 return access( this, function( elem, name, value ) {
415                         var styles, len,
416                                 map = {},
417                                 i = 0;
418
419                         if ( Array.isArray( name ) ) {
420                                 styles = getStyles( elem );
421                                 len = name.length;
422
423                                 for ( ; i < len; i++ ) {
424                                         map[ name[ i ] ] = jQuery.css( elem, name[ i ], false, styles );
425                                 }
426
427                                 return map;
428                         }
429
430                         return value !== undefined ?
431                                 jQuery.style( elem, name, value ) :
432                                 jQuery.css( elem, name );
433                 }, name, value, arguments.length > 1 );
434         }
435 } );
436
437 return jQuery;
438 } );