c5169e0e
Renato De Donato
a new hope
|
1
|
define([
|
74249687
Luigi Serra
Cross browser con...
|
2
3
4
5
|
"./core",
"./var/pnum",
"./core/access",
"./css/var/rmargin",
|
74249687
Luigi Serra
Cross browser con...
|
6
7
8
9
|
"./css/var/rnumnonpx",
"./css/var/cssExpand",
"./css/var/isHidden",
"./css/var/getStyles",
|
74249687
Luigi Serra
Cross browser con...
|
10
|
"./css/curCSS",
|
74249687
Luigi Serra
Cross browser con...
|
11
12
13
|
"./css/defaultDisplay",
"./css/addGetHookIf",
"./css/support",
|
c5169e0e
Renato De Donato
a new hope
|
14
|
"./data/var/data_priv",
|
74249687
Luigi Serra
Cross browser con...
|
15
16
|
"./core/init",
|
c5169e0e
Renato De Donato
a new hope
|
17
|
"./css/swap",
|
74249687
Luigi Serra
Cross browser con...
|
18
19
|
"./core/ready",
"./selector" // contains
|
c5169e0e
Renato De Donato
a new hope
|
20
21
|
], function( jQuery, pnum, access, rmargin, rnumnonpx, cssExpand, isHidden,
getStyles, curCSS, defaultDisplay, addGetHookIf, support, data_priv ) {
|
74249687
Luigi Serra
Cross browser con...
|
22
23
|
var
|
c5169e0e
Renato De Donato
a new hope
|
24
|
// Swappable if display is none or starts with table except "table", "table-cell", or "table-caption"
|
74249687
Luigi Serra
Cross browser con...
|
25
26
|
// See here for display values: https://developer.mozilla.org/en-US/docs/CSS/display
rdisplayswap = /^(none|table(?!-c[ea]).+)/,
|
c5169e0e
Renato De Donato
a new hope
|
27
28
|
rnumsplit = new RegExp( "^(" + pnum + ")(.*)$", "i" ),
rrelNum = new RegExp( "^([+-])=(" + pnum + ")", "i" ),
|
74249687
Luigi Serra
Cross browser con...
|
29
30
31
32
33
34
35
|
cssShow = { position: "absolute", visibility: "hidden", display: "block" },
cssNormalTransform = {
letterSpacing: "0",
fontWeight: "400"
},
|
c5169e0e
Renato De Donato
a new hope
|
36
|
cssPrefixes = [ "Webkit", "O", "Moz", "ms" ];
|
74249687
Luigi Serra
Cross browser con...
|
37
38
|
// Return a css property mapped to a potentially vendor prefixed property
|
c5169e0e
Renato De Donato
a new hope
|
39
|
function vendorPropName( style, name ) {
|
74249687
Luigi Serra
Cross browser con...
|
40
41
|
// Shortcut for names that are not vendor prefixed
|
c5169e0e
Renato De Donato
a new hope
|
42
|
if ( name in style ) {
|
74249687
Luigi Serra
Cross browser con...
|
43
44
45
46
|
return name;
}
// Check for vendor prefixed names
|
c5169e0e
Renato De Donato
a new hope
|
47
48
|
var capName = name[0].toUpperCase() + name.slice(1),
origName = name,
|
74249687
Luigi Serra
Cross browser con...
|
49
50
51
52
|
i = cssPrefixes.length;
while ( i-- ) {
name = cssPrefixes[ i ] + capName;
|
c5169e0e
Renato De Donato
a new hope
|
53
|
if ( name in style ) {
|
74249687
Luigi Serra
Cross browser con...
|
54
55
56
|
return name;
}
}
|
c5169e0e
Renato De Donato
a new hope
|
57
58
|
return origName;
|
74249687
Luigi Serra
Cross browser con...
|
59
60
61
|
}
function setPositiveNumber( elem, value, subtract ) {
|
c5169e0e
Renato De Donato
a new hope
|
62
|
var matches = rnumsplit.exec( value );
|
74249687
Luigi Serra
Cross browser con...
|
63
|
return matches ?
|
74249687
Luigi Serra
Cross browser con...
|
64
|
// Guard against undefined "subtract", e.g., when used as in cssHooks
|
c5169e0e
Renato De Donato
a new hope
|
65
|
Math.max( 0, matches[ 1 ] - ( subtract || 0 ) ) + ( matches[ 2 ] || "px" ) :
|
74249687
Luigi Serra
Cross browser con...
|
66
67
68
69
70
|
value;
}
function augmentWidthOrHeight( elem, name, extra, isBorderBox, styles ) {
var i = extra === ( isBorderBox ? "border" : "content" ) ?
|
74249687
Luigi Serra
Cross browser con...
|
71
72
|
// If we already have the right measurement, avoid augmentation
4 :
|
74249687
Luigi Serra
Cross browser con...
|
73
74
75
76
77
78
|
// Otherwise initialize for horizontal or vertical properties
name === "width" ? 1 : 0,
val = 0;
for ( ; i < 4; i += 2 ) {
|
74249687
Luigi Serra
Cross browser con...
|
79
80
81
82
83
84
|
// Both box models exclude margin, so add it if we want it
if ( extra === "margin" ) {
val += jQuery.css( elem, extra + cssExpand[ i ], true, styles );
}
if ( isBorderBox ) {
|
74249687
Luigi Serra
Cross browser con...
|
85
86
87
88
89
90
91
92
93
94
|
// border-box includes padding, so remove it if we want content
if ( extra === "content" ) {
val -= jQuery.css( elem, "padding" + cssExpand[ i ], true, styles );
}
// At this point, extra isn't border nor margin, so remove border
if ( extra !== "margin" ) {
val -= jQuery.css( elem, "border" + cssExpand[ i ] + "Width", true, styles );
}
} else {
|
74249687
Luigi Serra
Cross browser con...
|
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
// At this point, extra isn't content, so add padding
val += jQuery.css( elem, "padding" + cssExpand[ i ], true, styles );
// At this point, extra isn't content nor padding, so add border
if ( extra !== "padding" ) {
val += jQuery.css( elem, "border" + cssExpand[ i ] + "Width", true, styles );
}
}
}
return val;
}
function getWidthOrHeight( elem, name, extra ) {
// Start with offset property, which is equivalent to the border-box value
var valueIsBorderBox = true,
val = name === "width" ? elem.offsetWidth : elem.offsetHeight,
styles = getStyles( elem ),
isBorderBox = jQuery.css( elem, "boxSizing", false, styles ) === "border-box";
|
74249687
Luigi Serra
Cross browser con...
|
116
117
118
119
|
// Some non-html elements return undefined for offsetWidth, so check for null/undefined
// svg - https://bugzilla.mozilla.org/show_bug.cgi?id=649285
// MathML - https://bugzilla.mozilla.org/show_bug.cgi?id=491668
if ( val <= 0 || val == null ) {
|
74249687
Luigi Serra
Cross browser con...
|
120
121
122
123
124
125
126
|
// Fall back to computed then uncomputed css if necessary
val = curCSS( elem, name, styles );
if ( val < 0 || val == null ) {
val = elem.style[ name ];
}
// Computed unit is not pixels. Stop here and return.
|
c5169e0e
Renato De Donato
a new hope
|
127
|
if ( rnumnonpx.test(val) ) {
|
74249687
Luigi Serra
Cross browser con...
|
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
|
return val;
}
// Check for style in case a browser which returns unreliable values
// for getComputedStyle silently falls back to the reliable elem.style
valueIsBorderBox = isBorderBox &&
( support.boxSizingReliable() || val === elem.style[ name ] );
// Normalize "", auto, and prepare for extra
val = parseFloat( val ) || 0;
}
// Use the active box-sizing model to add/subtract irrelevant styles
return ( val +
augmentWidthOrHeight(
elem,
name,
extra || ( isBorderBox ? "border" : "content" ),
valueIsBorderBox,
styles
)
) + "px";
}
function showHide( elements, show ) {
var display, elem, hidden,
values = [],
index = 0,
length = elements.length;
for ( ; index < length; index++ ) {
elem = elements[ index ];
if ( !elem.style ) {
continue;
}
|
c5169e0e
Renato De Donato
a new hope
|
164
|
values[ index ] = data_priv.get( elem, "olddisplay" );
|
74249687
Luigi Serra
Cross browser con...
|
165
166
|
display = elem.style.display;
if ( show ) {
|
74249687
Luigi Serra
Cross browser con...
|
167
168
169
170
171
172
173
174
175
176
|
// Reset the inline display of this element to learn if it is
// being hidden by cascaded rules or not
if ( !values[ index ] && display === "none" ) {
elem.style.display = "";
}
// Set elements which have been overridden with display: none
// in a stylesheet to whatever the default browser style is
// for such an element
if ( elem.style.display === "" && isHidden( elem ) ) {
|
c5169e0e
Renato De Donato
a new hope
|
177
|
values[ index ] = data_priv.access( elem, "olddisplay", defaultDisplay(elem.nodeName) );
|
74249687
Luigi Serra
Cross browser con...
|
178
179
180
181
182
|
}
} else {
hidden = isHidden( elem );
if ( display !== "none" || !hidden ) {
|
c5169e0e
Renato De Donato
a new hope
|
183
|
data_priv.set( elem, "olddisplay", hidden ? display : jQuery.css( elem, "display" ) );
|
74249687
Luigi Serra
Cross browser con...
|
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
|
}
}
}
// Set the display of most of the elements in a second loop
// to avoid the constant reflow
for ( index = 0; index < length; index++ ) {
elem = elements[ index ];
if ( !elem.style ) {
continue;
}
if ( !show || elem.style.display === "none" || elem.style.display === "" ) {
elem.style.display = show ? values[ index ] || "" : "none";
}
}
return elements;
}
|
c5169e0e
Renato De Donato
a new hope
|
203
|
jQuery.extend({
|
74249687
Luigi Serra
Cross browser con...
|
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
|
// Add in style property hooks for overriding the default
// behavior of getting and setting a style property
cssHooks: {
opacity: {
get: function( elem, computed ) {
if ( computed ) {
// We should always get a number back from opacity
var ret = curCSS( elem, "opacity" );
return ret === "" ? "1" : ret;
}
}
}
},
// Don't automatically add "px" to these possibly-unitless properties
cssNumber: {
|
74249687
Luigi Serra
Cross browser con...
|
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
|
"columnCount": true,
"fillOpacity": true,
"flexGrow": true,
"flexShrink": true,
"fontWeight": true,
"lineHeight": true,
"opacity": true,
"order": true,
"orphans": true,
"widows": true,
"zIndex": true,
"zoom": true
},
// Add in properties whose names you wish to fix before
// setting or getting the value
cssProps: {
"float": "cssFloat"
},
// Get and set the style property on a DOM Node
style: function( elem, name, value, extra ) {
// Don't set styles on text and comment nodes
if ( !elem || elem.nodeType === 3 || elem.nodeType === 8 || !elem.style ) {
return;
}
// Make sure that we're working with the right name
var ret, type, hooks,
origName = jQuery.camelCase( name ),
style = elem.style;
|
c5169e0e
Renato De Donato
a new hope
|
255
|
name = jQuery.cssProps[ origName ] || ( jQuery.cssProps[ origName ] = vendorPropName( style, origName ) );
|
74249687
Luigi Serra
Cross browser con...
|
256
257
258
259
260
261
262
263
264
|
// Gets hook for the prefixed version, then unprefixed version
hooks = jQuery.cssHooks[ name ] || jQuery.cssHooks[ origName ];
// Check if we're setting a value
if ( value !== undefined ) {
type = typeof value;
// Convert "+=" or "-=" to relative numbers (#7345)
|
c5169e0e
Renato De Donato
a new hope
|
265
266
|
if ( type === "string" && (ret = rrelNum.exec( value )) ) {
value = ( ret[1] + 1 ) * ret[2] + parseFloat( jQuery.css( elem, name ) );
|
74249687
Luigi Serra
Cross browser con...
|
267
268
269
270
271
272
273
274
275
|
// Fixes bug #9237
type = "number";
}
// Make sure that null and NaN values aren't set (#7116)
if ( value == null || value !== value ) {
return;
}
|
c5169e0e
Renato De Donato
a new hope
|
276
277
278
|
// If a number, add 'px' to the (except for certain CSS properties)
if ( type === "number" && !jQuery.cssNumber[ origName ] ) {
value += "px";
|
74249687
Luigi Serra
Cross browser con...
|
279
280
281
282
283
284
285
286
287
|
}
// Support: IE9-11+
// background-* props affect original clone's values
if ( !support.clearCloneStyle && value === "" && name.indexOf( "background" ) === 0 ) {
style[ name ] = "inherit";
}
// If a hook was provided, use that value, otherwise just set the specified value
|
c5169e0e
Renato De Donato
a new hope
|
288
|
if ( !hooks || !("set" in hooks) || (value = hooks.set( elem, value, extra )) !== undefined ) {
|
74249687
Luigi Serra
Cross browser con...
|
289
290
291
292
|
style[ name ] = value;
}
} else {
|
74249687
Luigi Serra
Cross browser con...
|
293
|
// If a hook was provided get the non-computed value from there
|
c5169e0e
Renato De Donato
a new hope
|
294
|
if ( hooks && "get" in hooks && (ret = hooks.get( elem, false, extra )) !== undefined ) {
|
74249687
Luigi Serra
Cross browser con...
|
295
296
297
298
299
300
301
302
303
304
305
306
307
|
return ret;
}
// Otherwise just get the value from the style object
return style[ name ];
}
},
css: function( elem, name, extra, styles ) {
var val, num, hooks,
origName = jQuery.camelCase( name );
// Make sure that we're working with the right name
|
c5169e0e
Renato De Donato
a new hope
|
308
|
name = jQuery.cssProps[ origName ] || ( jQuery.cssProps[ origName ] = vendorPropName( elem.style, origName ) );
|
74249687
Luigi Serra
Cross browser con...
|
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
|
// Try prefixed name followed by the unprefixed name
hooks = jQuery.cssHooks[ name ] || jQuery.cssHooks[ origName ];
// If a hook was provided get the computed value from there
if ( hooks && "get" in hooks ) {
val = hooks.get( elem, true, extra );
}
// Otherwise, if a way to get the computed value exists, use that
if ( val === undefined ) {
val = curCSS( elem, name, styles );
}
// Convert "normal" to computed value
if ( val === "normal" && name in cssNormalTransform ) {
val = cssNormalTransform[ name ];
}
// Make numeric if forced or a qualifier was provided and val looks numeric
if ( extra === "" || extra ) {
num = parseFloat( val );
|
c5169e0e
Renato De Donato
a new hope
|
331
|
return extra === true || jQuery.isNumeric( num ) ? num || 0 : val;
|
74249687
Luigi Serra
Cross browser con...
|
332
333
334
|
}
return val;
}
|
c5169e0e
Renato De Donato
a new hope
|
335
|
});
|
74249687
Luigi Serra
Cross browser con...
|
336
|
|
c5169e0e
Renato De Donato
a new hope
|
337
|
jQuery.each([ "height", "width" ], function( i, name ) {
|
74249687
Luigi Serra
Cross browser con...
|
338
339
340
341
342
343
|
jQuery.cssHooks[ name ] = {
get: function( elem, computed, extra ) {
if ( computed ) {
// Certain elements can have dimension info if we invisibly show them
// but it must have a current display style that would benefit
|
c5169e0e
Renato De Donato
a new hope
|
344
345
346
347
348
|
return rdisplayswap.test( jQuery.css( elem, "display" ) ) && elem.offsetWidth === 0 ?
jQuery.swap( elem, cssShow, function() {
return getWidthOrHeight( elem, name, extra );
}) :
getWidthOrHeight( elem, name, extra );
|
74249687
Luigi Serra
Cross browser con...
|
349
350
351
352
|
}
},
set: function( elem, value, extra ) {
|
c5169e0e
Renato De Donato
a new hope
|
353
354
355
|
var styles = extra && getStyles( elem );
return setPositiveNumber( elem, value, extra ?
augmentWidthOrHeight(
|
74249687
Luigi Serra
Cross browser con...
|
356
357
358
359
360
|
elem,
name,
extra,
jQuery.css( elem, "boxSizing", false, styles ) === "border-box",
styles
|
c5169e0e
Renato De Donato
a new hope
|
361
362
|
) : 0
);
|
74249687
Luigi Serra
Cross browser con...
|
363
364
|
}
};
|
c5169e0e
Renato De Donato
a new hope
|
365
|
});
|
74249687
Luigi Serra
Cross browser con...
|
366
367
368
369
370
|
// Support: Android 2.3
jQuery.cssHooks.marginRight = addGetHookIf( support.reliableMarginRight,
function( elem, computed ) {
if ( computed ) {
|
c5169e0e
Renato De Donato
a new hope
|
371
|
return jQuery.swap( elem, { "display": "inline-block" },
|
74249687
Luigi Serra
Cross browser con...
|
372
373
374
375
376
377
|
curCSS, [ elem, "marginRight" ] );
}
}
);
// These hooks are used by animate to expand properties
|
c5169e0e
Renato De Donato
a new hope
|
378
|
jQuery.each({
|
74249687
Luigi Serra
Cross browser con...
|
379
380
381
382
383
384
385
386
387
388
|
margin: "",
padding: "",
border: "Width"
}, function( prefix, suffix ) {
jQuery.cssHooks[ prefix + suffix ] = {
expand: function( value ) {
var i = 0,
expanded = {},
// Assumes a single number if not a string
|
c5169e0e
Renato De Donato
a new hope
|
389
|
parts = typeof value === "string" ? value.split(" ") : [ value ];
|
74249687
Luigi Serra
Cross browser con...
|
390
391
392
393
394
395
396
397
398
399
400
401
402
|
for ( ; i < 4; i++ ) {
expanded[ prefix + cssExpand[ i ] + suffix ] =
parts[ i ] || parts[ i - 2 ] || parts[ 0 ];
}
return expanded;
}
};
if ( !rmargin.test( prefix ) ) {
jQuery.cssHooks[ prefix + suffix ].set = setPositiveNumber;
}
|
c5169e0e
Renato De Donato
a new hope
|
403
|
});
|
74249687
Luigi Serra
Cross browser con...
|
404
|
|
c5169e0e
Renato De Donato
a new hope
|
405
|
jQuery.fn.extend({
|
74249687
Luigi Serra
Cross browser con...
|
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
|
css: function( name, value ) {
return access( this, function( elem, name, value ) {
var styles, len,
map = {},
i = 0;
if ( jQuery.isArray( name ) ) {
styles = getStyles( elem );
len = name.length;
for ( ; i < len; i++ ) {
map[ name[ i ] ] = jQuery.css( elem, name[ i ], false, styles );
}
return map;
}
return value !== undefined ?
jQuery.style( elem, name, value ) :
jQuery.css( elem, name );
}, name, value, arguments.length > 1 );
},
show: function() {
return showHide( this, true );
},
hide: function() {
return showHide( this );
},
toggle: function( state ) {
if ( typeof state === "boolean" ) {
return state ? this.show() : this.hide();
}
|
c5169e0e
Renato De Donato
a new hope
|
439
|
return this.each(function() {
|
74249687
Luigi Serra
Cross browser con...
|
440
441
442
443
444
|
if ( isHidden( this ) ) {
jQuery( this ).show();
} else {
jQuery( this ).hide();
}
|
c5169e0e
Renato De Donato
a new hope
|
445
|
});
|
74249687
Luigi Serra
Cross browser con...
|
446
|
}
|
c5169e0e
Renato De Donato
a new hope
|
447
|
});
|
74249687
Luigi Serra
Cross browser con...
|
448
449
|
return jQuery;
|
c5169e0e
Renato De Donato
a new hope
|
450
|
});
|