scratch – Diff between revs 58 and 125

Subversion Repositories:
Rev:
Show entire fileIgnore whitespace
Rev 58 Rev 125
Line 1... Line 1...
1 define( [ 1 define([
2 "./core", 2 "./core",
3 "./var/pnum", 3 "./var/pnum",
4 "./core/access", 4 "./core/access",
5 "./css/var/rmargin", 5 "./css/var/rmargin",
6 "./var/document", -  
7 "./var/rcssNum", -  
8 "./css/var/rnumnonpx", 6 "./css/var/rnumnonpx",
9 "./css/var/cssExpand", 7 "./css/var/cssExpand",
-   8 "./css/var/isHidden",
10 "./css/var/getStyles", 9 "./css/var/getStyles",
11 "./css/var/swap", -  
12 "./css/curCSS", 10 "./css/curCSS",
13 "./css/adjustCSS", 11 "./css/defaultDisplay",
14 "./css/addGetHookIf", 12 "./css/addGetHookIf",
15 "./css/support", 13 "./css/support",
-   14 "./data/var/data_priv",
Line 16... Line 15...
16   15  
-   16 "./core/init",
17 "./core/init", 17 "./css/swap",
18 "./core/ready", 18 "./core/ready",
19 "./selector" // contains 19 "./selector" // contains
20 ], function( jQuery, pnum, access, rmargin, document, rcssNum, rnumnonpx, cssExpand, 20 ], function( jQuery, pnum, access, rmargin, rnumnonpx, cssExpand, isHidden,
21 getStyles, swap, curCSS, adjustCSS, addGetHookIf, support ) { -  
22   -  
Line 23... Line 21...
23 "use strict"; 21 getStyles, curCSS, defaultDisplay, addGetHookIf, support, data_priv ) {
24   -  
25 var 22  
26   -  
27 // Swappable if display is none or starts with table 23 var
28 // except "table", "table-cell", or "table-caption" 24 // Swappable if display is none or starts with table except "table", "table-cell", or "table-caption"
-   25 // See here for display values: https://developer.mozilla.org/en-US/docs/CSS/display
-   26 rdisplayswap = /^(none|table(?!-c[ea]).+)/,
-   27 rnumsplit = new RegExp( "^(" + pnum + ")(.*)$", "i" ),
29 // See here for display values: https://developer.mozilla.org/en-US/docs/CSS/display 28 rrelNum = new RegExp( "^([+-])=(" + pnum + ")", "i" ),
30 rdisplayswap = /^(none|table(?!-c[ea]).+)/, 29  
31 cssShow = { position: "absolute", visibility: "hidden", display: "block" }, 30 cssShow = { position: "absolute", visibility: "hidden", display: "block" },
32 cssNormalTransform = { 31 cssNormalTransform = {
33 letterSpacing: "0", 32 letterSpacing: "0",
Line 34... Line 33...
34 fontWeight: "400" 33 fontWeight: "400"
35 }, -  
Line 36... Line 34...
36   34 },
37 cssPrefixes = [ "Webkit", "Moz", "ms" ], 35  
Line 38... Line 36...
38 emptyStyle = document.createElement( "div" ).style; 36 cssPrefixes = [ "Webkit", "O", "Moz", "ms" ];
39   37  
40 // Return a css property mapped to a potentially vendor prefixed property 38 // Return a css property mapped to a potentially vendor prefixed property
41 function vendorPropName( name ) { 39 function vendorPropName( style, name ) {
Line 42... Line 40...
42   40  
43 // Shortcut for names that are not vendor prefixed 41 // Shortcut for names that are not vendor prefixed
-   42 if ( name in style ) {
44 if ( name in emptyStyle ) { 43 return name;
Line 45... Line 44...
45 return name; 44 }
46 } 45  
47   46 // Check for vendor prefixed names
48 // Check for vendor prefixed names 47 var capName = name[0].toUpperCase() + name.slice(1),
49 var capName = name[ 0 ].toUpperCase() + name.slice( 1 ), 48 origName = name,
50 i = cssPrefixes.length; 49 i = cssPrefixes.length;
-   50  
-   51 while ( i-- ) {
51   52 name = cssPrefixes[ i ] + capName;
Line 52... Line 53...
52 while ( i-- ) { 53 if ( name in style ) {
53 name = cssPrefixes[ i ] + capName; -  
54 if ( name in emptyStyle ) { -  
55 return name; -  
56 } 54 return name;
57 } 55 }
58 } -  
59   56 }
60 function setPositiveNumber( elem, value, subtract ) { 57  
61   58 return origName;
62 // Any relative (+/-) values have already been 59 }
Line 63... Line 60...
63 // normalized at this point 60  
-   61 function setPositiveNumber( elem, value, subtract ) {
-   62 var matches = rnumsplit.exec( value );
64 var matches = rcssNum.exec( value ); 63 return matches ?
-   64 // Guard against undefined "subtract", e.g., when used as in cssHooks
65 return matches ? 65 Math.max( 0, matches[ 1 ] - ( subtract || 0 ) ) + ( matches[ 2 ] || "px" ) :
Line 66... Line -...
66   -  
67 // Guard against undefined "subtract", e.g., when used as in cssHooks -  
68 Math.max( 0, matches[ 2 ] - ( subtract || 0 ) ) + ( matches[ 3 ] || "px" ) : 66 value;
69 value; -  
70 } -  
71   -  
72 function augmentWidthOrHeight( elem, name, extra, isBorderBox, styles ) { -  
73 var i, -  
Line 74... Line 67...
74 val = 0; 67 }
75   -  
76 // If we already have the right measurement, avoid augmentation 68  
77 if ( extra === ( isBorderBox ? "border" : "content" ) ) { 69 function augmentWidthOrHeight( elem, name, extra, isBorderBox, styles ) {
78 i = 4; 70 var i = extra === ( isBorderBox ? "border" : "content" ) ?
79   71 // If we already have the right measurement, avoid augmentation
Line 80... Line 72...
80 // Otherwise initialize for horizontal or vertical properties 72 4 :
81 } else { -  
82 i = name === "width" ? 1 : 0; 73 // Otherwise initialize for horizontal or vertical properties
83 } 74 name === "width" ? 1 : 0,
84   75  
85 for ( ; i < 4; i += 2 ) { 76 val = 0;
Line 86... Line 77...
86   77  
87 // Both box models exclude margin, so add it if we want it 78 for ( ; i < 4; i += 2 ) {
88 if ( extra === "margin" ) { 79 // Both box models exclude margin, so add it if we want it
89 val += jQuery.css( elem, extra + cssExpand[ i ], true, styles ); 80 if ( extra === "margin" ) {
90 } 81 val += jQuery.css( elem, extra + cssExpand[ i ], true, styles );
91   -  
92 if ( isBorderBox ) { 82 }
93   83  
Line 94... Line 84...
94 // border-box includes padding, so remove it if we want content 84 if ( isBorderBox ) {
95 if ( extra === "content" ) { 85 // border-box includes padding, so remove it if we want content
Line 116... Line 106...
116 } 106 }
Line 117... Line 107...
117   107  
Line 118... Line 108...
118 function getWidthOrHeight( elem, name, extra ) { 108 function getWidthOrHeight( elem, name, extra ) {
119   -  
120 // Start with offset property, which is equivalent to the border-box value 109  
-   110 // Start with offset property, which is equivalent to the border-box value
121 var val, 111 var valueIsBorderBox = true,
122 valueIsBorderBox = true, 112 val = name === "width" ? elem.offsetWidth : elem.offsetHeight,
Line 123... Line -...
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 ]; 113 styles = getStyles( elem ),
131 } 114 isBorderBox = jQuery.css( elem, "boxSizing", false, styles ) === "border-box";
132   115  
133 // Some non-html elements return undefined for offsetWidth, so check for null/undefined 116 // 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 117 // svg - https://bugzilla.mozilla.org/show_bug.cgi?id=649285
136 if ( val <= 0 || val == null ) { 118 // MathML - https://bugzilla.mozilla.org/show_bug.cgi?id=491668
137   119 if ( val <= 0 || val == null ) {
138 // Fall back to computed then uncomputed css if necessary 120 // Fall back to computed then uncomputed css if necessary
139 val = curCSS( elem, name, styles ); 121 val = curCSS( elem, name, styles );
Line 140... Line 122...
140 if ( val < 0 || val == null ) { 122 if ( val < 0 || val == null ) {
141 val = elem.style[ name ]; 123 val = elem.style[ name ];
142 } 124 }
143   125  
Line 144... Line 126...
144 // Computed unit is not pixels. Stop here and return. 126 // Computed unit is not pixels. Stop here and return.
145 if ( rnumnonpx.test( val ) ) { 127 if ( rnumnonpx.test(val) ) {
Line 165... Line 147...
165 styles 147 styles
166 ) 148 )
167 ) + "px"; 149 ) + "px";
168 } 150 }
Line -... Line 151...
-   151  
-   152 function showHide( elements, show ) {
-   153 var display, elem, hidden,
-   154 values = [],
-   155 index = 0,
-   156 length = elements.length;
-   157  
-   158 for ( ; index < length; index++ ) {
-   159 elem = elements[ index ];
-   160 if ( !elem.style ) {
-   161 continue;
-   162 }
-   163  
-   164 values[ index ] = data_priv.get( elem, "olddisplay" );
-   165 display = elem.style.display;
-   166 if ( show ) {
-   167 // Reset the inline display of this element to learn if it is
-   168 // being hidden by cascaded rules or not
-   169 if ( !values[ index ] && display === "none" ) {
-   170 elem.style.display = "";
-   171 }
-   172  
-   173 // Set elements which have been overridden with display: none
-   174 // in a stylesheet to whatever the default browser style is
-   175 // for such an element
-   176 if ( elem.style.display === "" && isHidden( elem ) ) {
-   177 values[ index ] = data_priv.access( elem, "olddisplay", defaultDisplay(elem.nodeName) );
-   178 }
-   179 } else {
-   180 hidden = isHidden( elem );
-   181  
-   182 if ( display !== "none" || !hidden ) {
-   183 data_priv.set( elem, "olddisplay", hidden ? display : jQuery.css( elem, "display" ) );
-   184 }
-   185 }
-   186 }
-   187  
-   188 // Set the display of most of the elements in a second loop
-   189 // to avoid the constant reflow
-   190 for ( index = 0; index < length; index++ ) {
-   191 elem = elements[ index ];
-   192 if ( !elem.style ) {
-   193 continue;
-   194 }
-   195 if ( !show || elem.style.display === "none" || elem.style.display === "" ) {
-   196 elem.style.display = show ? values[ index ] || "" : "none";
-   197 }
-   198 }
-   199  
-   200 return elements;
-   201 }
169   202  
Line 170... Line 203...
170 jQuery.extend( { 203 jQuery.extend({
171   204  
172 // Add in style property hooks for overriding the default 205 // Add in style property hooks for overriding the default
173 // behavior of getting and setting a style property 206 // behavior of getting and setting a style property
Line 184... Line 217...
184 } 217 }
185 }, 218 },
Line 186... Line 219...
186   219  
187 // Don't automatically add "px" to these possibly-unitless properties 220 // Don't automatically add "px" to these possibly-unitless properties
188 cssNumber: { -  
189 "animationIterationCount": true, 221 cssNumber: {
190 "columnCount": true, 222 "columnCount": true,
191 "fillOpacity": true, 223 "fillOpacity": true,
192 "flexGrow": true, 224 "flexGrow": true,
193 "flexShrink": true, 225 "flexShrink": true,
Line 218... Line 250...
218 // Make sure that we're working with the right name 250 // Make sure that we're working with the right name
219 var ret, type, hooks, 251 var ret, type, hooks,
220 origName = jQuery.camelCase( name ), 252 origName = jQuery.camelCase( name ),
221 style = elem.style; 253 style = elem.style;
Line 222... Line -...
222   -  
223 name = jQuery.cssProps[ origName ] || 254  
Line 224... Line 255...
224 ( jQuery.cssProps[ origName ] = vendorPropName( origName ) || origName ); 255 name = jQuery.cssProps[ origName ] || ( jQuery.cssProps[ origName ] = vendorPropName( style, origName ) );
225   256  
Line 226... Line 257...
226 // Gets hook for the prefixed version, then unprefixed version 257 // Gets hook for the prefixed version, then unprefixed version
227 hooks = jQuery.cssHooks[ name ] || jQuery.cssHooks[ origName ]; 258 hooks = jQuery.cssHooks[ name ] || jQuery.cssHooks[ origName ];
228   259  
Line 229... Line 260...
229 // Check if we're setting a value 260 // Check if we're setting a value
230 if ( value !== undefined ) { 261 if ( value !== undefined ) {
231 type = typeof value; 262 type = typeof value;
232   -  
233 // Convert "+=" or "-=" to relative numbers (#7345) 263  
234 if ( type === "string" && ( ret = rcssNum.exec( value ) ) && ret[ 1 ] ) { 264 // Convert "+=" or "-=" to relative numbers (#7345)
235 value = adjustCSS( elem, name, ret ); 265 if ( type === "string" && (ret = rrelNum.exec( value )) ) {
Line 236... Line 266...
236   266 value = ( ret[1] + 1 ) * ret[2] + parseFloat( jQuery.css( elem, name ) );
237 // Fixes bug #9237 267 // Fixes bug #9237
238 type = "number"; 268 type = "number";
239 } 269 }
Line 240... Line 270...
240   270  
241 // Make sure that null and NaN values aren't set (#7116) 271 // Make sure that null and NaN values aren't set (#7116)
242 if ( value == null || value !== value ) { 272 if ( value == null || value !== value ) {
243 return; 273 return;
Line -... Line 274...
-   274 }
244 } 275  
245   276 // If a number, add 'px' to the (except for certain CSS properties)
246 // If a number was passed in, add the unit (except for certain CSS properties) 277 if ( type === "number" && !jQuery.cssNumber[ origName ] ) {
247 if ( type === "number" ) { 278 value += "px";
Line 248... Line 279...
248 value += ret && ret[ 3 ] || ( jQuery.cssNumber[ origName ] ? "" : "px" ); 279 }
249 } -  
250   280  
251 // background-* props affect original clone's values -  
252 if ( !support.clearCloneStyle && value === "" && name.indexOf( "background" ) === 0 ) { 281 // Support: IE9-11+
253 style[ name ] = "inherit"; 282 // background-* props affect original clone's values
Line 254... Line 283...
254 } 283 if ( !support.clearCloneStyle && value === "" && name.indexOf( "background" ) === 0 ) {
255   -  
256 // If a hook was provided, use that value, otherwise just set the specified value 284 style[ name ] = "inherit";
257 if ( !hooks || !( "set" in hooks ) || -  
258 ( value = hooks.set( elem, value, extra ) ) !== undefined ) { 285 }
259   -  
260 style[ name ] = value; 286  
261 } 287 // If a hook was provided, use that value, otherwise just set the specified value
Line 262... Line 288...
262   288 if ( !hooks || !("set" in hooks) || (value = hooks.set( elem, value, extra )) !== undefined ) {
263 } else { 289 style[ name ] = value;
Line 277... Line 303...
277 css: function( elem, name, extra, styles ) { 303 css: function( elem, name, extra, styles ) {
278 var val, num, hooks, 304 var val, num, hooks,
279 origName = jQuery.camelCase( name ); 305 origName = jQuery.camelCase( name );
Line 280... Line 306...
280   306  
281 // Make sure that we're working with the right name -  
282 name = jQuery.cssProps[ origName ] || 307 // Make sure that we're working with the right name
Line 283... Line 308...
283 ( jQuery.cssProps[ origName ] = vendorPropName( origName ) || origName ); 308 name = jQuery.cssProps[ origName ] || ( jQuery.cssProps[ origName ] = vendorPropName( elem.style, origName ) );
284   309  
Line 285... Line 310...
285 // Try prefixed name followed by the unprefixed name 310 // Try prefixed name followed by the unprefixed name
Line 301... Line 326...
301 } 326 }
Line 302... Line 327...
302   327  
303 // Make numeric if forced or a qualifier was provided and val looks numeric 328 // Make numeric if forced or a qualifier was provided and val looks numeric
304 if ( extra === "" || extra ) { 329 if ( extra === "" || extra ) {
305 num = parseFloat( val ); 330 num = parseFloat( val );
306 return extra === true || isFinite( num ) ? num || 0 : val; 331 return extra === true || jQuery.isNumeric( num ) ? num || 0 : val;
307 } 332 }
308 return val; 333 return val;
309 } 334 }
Line 310... Line 335...
310 } ); 335 });
311   336  
312 jQuery.each( [ "height", "width" ], function( i, name ) { 337 jQuery.each([ "height", "width" ], function( i, name ) {
313 jQuery.cssHooks[ name ] = { 338 jQuery.cssHooks[ name ] = {
Line 314... Line 339...
314 get: function( elem, computed, extra ) { 339 get: function( elem, computed, extra ) {
315 if ( computed ) { 340 if ( computed ) {
316   341  
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 342 // Certain elements can have dimension info if we invisibly show them
326 // in IE throws an error. 343 // but it must have a current display style that would benefit
327 ( !elem.getClientRects().length || !elem.getBoundingClientRect().width ) ? 344 return rdisplayswap.test( jQuery.css( elem, "display" ) ) && elem.offsetWidth === 0 ?
328 swap( elem, cssShow, function() { 345 jQuery.swap( elem, cssShow, function() {
329 return getWidthOrHeight( elem, name, extra ); 346 return getWidthOrHeight( elem, name, extra );
330 } ) : 347 }) :
Line 331... Line 348...
331 getWidthOrHeight( elem, name, extra ); 348 getWidthOrHeight( elem, name, extra );
332 } -  
333 }, 349 }
-   350 },
334   351  
335 set: function( elem, value, extra ) { 352 set: function( elem, value, extra ) {
336 var matches, 353 var styles = extra && getStyles( elem );
337 styles = extra && getStyles( elem ), 354 return setPositiveNumber( elem, value, extra ?
338 subtract = extra && augmentWidthOrHeight( 355 augmentWidthOrHeight(
339 elem, 356 elem,
340 name, 357 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" ) { 358 extra,
349   -  
350 elem.style[ name ] = value; -  
351 value = jQuery.css( elem, name ); 359 jQuery.css( elem, "boxSizing", false, styles ) === "border-box",
352 } 360 styles
353   361 ) : 0
Line -... Line 362...
-   362 );
354 return setPositiveNumber( elem, value, subtract ); 363 }
355 } 364 };
356 }; 365 });
357 } ); 366  
358   -  
359 jQuery.cssHooks.marginLeft = addGetHookIf( support.reliableMarginLeft, 367 // Support: Android 2.3
360 function( elem, computed ) { -  
361 if ( computed ) { -  
362 return ( parseFloat( curCSS( elem, "marginLeft" ) ) || -  
363 elem.getBoundingClientRect().left - 368 jQuery.cssHooks.marginRight = addGetHookIf( support.reliableMarginRight,
364 swap( elem, { marginLeft: 0 }, function() { 369 function( elem, computed ) {
365 return elem.getBoundingClientRect().left; 370 if ( computed ) {
Line 366... Line 371...
366 } ) 371 return jQuery.swap( elem, { "display": "inline-block" },
367 ) + "px"; 372 curCSS, [ elem, "marginRight" ] );
368 } 373 }
369 } 374 }
370 ); 375 );
371   376  
372 // These hooks are used by animate to expand properties 377 // These hooks are used by animate to expand properties
373 jQuery.each( { 378 jQuery.each({
374 margin: "", 379 margin: "",
375 padding: "", 380 padding: "",
Line 376... Line 381...
376 border: "Width" 381 border: "Width"
377 }, function( prefix, suffix ) { 382 }, function( prefix, suffix ) {
Line 378... Line 383...
378 jQuery.cssHooks[ prefix + suffix ] = { 383 jQuery.cssHooks[ prefix + suffix ] = {
379 expand: function( value ) { 384 expand: function( value ) {
380 var i = 0, 385 var i = 0,
381 expanded = {}, 386 expanded = {},
Line 393... Line 398...
393 }; 398 };
Line 394... Line 399...
394   399  
395 if ( !rmargin.test( prefix ) ) { 400 if ( !rmargin.test( prefix ) ) {
396 jQuery.cssHooks[ prefix + suffix ].set = setPositiveNumber; 401 jQuery.cssHooks[ prefix + suffix ].set = setPositiveNumber;
397 } 402 }
Line 398... Line 403...
398 } ); 403 });
399   404  
400 jQuery.fn.extend( { 405 jQuery.fn.extend({
401 css: function( name, value ) { 406 css: function( name, value ) {
402 return access( this, function( elem, name, value ) { 407 return access( this, function( elem, name, value ) {
403 var styles, len, 408 var styles, len,
Line 417... Line 422...
417   422  
418 return value !== undefined ? 423 return value !== undefined ?
419 jQuery.style( elem, name, value ) : 424 jQuery.style( elem, name, value ) :
420 jQuery.css( elem, name ); 425 jQuery.css( elem, name );
-   426 }, name, value, arguments.length > 1 );
-   427 },
-   428 show: function() {
-   429 return showHide( this, true );
-   430 },
-   431 hide: function() {
-   432 return showHide( this );
-   433 },
-   434 toggle: function( state ) {
-   435 if ( typeof state === "boolean" ) {
-   436 return state ? this.show() : this.hide();
-   437 }
-   438  
-   439 return this.each(function() {
-   440 if ( isHidden( this ) ) {
-   441 jQuery( this ).show();
-   442 } else {
-   443 jQuery( this ).hide();
-   444 }
421 }, name, value, arguments.length > 1 ); 445 });
422 } 446 }
Line 423... Line 447...
423 } ); 447 });
424   448