Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Fix #10413, #10679. Fix box-sizing:border-box and add css vendor pref…
…ix support.
- Loading branch information
1 parent
77536f5
commit 5376a80
Showing
3 changed files
with
129 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -13,12 +13,35 @@ var ralpha = /alpha\([^)]*\)/i, | ||
|
||
// order is important! | ||
cssExpand = [ "Top", "Right", "Bottom", "Left" ], | ||
cssPrefixes = [ "O", "Webkit", "Moz", "ms" ], | ||
|
||
curCSS, | ||
|
||
getComputedStyle, | ||
currentStyle; | ||
|
||
// return a css property mapped to a potentially vendor prefixed property | ||
function vendorPropName( style, name ) { | ||
|
||
// shortcut for names that are not vendor prefixed | ||
if ( name in style ) { | ||
return name; | ||
} | ||
|
||
// check for vendor prefixed names | ||
var capName = name.charAt(0).toUpperCase() + name.slice(1), | ||
origName = name, | ||
i = cssPrefixes.length; | ||
|
||
while ( i-- ) { | ||
name = cssPrefixes[ i ] + capName; | ||
if ( name in style ) { | ||
return name; | ||
} | ||
} | ||
|
||
return origName; | ||
} | ||
|
||
jQuery.fn.css = function( name, value ) { | ||
return jQuery.access( this, function( elem, name, value ) { | ||
return value !== undefined ? | ||
@@ -72,10 +95,15 @@ jQuery.extend({ | ||
} | ||
|
||
// Make sure that we're working with the right name | ||
var ret, type, origName = jQuery.camelCase( name ), | ||
style = elem.style, hooks = jQuery.cssHooks[ origName ]; | ||
var ret, type, hooks, | ||
origName = jQuery.camelCase( name ), | ||
style = elem.style; | ||
|
||
name = jQuery.cssProps[ origName ] || origName; | ||
name = jQuery.cssProps[ origName ] || ( jQuery.cssProps[ origName ] = vendorPropName( style, origName ) ); | ||
|
||
// gets hook for the prefixed version | ||
// followed by the unprefixed version | ||
hooks = jQuery.cssHooks[ name ] || jQuery.cssHooks[ origName ]; | ||
|
||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
rwaldron
Member
|
||
// Check if we're setting a value | ||
if ( value !== undefined ) { | ||
@@ -119,12 +147,15 @@ jQuery.extend({ | ||
}, | ||
|
||
css: function( elem, name, extra ) { | ||
var ret, hooks; | ||
var ret, hooks, | ||
origName = jQuery.camelCase( name ); | ||
|
||
// Make sure that we're working with the right name | ||
name = jQuery.camelCase( name ); | ||
hooks = jQuery.cssHooks[ name ]; | ||
name = jQuery.cssProps[ name ] || name; | ||
name = jQuery.cssProps[ origName ] || ( jQuery.cssProps[ origName ] = vendorPropName( elem.style, origName ) ); | ||
|
||
// gets hook for the prefixed version | ||
// followed by the unprefixed version | ||
hooks = jQuery.cssHooks[ name ] || jQuery.cssHooks[ origName ]; | ||
|
||
// cssFloat needs a special treatment | ||
if ( name === "cssFloat" ) { | ||
@@ -244,9 +275,29 @@ function getWidthOrHeight( elem, name, extra ) { | ||
// Start with offset property | ||
var val = name === "width" ? elem.offsetWidth : elem.offsetHeight, | ||
i = name === "width" ? 1 : 0, | ||
len = 4; | ||
len = 4, | ||
usedOffset = true; | ||
|
||
if ( val <= 0 ) { | ||
usedOffset = false; | ||
|
||
// Fall back to computed then uncomputed css if necessary | ||
val = curCSS( elem, name ); | ||
if ( val < 0 || val == null ) { | ||
val = elem.style[ name ]; | ||
} | ||
|
||
// Computed unit is not pixels. Stop here and return. | ||
if ( rnumnonpx.test(val) ) { | ||
return val; | ||
} | ||
|
||
// Normalize "", auto, and prepare for extra | ||
val = parseFloat( val ) || 0; | ||
} | ||
|
||
if ( val > 0 ) { | ||
//if we're using border-box, the css width/height value behaves like the offsetWidth/Height property! | ||
if ( usedOffset || ( jQuery.support.boxSizing && jQuery.css( elem, "boxSizing" ) === "border-box" ) ) { | ||
if ( extra !== "border" ) { | ||
for ( ; i < len; i += 2 ) { | ||
if ( !extra ) { | ||
@@ -259,33 +310,17 @@ function getWidthOrHeight( elem, name, extra ) { | ||
} | ||
} | ||
} | ||
|
||
return val + "px"; | ||
} | ||
|
||
// Fall back to computed then uncomputed css if necessary | ||
val = curCSS( elem, name ); | ||
if ( val < 0 || val == null ) { | ||
val = elem.style[ name ]; | ||
} | ||
|
||
// Computed unit is not pixels. Stop here and return. | ||
if ( rnumnonpx.test(val) ) { | ||
return val; | ||
} | ||
|
||
// Normalize "", auto, and prepare for extra | ||
val = parseFloat( val ) || 0; | ||
|
||
// Add padding, border, margin | ||
if ( extra ) { | ||
for ( ; i < len; i += 2 ) { | ||
val += parseFloat( jQuery.css( elem, "padding" + cssExpand[ i ] ) ) || 0; | ||
if ( extra !== "padding" ) { | ||
val += parseFloat( jQuery.css( elem, "border" + cssExpand[ i ] + "Width" ) ) || 0; | ||
} | ||
if ( extra === "margin" ) { | ||
val += parseFloat( jQuery.css( elem, extra + cssExpand[ i ]) ) || 0; | ||
} else { | ||
// Add padding, border, margin | ||
if ( extra ) { | ||
for ( ; i < len; i += 2 ) { | ||
val += parseFloat( jQuery.css( elem, "padding" + cssExpand[ i ] ) ) || 0; | ||
if ( extra !== "padding" ) { | ||
val += parseFloat( jQuery.css( elem, "border" + cssExpand[ i ] + "Width" ) ) || 0; | ||
} | ||
if ( extra === "margin" ) { | ||
val += parseFloat( jQuery.css( elem, extra + cssExpand[ i ] ) ) || 0; | ||
} | ||
} | ||
} | ||
} | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Hmmm, probably a better way to do it besides cssHooks, but this means that the animate side of the equation needs some re-factoring....