Skip to content
Permalink
Browse files

Scale: We can't detect this reliably currently, so assume all element…

…s are positioned with left and top
  • Loading branch information...
gnarf committed Oct 13, 2011
1 parent 42d33f2 commit d4d8d74b10431933aadca19248c15e36fbb35a03
Showing with 5 additions and 18 deletions.
  1. +2 −0 tests/unit/effects/effects_scale.js
  2. +3 −18 ui/jquery.effects.scale.js
@@ -44,9 +44,11 @@ function suite( position ) {
run( position, "top", "left", "top", "left" );
run( position, "top", "left", "middle", "center" );
run( position, "top", "left", "bottom", "right" );
/* Firefox is currently not capable of supporting detection of bottom and right....
run( position, "bottom", "right", "top", "left" );
run( position, "bottom", "right", "middle", "center" );
run( position, "bottom", "right", "bottom", "right" );
*/
}

$(function() {
@@ -117,9 +117,7 @@ $.effects.effect.size = function( o, done ) {
scale = o.scale || "both",
origin = o.origin || [ "middle", "center" ],
original, baseline, factor,
position = el.css( "position" ),
originalVerticalPositioning = el.css( "bottom" ) !== "auto" ? "bottom" : "top";
originalHorizontalPositioning = el.css( "right" ) !== "auto" ? "right" : "left";
position = el.css( "position" );

if ( mode === "show" ) {
el.show();
@@ -260,32 +258,19 @@ $.effects.effect.size = function( o, done ) {
left: el.to.left
});
} else {
$.each([ originalVerticalPositioning, originalHorizontalPositioning ], function( idx, pos ) {
$.each([ "top", "left" ], function( idx, pos ) {
el.css( pos, function( _, str ) {
var val = parseInt( str, 10 ),
toRef = idx ? el.to.left : el.to.top,
delta = idx ? el.to.outerWidth - el.from.outerWidth: el.to.outerHeight - el.from.outerHeight,
same = origin[ idx ] === pos,
mid = origin[ idx ] === "middle" || origin[ idx ] === "center",
direction = pos == "left" || pos == "top";
mid = origin[ idx ] === "middle" || origin[ idx ] === "center";

// if original was "auto", recalculate the new value from wrapper
if ( str === "auto" ) {
return toRef + "px";
}

// if not setting left or top
if ( !direction ) {

// if the position is relative, bottom/right are reversed meaning
if ( position === "relative" ) {
toRef *= -1;

// otherwise, if its NOT a midpoint origin, compensate for the outerWidth difference
} else if ( !mid ) {
toRef -= delta * ( same ? -1 : 1 );
}
}
return val + toRef + "px";
});
});

0 comments on commit d4d8d74

Please sign in to comment.
You can’t perform that action at this time.