jquery-ui/tests/unit/effects/scale.js

90 lines
2.1 KiB
JavaScript
Raw Normal View History

define( [
2016-04-03 16:45:40 +00:00
"qunit",
"jquery",
"lib/helper",
"ui/effects/effect-scale"
], function( QUnit, $, helper ) {
"use strict";
QUnit.module( "effect.scale: Scale", { afterEach: helper.moduleAfterEach } );
function run( position, v, h, vo, ho ) {
var desc = "End Position Correct: " + position + " (" + v + "," + h + ") - origin: (" + vo + "," + ho + ")";
2016-04-03 16:45:40 +00:00
QUnit.test( desc, function( assert ) {
var ready = assert.async();
assert.expect( 2 );
2012-04-19 13:39:21 +00:00
function complete() {
assert.close( parseInt( test.css( h ), 10 ), target[ h ], 1, "Horizontal Position Correct " + desc );
assert.close( parseInt( test.css( v ), 10 ), target[ v ], 1, "Vertical Position Correct " + desc );
2016-04-03 16:45:40 +00:00
ready();
2012-04-19 13:39:21 +00:00
}
var test = $( ".testScale" ),
css = {
position: position
},
effect = {
effect: "scale",
mode: "effect",
percent: 200,
origin: [ vo, ho ],
complete: complete,
duration: 1
},
target = {},
relative = position === "relative";
css[ h ] = 33;
css[ v ] = 33;
if ( h === ho ) {
target[ h ] = css[ h ];
} else if ( ho === "center" ) {
target[ h ] = css[ h ] - 35;
} else {
target[ h ] = css[ h ] - 70;
}
if ( v === vo ) {
target[ v ] = css[ v ];
} else if ( vo === "middle" ) {
target[ v ] = css[ v ] - 35;
} else {
target[ v ] = css[ v ] - 70;
}
2012-04-19 13:39:21 +00:00
if ( relative && h === "right" ) {
target[ h ] += 70;
}
2012-04-19 13:39:21 +00:00
if ( relative && v === "bottom" ) {
target[ v ] += 70;
}
test.css( css );
test.effect( effect );
2015-08-24 13:32:42 +00:00
} );
}
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" );
*/
}
2015-08-24 13:32:42 +00:00
$( function() {
suite( "absolute" );
suite( "relative" );
var fixedElem = $( "<div>" )
2015-08-24 13:32:42 +00:00
.css( {
position: "fixed",
top: 10
2015-08-24 13:32:42 +00:00
} )
.appendTo( "body" );
if ( fixedElem.offset().top === 10 ) {
suite( "fixed" );
}
2015-08-24 13:32:42 +00:00
} );
} );