Skip to content

Instantly share code, notes, and snippets.

@dsimunic
Forked from barneycarroll/animator.js
Last active August 29, 2015 14:12
Show Gist options
  • Save dsimunic/a7e2d8110b4c976b4b63 to your computer and use it in GitHub Desktop.
Save dsimunic/a7e2d8110b4c976b4b63 to your computer and use it in GitHub Desktop.
var animator = ( function animatorScope(){
var animating = false;
return function animator( input, incoming, outgoing, alwaysAnimate ){
var module = {
controller : input.controller || function(){},
view : function animatedView( ctrl ){
var view = ( input.view || input )( ctrl );
var cfg = view.attrs.config;
view.attrs.config = function animationConfig( el, init, context ){
if( !init ){
if( alwaysAnimate || animating ){
if( incoming){
incoming( el, function noop(){} );
}
animating = false;
}
context.parent = el.parentElement;
context.next = el.nextElementSibling;
context.onunload = function out(){
animating = true;
if( outgoing ){
var clone = el.cloneNode( true );
context.parent.insertBefore( clone, context.next || null );
outgoing( clone, function destroy(){
context.parent.removeChild( clone );
} );
}
};
}
if( cfg ){
return cfg( el, init, context );
}
};
return view;
}
};
return input.view ? module : module.view;
};
}() );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment