update how view's set titles, closes #337

This commit is contained in:
Adam Bradley
2014-01-12 22:39:10 -06:00
parent 8982a8ad40
commit 3124ef3981
8 changed files with 38 additions and 32 deletions

View File

@@ -913,11 +913,6 @@ angular.module('ionic.service.view', ['ui.router'])
}
opts.parentElement.append(opts.enteringElement);
}
$rootScope.$broadcast('viewState.viewEnter', {
title: (opts.enteringScope ? opts.enteringScope.title : null),
navDirection: (opts.navDirection ? opts.navDirection : null)
});
function getAnimationClass(){
// go up the ancestors looking for an animation value
@@ -1995,7 +1990,7 @@ angular.module('ionic.ui.slideBox', [])
showPager: '@',
disableScroll: '@',
onSlideChanged: '&',
activeSlide: '='
activeSlide: '=?'
},
controller: ['$scope', '$element', function($scope, $element) {
var _this = this;
@@ -2550,12 +2545,9 @@ angular.module('ionic.ui.viewState', ['ionic.service.view', 'ionic.service.gestu
$element.addClass($scope.type);
var updateHeaderData = function(data) {
var oldTitle = $scope.currentTitle;
$scope.oldTitle = oldTitle;
$scope.oldTitle = $scope.currentTitle;
if(typeof data.title !== 'undefined') {
$scope.currentTitle = data.title;
}
$scope.currentTitle = (data && data.title ? data.title : '');
$scope.leftButtons = data.leftButtons;
$scope.rightButtons = data.rightButtons;
@@ -2573,7 +2565,7 @@ angular.module('ionic.ui.viewState', ['ionic.service.view', 'ionic.service.gestu
$element[0].classList.remove('reverse');
}
animate($scope, $element, oldTitle, data, function() {
animate($scope, $element, $scope.oldTitle, data, function() {
hb.align();
});
} else {
@@ -2622,6 +2614,12 @@ angular.module('ionic.ui.viewState', ['ionic.service.view', 'ionic.service.gestu
tElement[0].removeAttribute('title');
return function link($scope, $element, $attr) {
$rootScope.$broadcast('viewState.viewEnter', {
title: $scope.title,
navDirection: $scope.$navDirection || $scope.$parent.$navDirection
});
// Should we hide a back button when this tab is shown
$scope.hideBackButton = $scope.$eval($scope.hideBackButton);
if($scope.hideBackButton) {
@@ -2769,6 +2767,7 @@ angular.module('ionic.ui.viewState', ['ionic.service.view', 'ionic.service.gestu
current = $state.current;
viewScope = current.scope = scope.$new();
viewScope.$navDirection = transitionOptions.navDirection;
if (locals.$$controller) {
locals.$scope = viewScope;

View File

File diff suppressed because one or more lines are too long

View File

File diff suppressed because one or more lines are too long

View File

@@ -102,12 +102,9 @@ angular.module('ionic.ui.viewState', ['ionic.service.view', 'ionic.service.gestu
$element.addClass($scope.type);
var updateHeaderData = function(data) {
var oldTitle = $scope.currentTitle;
$scope.oldTitle = oldTitle;
$scope.oldTitle = $scope.currentTitle;
if(typeof data.title !== 'undefined') {
$scope.currentTitle = data.title;
}
$scope.currentTitle = (data && data.title ? data.title : '');
$scope.leftButtons = data.leftButtons;
$scope.rightButtons = data.rightButtons;
@@ -125,7 +122,7 @@ angular.module('ionic.ui.viewState', ['ionic.service.view', 'ionic.service.gestu
$element[0].classList.remove('reverse');
}
animate($scope, $element, oldTitle, data, function() {
animate($scope, $element, $scope.oldTitle, data, function() {
hb.align();
});
} else {
@@ -174,6 +171,12 @@ angular.module('ionic.ui.viewState', ['ionic.service.view', 'ionic.service.gestu
tElement[0].removeAttribute('title');
return function link($scope, $element, $attr) {
$rootScope.$broadcast('viewState.viewEnter', {
title: $scope.title,
navDirection: $scope.$navDirection || $scope.$parent.$navDirection
});
// Should we hide a back button when this tab is shown
$scope.hideBackButton = $scope.$eval($scope.hideBackButton);
if($scope.hideBackButton) {
@@ -321,6 +324,7 @@ angular.module('ionic.ui.viewState', ['ionic.service.view', 'ionic.service.gestu
current = $state.current;
viewScope = current.scope = scope.$new();
viewScope.$navDirection = transitionOptions.navDirection;
if (locals.$$controller) {
locals.$scope = viewScope;

View File

@@ -357,11 +357,6 @@ angular.module('ionic.service.view', ['ui.router'])
}
opts.parentElement.append(opts.enteringElement);
}
$rootScope.$broadcast('viewState.viewEnter', {
title: (opts.enteringScope ? opts.enteringScope.title : null),
navDirection: (opts.navDirection ? opts.navDirection : null)
});
function getAnimationClass(){
// go up the ancestors looking for an animation value

View File

@@ -21,6 +21,16 @@ describe('Ionic View', function() {
expect(element.hasClass('pane')).toEqual(true);
});
it('should broacast view enter on link', function() {
spyOn(scope, '$broadcast');
var element = compile('<view title="\'Me Title\'"></view>')(scope);
expect(scope.$broadcast).toHaveBeenCalledWith('viewState.viewEnter', { title: 'Me Title', navDirection: undefined });
scope.$navDirection = 'forward';
element = compile('<view title="\'Me Title\'"></view>')(scope);
expect(scope.$broadcast).toHaveBeenCalledWith('viewState.viewEnter', { title: 'Me Title', navDirection: 'forward' });
});
it('should set hide back button', function() {
spyOn(scope, '$broadcast');

View File

@@ -779,12 +779,9 @@ describe('Ionic View Service', function() {
opts.leavingElement = opts.parentElement.find('leaving');
opts.enteringElement = $compile("<entering>entering</entering>")(rootScope);
spyOn(rootScope, '$broadcast');
expect(opts.parentElement.html()).toContain("leaving");
viewService.transition(opts);
expect(opts.parentElement.html()).toContain("entering");
expect(rootScope.$broadcast).toHaveBeenCalledWith('viewState.viewEnter', { title: null, navDirection: null });
}));
it('should add the animation classname', inject(function($compile) {

View File

@@ -83,8 +83,9 @@
</script>
<script id="contact.html" type="text/ng-template">
<view title="'Contact'" hide-back-button="true">
<view hide-back-button="true">
<content has-header="true" padding="true">
<p>The view's title is blank on purpose.</p>
<p>The hideBackButton attribute is "true" for this view.</p>
<p>@drifty</p>
<p class="text-center">