X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?p=src%2Fapp-framework-demo.git;a=blobdiff_plain;f=afb-client%2Fbower_components%2Ffoundation-apps%2Fjs%2Fangular%2Fservices%2Ffoundation.dynamicRouting.animations.js;fp=afb-client%2Fbower_components%2Ffoundation-apps%2Fjs%2Fangular%2Fservices%2Ffoundation.dynamicRouting.animations.js;h=ba79c52c36b308a43af103f27129cde70c800df3;hp=0000000000000000000000000000000000000000;hb=5b1e6cc132f44262a873fa8296a2a3e1017b0278;hpb=f7d2f9ac4168ee5064580c666d508667a73cefc0 diff --git a/afb-client/bower_components/foundation-apps/js/angular/services/foundation.dynamicRouting.animations.js b/afb-client/bower_components/foundation-apps/js/angular/services/foundation.dynamicRouting.animations.js new file mode 100644 index 0000000..ba79c52 --- /dev/null +++ b/afb-client/bower_components/foundation-apps/js/angular/services/foundation.dynamicRouting.animations.js @@ -0,0 +1,125 @@ +(function() { + 'use strict'; + + angular.module('foundation.dynamicRouting.animations', ['foundation.dynamicRouting']) + .directive('uiView', uiView) + ; + + uiView.$inject = ['$rootScope', '$state']; + + function uiView($rootScope, $state) { + var directive = { + restrict : 'ECA', + priority : -400, + link : link + }; + + return directive; + + function link(scope, element) { + var animation = {}; + var animationEnded = false; + var presetHeight; + + var cleanup = [ + $rootScope.$on('$stateChangeStart', onStateChangeStart), + $rootScope.$on('$stateChangeError', onStateChangeError), + scope.$on('$stateChangeSuccess', onStateChangeSuccess), + scope.$on('$viewContentAnimationEnded', onViewContentAnimationEnded) + ]; + + var destroyed = scope.$on('$destroy', function onDestroy() { + angular.forEach(cleanup, function (cb) { + if (angular.isFunction(cb)) { + cb(); + } + }); + + destroyed(); + }); + + function onStateChangeStart(event, toState, toParams, fromState, fromParams) { + + if (fromState.animation) { + if (!fromState.animation.leave && !toState.animation.leave) { + return; + } + else { + animationRouter(event, toState, fromState); + } + } + } + + function animationRouter(event, toState, fromState) { + if (!animationEnded) { + resetParent(); + prepareParent(); + + element.removeClass(fromState.animation.leave); + } + else { + prepareParent(); + + element.addClass(fromState.animation.leave); + } + + } + + function onStateChangeError() { + if(animation.leave) { + element.removeClass(animation.leave); + } + + resetParent(); //reset parent if state change fails + } + + function onStateChangeSuccess() { + resetParent(); + if ($state.includes(getState()) && animation.enter) { + element.addClass(animation.enter); + } + } + + function onViewContentAnimationEnded(event) { + if (event.targetScope === scope && animation.enter) { + element.removeClass(animation.enter); + } + + animationEnded = true; + + } + + function getState() { + var view = element.data('$uiView'); + var state = view && view.state && view.state.self; + + if (state) { + angular.extend(animation, state.animation); + } + + return state; + } + + function resetParent() { + element.parent().removeClass('position-absolute'); + if(presetHeight !== true) { + element.parent()[0].style.height = null; + } + } + + function prepareParent() { + var parentHeight = parseInt(element.parent()[0].style.height); + var elHeight = parseInt(window.getComputedStyle(element[0], null).getPropertyValue('height')); + var tempHeight = parentHeight > 0 ? parentHeight : elHeight > 0 ? elHeight : ''; + + if(parentHeight > 0) { + presetHeight = true; + } + + element.parent()[0].style.height = tempHeight + 'px'; + element.parent().addClass('position-absolute'); + } + } + } + +})(); \ No newline at end of file