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