Skip to content

Instantly share code, notes, and snippets.

@gnarf
Created September 15, 2011 23:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gnarf/1220819 to your computer and use it in GitHub Desktop.
Save gnarf/1220819 to your computer and use it in GitHub Desktop.
var rwhitespace = /\s+/;
// These hooks are used by animate to expand properties
$.each({
margin: "margin*",
padding: "padding*",
borderWidth: "border*Width"
}, function( property, expandTemplate ) {
// order is important!
var cssExpand = [ "Top", "Right", "Bottom", "Left" ];
$.cssHooks[ property ] = {
expand: function ( value ) {
var i,
type = $.type( value ),
// assumes a single number if not a string
parts = type === "string" ? value.split( rwhitespace ) : [ value ],
expanded = {};
for ( i = 0; i < 4; i++ ) {
expanded[ expandTemplate.replace("*", cssExpand[i] ) ] =
parts[ i ] || parts[ i - 2 ] || parts[ 0 ];
}
return expanded;
}
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment