Skip to content

Commit

Permalink
Updated so it uses the new DRY version of effects.core
Browse files Browse the repository at this point in the history
  • Loading branch information
Jesper Lindstroem Nielsen authored and Jesper Lindstroem Nielsen committed Jul 23, 2011
1 parent 1160a32 commit e6cc967
Show file tree
Hide file tree
Showing 6 changed files with 262 additions and 275 deletions.
48 changes: 23 additions & 25 deletions ui/jquery.effects.blockfade.js
Expand Up @@ -13,7 +13,7 @@
*/
(function( $, undefined ) {

$.effects.effect.blockfade = function( o ) {
$.effects.effect.blockfade = function( o, done ) {

/*Options:
* random,
Expand All @@ -27,33 +27,31 @@
* show
*/

return this.queue( function( next ) {
var el = $( this ),
opt = $.effects.split.options( el, {
distance: 1,
reverse: false,
random: false,
interval: false
}, o );
var el = $( this ),
opt = $.effects.split.options( el, {
distance: 1,
reverse: false,
random: false,
interval: false
}, o );

function animate( width, height, interval, duration, row, column, documentCoords, parentCoords, callback ) {
var random = opt.random ? Math.abs( opt.random ) : 0,
el = $( this ),
randomDelay = Math.random() * ( opt.rows + opt.columns ) * interval,
uniformDelay = ( opt.reverse ) ?
( ( ( opt.rows + opt.columns ) - ( row + column ) ) * interval ) :
( ( row + column ) * interval ),
delay = randomDelay * random + Math.max( 1 - random, 0 ) * uniformDelay;

if ( opt.show ) {
el.css( "opacity", 0 );
}

el.delay( delay ).animate( { opacity: ( opt.show ? 1 : 0 ) }, duration, opt.easing, callback );
function animate( width, height, interval, duration, row, column, documentCoords, parentCoords, callback ) {
var random = opt.random ? Math.abs( opt.random ) : 0,
el = $( this ),
randomDelay = Math.random() * ( opt.rows + opt.columns ) * interval,
uniformDelay = ( opt.reverse ) ?
( ( ( opt.rows + opt.columns ) - ( row + column ) ) * interval ) :
( ( row + column ) * interval ),
delay = randomDelay * random + Math.max( 1 - random, 0 ) * uniformDelay;

if ( opt.show ) {
el.css( "opacity", 0 );
}

el.delay( delay ).animate( { opacity: ( opt.show ? 1 : 0 ) }, duration, opt.easing, callback );
}

$.effects.split.startAnim( el, opt, animate, next );
} );
$.effects.split.startAnim( el, opt, animate, done );
}

})(jQuery);
122 changes: 59 additions & 63 deletions ui/jquery.effects.build.js
Expand Up @@ -13,7 +13,7 @@
*/
(function( $, undefined ) {

$.effects.effect.build = function( o ){
$.effects.effect.build = function( o, done ){
/*Options:
* random,
* reverse,
Expand All @@ -29,80 +29,76 @@
* fade,
* show
*/

return this.queue( function( next ) {

var el = $( this ),
opt = $.effects.split.options( el, {
direction: "bottom",
distance: 1,
reverse: false,
random: false,
interval: false,
fade: true,
crop: false
}, o );
var el = $( this ),
opt = $.effects.split.options( el, {
direction: "bottom",
distance: 1,
reverse: false,
random: false,
interval: false,
fade: true,
crop: false
}, o );

function animate( width, height, interval, duration, row, column, documentCoords, parentCoords, callback ) {
var random = opt.random ? Math.abs( opt.random ) : 0,
el = $( this ),
randomDelay = Math.random() * ( opt.rows + opt.columns ) * interval,
uniformDelay = ( opt.reverse || opt.distance < 0 ) ?
( ( row + column ) * interval ) :
( ( ( opt.rows + opt.columns ) - ( row + column ) ) * interval ),
delay = randomDelay * random + Math.max( 1 - random, 0 ) * uniformDelay,
properties = el.offset(),
maxTop = documentCoords.height - height,
maxLeft = documentCoords.width - width,
top, left;
function animate( width, height, interval, duration, row, column, documentCoords, parentCoords, callback ) {
var random = opt.random ? Math.abs( opt.random ) : 0,
el = $( this ),
randomDelay = Math.random() * ( opt.rows + opt.columns ) * interval,
uniformDelay = ( opt.reverse || opt.distance < 0 ) ?
( ( row + column ) * interval ) :
( ( ( opt.rows + opt.columns ) - ( row + column ) ) * interval ),
delay = randomDelay * random + Math.max( 1 - random, 0 ) * uniformDelay,
properties = el.offset(),
maxTop = documentCoords.height - height,
maxLeft = documentCoords.width - width,
top, left;

properties.top -= parentCoords.top;
properties.left -= parentCoords.left;
properties.top -= parentCoords.top;
properties.left -= parentCoords.left;

if ( opt.fade ) {
properties.opacity = ( opt.show ? 1 : 0 );
el.css( "opacity", opt.show ? 0 : "" );
}
if ( opt.fade ) {
properties.opacity = ( opt.show ? 1 : 0 );
el.css( "opacity", opt.show ? 0 : "" );
}


if ( opt.direction.indexOf( "bottom" ) !== -1 ) {
top = properties.top + parentCoords.height * opt.distance;
top = top > maxTop ? maxTop : top;
} else if ( opt.direction.indexOf( "top" ) !== -1 ) {
top = properties.top - parentCoords.height * opt.distance;
top = top < 0 ? 0 : top;
}
if ( opt.direction.indexOf( "bottom" ) !== -1 ) {
top = properties.top + parentCoords.height * opt.distance;
top = top > maxTop ? maxTop : top;
} else if ( opt.direction.indexOf( "top" ) !== -1 ) {
top = properties.top - parentCoords.height * opt.distance;
top = top < 0 ? 0 : top;
}

if ( opt.direction.indexOf( "right" ) !== -1 ) {
left = properties.left + parentCoords.width * opt.distance;
left = left > maxLeft ? maxLeft : left;
} else if ( opt.direction.indexOf( "left" ) !== -1 ) {
left = properties.left - parentCoords.width * opt.distance;
left = left < 0 ? 0 : left;
}
if ( opt.direction.indexOf( "right" ) !== -1 ) {
left = properties.left + parentCoords.width * opt.distance;
left = left > maxLeft ? maxLeft : left;
} else if ( opt.direction.indexOf( "left" ) !== -1 ) {
left = properties.left - parentCoords.width * opt.distance;
left = left < 0 ? 0 : left;
}

if ( opt.direction.indexOf( "right" ) || opt.direction.indexOf( "left" ) ) {
if ( opt.show ) {
el.css( "left", left );
} else {
properties.left = left;
}
if ( opt.direction.indexOf( "right" ) || opt.direction.indexOf( "left" ) ) {
if ( opt.show ) {
el.css( "left", left );
} else {
properties.left = left;
}
}

if ( opt.direction.indexOf( "top" ) || opt.direction.indexOf( "bottom" ) ) {
if ( opt.show ) {
el.css( "top", top );
} else {
properties.top = top;
}
if ( opt.direction.indexOf( "top" ) || opt.direction.indexOf( "bottom" ) ) {
if ( opt.show ) {
el.css( "top", top );
} else {
properties.top = top;
}

el.delay( delay ).animate( properties, duration, opt.easing, callback );
}

$.effects.split.startAnim( el, opt, animate, next );

} );

el.delay( delay ).animate( properties, duration, opt.easing, callback );
}

$.effects.split.startAnim( el, opt, animate, done );

}

Expand Down
117 changes: 57 additions & 60 deletions ui/jquery.effects.explode.js
Expand Up @@ -11,7 +11,7 @@
* jquery.effects.core.js
*/
(function( $, undefined ) {
$.effects.effect.explode = function( o ) {
$.effects.effect.explode = function( o, done ) {

/*Options:
* random,
Expand All @@ -28,73 +28,70 @@
* show,
* crop
*/

return this.queue( function( next ) {
var el = $( this ),
opt = $.effects.split.options( el, {
distance: 1,
reverse: false,
random: false,
sync: false,
interval: false,
fade: true,
crop: false
}, o );
var el = $( this ),
opt = $.effects.split.options( el, {
distance: 1,
reverse: false,
random: false,
sync: false,
interval: false,
fade: true,
crop: false
}, o );

function animate( width, height, interval, duration, row, column, documentCoords, parentCoords, callback ) {
var el = $( this ),
delay = 0,
startProperties = el.offset(),
distance = opt.distance,
randomX = 0,
randomY = 0,
properties, distanceX, distanceY, distanceXY, seed;
startProperties = {
top : startProperties.top - parentCoords.top,
left : startProperties.left - parentCoords.left
};
//Copy object
properties = $.extend( {}, startProperties );
if ( opt.fade ) {
properties.opacity = ( opt.show ? 1 : 0 );
startProperties.opacity = 1;
}
function animate( width, height, interval, duration, row, column, documentCoords, parentCoords, callback ) {
var el = $( this ),
delay = 0,
startProperties = el.offset(),
distance = opt.distance,
randomX = 0,
randomY = 0,
properties, distanceX, distanceY, distanceXY, seed;

startProperties = {
top : startProperties.top - parentCoords.top,
left : startProperties.left - parentCoords.left
};

//Copy object
properties = $.extend( {}, startProperties );

if ( opt.fade ) {
properties.opacity = ( opt.show ? 1 : 0 );
startProperties.opacity = 1;
}

if ( opt.random ) {
seed = ( Math.random() * opt.random ) + Math.max( 1 - opt.random, 0 );
distance *= seed;
duration *= seed;
if ( opt.random ) {
seed = ( Math.random() * opt.random ) + Math.max( 1 - opt.random, 0 );
distance *= seed;
duration *= seed;

// To syncronize, give each piece an appropriate delay so they end together
if ( opt.sync ) {
delay = opt.duration - duration;
}
randomX = Math.random() - 0.5;
randomY = Math.random() - 0.5;
// To syncronize, give each piece an appropriate delay so they end together
if ( opt.sync ) {
delay = opt.duration - duration;
}
randomX = Math.random() - 0.5;
randomY = Math.random() - 0.5;
}

distanceY = ( parentCoords.height - height ) / 2 - height * row;
distanceX = ( parentCoords.width - width ) / 2 - width * column;
distanceXY = Math.sqrt( Math.pow( distanceX, 2 ) + Math.pow( distanceY, 2 ) );
properties.top -= distanceY * distance + distanceXY * randomY;
properties.left -= distanceX * distance + distanceXY * randomX;

if ( opt.show ) {
el.css( properties );
if ( opt.fade ) {
el.css( "opacity", 0 );
}
properties = startProperties;
distanceY = ( parentCoords.height - height ) / 2 - height * row;
distanceX = ( parentCoords.width - width ) / 2 - width * column;
distanceXY = Math.sqrt( Math.pow( distanceX, 2 ) + Math.pow( distanceY, 2 ) );
properties.top -= distanceY * distance + distanceXY * randomY;
properties.left -= distanceX * distance + distanceXY * randomX;

if ( opt.show ) {
el.css( properties );
if ( opt.fade ) {
el.css( "opacity", 0 );
}

el.delay( delay ).animate( properties, duration, opt.easing, callback );
properties = startProperties;
}

$.effects.split.startAnim( el, opt, animate, next );
} );
el.delay( delay ).animate( properties, duration, opt.easing, callback );
}

$.effects.split.startAnim( el, opt, animate, done );
}

})(jQuery);

0 comments on commit e6cc967

Please sign in to comment.