(function() { 'use strict'; /** * @description * The NavController is a navigation stack View Controller modelled off of * UINavigationController from Cocoa Touch. With the Nav Controller, you can * "push" new "pages" on to the navigation stack, and then pop them off to go * back. The NavController controls a navigation bar with a back button and title * which updates as the pages switch. * * The NavController makes sure to not recycle scopes of old pages * so that a pop will still show the same state that the user left. * * However, once a page is popped, its scope is destroyed and will have to be * recreated then next time it is pushed. * */ angular.module('ionic.ui.viewState', ['ionic.service.view', 'ionic.service.gesture', 'ngSanitize']) /** * Our Nav Bar directive which updates as the controller state changes. */ .directive('ionNavBar', ['$ionicViewService', '$rootScope', '$animate', '$compile', function( $ionicViewService, $rootScope, $animate, $compile) { return { restrict: 'E', replace: true, scope: { animation: '@', type: '@', backType: '@backButtonType', backLabel: '@backButtonLabel', backIcon: '@backButtonIcon', alignTitle: '@' }, controller: function() {}, template: '', compile: function(tElement, tAttrs) { return function link($scope, $element, $attr) { $scope.titles = []; //defaults $scope.backButtonEnabled = true; $scope.animateEnabled = true; $scope.isReverse = false; $scope.isInvisible = true; // Initialize our header bar view which will handle // resizing and aligning our title labels var hb = new ionic.views.HeaderBar({ el: $element[0], alignTitle: $scope.alignTitle || 'center' }); $scope.headerBarView = hb; //Navbar events $scope.$on('viewState.viewEnter', function(e, data) { updateHeaderData(data); }); $scope.$on('viewState.showNavBar', function(e, showNavBar) { $scope.isInvisible = !showNavBar; }); // All of these these are emitted from children of a sibling scope, // so we listen on parent so we can catch them as they bubble up var unregisterEventListeners = [ $scope.$parent.$on('$viewHistory.historyChange', function(e, data) { $scope.backButtonEnabled = !!data.showBack; }), $scope.$parent.$on('viewState.leftButtonsChanged', function(e, data) { $scope.leftButtons = data; }), $scope.$parent.$on('viewState.rightButtonsChanged', function(e, data) { $scope.rightButtons = data; }), $scope.$parent.$on('viewState.showBackButton', function(e, data) { $scope.backButtonEnabled = !!data; }), $scope.$parent.$on('viewState.titleUpdated', function(e, data) { $scope.titles[$scope.titles.length - 1] = data && data.title || ''; }) ]; $scope.$on('$destroy', function() { for (var i=0; i