mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
show/hide back button from view
This commit is contained in:
23
dist/js/ionic-angular.js
vendored
23
dist/js/ionic-angular.js
vendored
@@ -2615,15 +2615,12 @@ angular.module('ionic.ui.viewState', ['ionic.service.view', 'ionic.service.gestu
|
||||
return function link($scope, $element, $attr) {
|
||||
// Should we hide a back button when this tab is shown
|
||||
$scope.hideBackButton = $scope.$eval($scope.hideBackButton);
|
||||
if($scope.hideBackButton) {
|
||||
$rootScope.$broadcast('viewState.showBackButton', false);
|
||||
}
|
||||
|
||||
$scope.hideNavBar = $scope.$eval($scope.hideNavBar);
|
||||
|
||||
if($scope.hideBackButton === true) {
|
||||
$scope.$emit('viewState.hideBackButton');
|
||||
} else {
|
||||
$scope.$emit('viewState.showBackButton');
|
||||
}
|
||||
|
||||
// watch for changes in the left buttons
|
||||
$scope.$watch('leftButtons', function(value) {
|
||||
$scope.$emit('viewState.leftButtonsChanged', $scope.leftButtons);
|
||||
@@ -2653,14 +2650,22 @@ angular.module('ionic.ui.viewState', ['ionic.service.view', 'ionic.service.gestu
|
||||
tElement.addClass('hide');
|
||||
|
||||
return function link($scope, $element) {
|
||||
$element.bind('click', goBack);
|
||||
$element.bind('tap', goBack);
|
||||
|
||||
$rootScope.$on('$viewHistory.historyChange', function(e, data) {
|
||||
if(data.showBack) {
|
||||
$scope.showButton = function(val) {
|
||||
if(val) {
|
||||
$element[0].classList.remove('hide');
|
||||
} else {
|
||||
$element[0].classList.add('hide');
|
||||
}
|
||||
};
|
||||
|
||||
$rootScope.$on('$viewHistory.historyChange', function(e, data) {
|
||||
$scope.showButton(data.showBack);
|
||||
});
|
||||
|
||||
$rootScope.$on('viewState.showBackButton', function(e, data) {
|
||||
$scope.showButton(data);
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
23
js/ext/angular/src/directive/ionicViewState.js
vendored
23
js/ext/angular/src/directive/ionicViewState.js
vendored
@@ -174,15 +174,12 @@ angular.module('ionic.ui.viewState', ['ionic.service.view', 'ionic.service.gestu
|
||||
return function link($scope, $element, $attr) {
|
||||
// Should we hide a back button when this tab is shown
|
||||
$scope.hideBackButton = $scope.$eval($scope.hideBackButton);
|
||||
if($scope.hideBackButton) {
|
||||
$rootScope.$broadcast('viewState.showBackButton', false);
|
||||
}
|
||||
|
||||
$scope.hideNavBar = $scope.$eval($scope.hideNavBar);
|
||||
|
||||
if($scope.hideBackButton === true) {
|
||||
$scope.$emit('viewState.hideBackButton');
|
||||
} else {
|
||||
$scope.$emit('viewState.showBackButton');
|
||||
}
|
||||
|
||||
// watch for changes in the left buttons
|
||||
$scope.$watch('leftButtons', function(value) {
|
||||
$scope.$emit('viewState.leftButtonsChanged', $scope.leftButtons);
|
||||
@@ -212,14 +209,22 @@ angular.module('ionic.ui.viewState', ['ionic.service.view', 'ionic.service.gestu
|
||||
tElement.addClass('hide');
|
||||
|
||||
return function link($scope, $element) {
|
||||
$element.bind('click', goBack);
|
||||
$element.bind('tap', goBack);
|
||||
|
||||
$rootScope.$on('$viewHistory.historyChange', function(e, data) {
|
||||
if(data.showBack) {
|
||||
$scope.showButton = function(val) {
|
||||
if(val) {
|
||||
$element[0].classList.remove('hide');
|
||||
} else {
|
||||
$element[0].classList.add('hide');
|
||||
}
|
||||
};
|
||||
|
||||
$rootScope.$on('$viewHistory.historyChange', function(e, data) {
|
||||
$scope.showButton(data.showBack);
|
||||
});
|
||||
|
||||
$rootScope.$on('viewState.showBackButton', function(e, data) {
|
||||
$scope.showButton(data);
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
48
js/ext/angular/test/directive/ionicView.unit.js
Normal file
48
js/ext/angular/test/directive/ionicView.unit.js
Normal file
@@ -0,0 +1,48 @@
|
||||
'use strict';
|
||||
|
||||
describe('Ionic View', function() {
|
||||
var compile, scope, listElement, listCtrl;
|
||||
|
||||
beforeEach(module('ionic.ui.viewState'));
|
||||
|
||||
beforeEach(inject(function($compile, $rootScope, $controller) {
|
||||
compile = $compile;
|
||||
scope = $rootScope;
|
||||
}));
|
||||
|
||||
it('should init a view', function() {
|
||||
var element = compile('<view>me view</view>')(scope);
|
||||
expect(element.html()).toEqual('me view');
|
||||
});
|
||||
|
||||
it('should add pane classname and remove title from view', function() {
|
||||
var element = compile('<view title="\'Me Title\'"></view>')(scope);
|
||||
expect(element.attr('title')).toBeUndefined();
|
||||
expect(element.hasClass('pane')).toEqual(true);
|
||||
});
|
||||
|
||||
it('should set hide back button', function() {
|
||||
spyOn(scope, '$broadcast');
|
||||
|
||||
var element = compile('<view></view>')(scope);
|
||||
var viewScope = element.isolateScope();
|
||||
expect(viewScope.hideBackButton).toBeUndefined();
|
||||
expect(scope.$broadcast).not.toHaveBeenCalledWith('viewState.showBackButton', false);
|
||||
|
||||
element = compile('<view hide-back-button="true"></view>')(scope);
|
||||
viewScope = element.isolateScope();
|
||||
expect(viewScope.hideBackButton).toEqual(true);
|
||||
expect(scope.$broadcast).toHaveBeenCalledWith('viewState.showBackButton', false);
|
||||
});
|
||||
|
||||
it('should show/hide viewBack', function() {
|
||||
var element = compile('<button view-back>BUTTON</button>')(scope);
|
||||
expect(element.hasClass('hide')).toEqual(true);
|
||||
scope.$broadcast('viewState.showBackButton', true);
|
||||
expect(element.hasClass('hide')).toEqual(false);
|
||||
scope.$broadcast('$viewHistory.historyChange', { showBack: false });
|
||||
expect(element.hasClass('hide')).toEqual(true);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -80,8 +80,9 @@
|
||||
</script>
|
||||
|
||||
<script id="contact.html" type="text/ng-template">
|
||||
<view title="'Contact'">
|
||||
<view title="'Contact'" hide-back-button="true">
|
||||
<content has-header="true" padding="true">
|
||||
<p>The hideBackButton attribute is "true" for this view.</p>
|
||||
<p>@drifty</p>
|
||||
<p class="text-center">
|
||||
<a href="#/sign-in">Sign-In</a> -
|
||||
@@ -179,6 +180,10 @@
|
||||
<a ng-href="#/tabs/autos/6" class="ng-binding" href="#/tabs/autos/6">1948 Tucker 48</a>
|
||||
</li>
|
||||
</ul>
|
||||
<p>
|
||||
<button ng-click="hideBackButton()">Hide Back Button</button>
|
||||
<button ng-click="showBackButton()">Show Back Button</button>
|
||||
</p>
|
||||
<p>
|
||||
Current View: {{ $viewHistory.currentView }}<br>
|
||||
Back View: {{ $viewHistory.backView }}<br>
|
||||
@@ -326,6 +331,13 @@
|
||||
.controller('AutoDetailCtrl', function($scope, $state, $stateParams) {
|
||||
$scope.autoDetailData = "AutoDetailCtrl Data";
|
||||
|
||||
$scope.hideBackButton = function() {
|
||||
$scope.$emit('viewState.showBackButton', false);
|
||||
};
|
||||
$scope.showBackButton = function() {
|
||||
$scope.$emit('viewState.showBackButton', true);
|
||||
};
|
||||
|
||||
$scope.auto = $scope.autos[$stateParams.id];
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user