-
-
Save dsimunic/a7e2d8110b4c976b4b63 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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