Conflicts:
	dist/js/ionic-angular.min.js
This commit is contained in:
Max Lynch
2014-01-12 20:25:23 -06:00
6 changed files with 162 additions and 42 deletions

View File

@@ -2515,7 +2515,7 @@ angular.module('ionic.ui.viewState', ['ionic.service.view', 'ionic.service.gestu
backButtonIcon: '@',
alignTitle: '@'
},
template: '<header class="bar bar-header nav-bar">'+//' ng-class="{invisible: !navController.navBar.isVisible}">' +
template: '<header class="bar bar-header nav-bar" ng-class="{invisible: !showNavBar}">' +
'<div class="buttons"> ' +
'<button view-back class="button" ng-if="enableBackButton" ng-class="backButtonClass" ng-bind-html="backButtonLabel"></button>' +
'<button ng-click="button.tap($event)" ng-repeat="button in leftButtons" class="button no-animation {{button.type}}" ng-bind-html="button.content"></button>' +
@@ -2525,7 +2525,7 @@ angular.module('ionic.ui.viewState', ['ionic.service.view', 'ionic.service.gestu
'<button ng-click="button.tap($event)" ng-repeat="button in rightButtons" class="button no-animation {{button.type}}" ng-bind-html="button.content"></button>' +
'</div>' +
'</header>',
link: function($scope, $element, $attr, navCtrl) {
link: function($scope, $element, $attr) {
// Create the back button content and show/hide it based on scope settings
$scope.enableBackButton = true;
@@ -2534,8 +2534,10 @@ angular.module('ionic.ui.viewState', ['ionic.service.view', 'ionic.service.gestu
$scope.backButtonClass += ' icon ' + $attr.backButtonIcon;
}
// Store a reference to our nav controller
$scope.navController = navCtrl;
$scope.showNavBar = true;
$rootScope.$on('viewState.showNavBar', function(e, data) {
$scope.showNavBar = data;
});
// Initialize our header bar view which will handle resizing and aligning our title labels
var hb = new ionic.views.HeaderBar({
@@ -2622,24 +2624,29 @@ 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);
$scope.hideNavBar = $scope.$eval($scope.hideNavBar);
if($scope.hideBackButton === true) {
$scope.$emit('viewState.hideBackButton');
} else {
$scope.$emit('viewState.showBackButton');
if($scope.hideBackButton) {
$rootScope.$broadcast('viewState.showBackButton', false);
}
// Should the nav bar be hidden for this view or not?
$scope.hideNavBar = $scope.$eval($scope.hideNavBar);
$rootScope.$broadcast('viewState.showNavBar', !$scope.hideNavBar);
// watch for changes in the left buttons
$scope.$watch('leftButtons', function(value) {
var deregLeftButtons = $scope.$watch('leftButtons', function(value) {
$scope.$emit('viewState.leftButtonsChanged', $scope.leftButtons);
});
$scope.$watch('rightButtons', function(val) {
var deregRightButtons = $scope.$watch('rightButtons', function(val) {
$scope.$emit('viewState.rightButtonsChanged', $scope.rightButtons);
});
$scope.$on('$destroy', function(){
// deregister on destroy
deregLeftButtons();
deregRightButtons();
});
};
}
};
@@ -2660,14 +2667,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);
});
};

View File

@@ -37,7 +37,7 @@
back-button-icon="ion-arrow-left-c"></nav-bar>
<!-- where the content of each page will be rendered -->
<nav-view animation="slide-left-right"></ui-view>
<nav-view animation="slide-left-right"></nav-view>
<!--

View File

@@ -67,7 +67,7 @@ angular.module('ionic.ui.viewState', ['ionic.service.view', 'ionic.service.gestu
backButtonIcon: '@',
alignTitle: '@'
},
template: '<header class="bar bar-header nav-bar">'+//' ng-class="{invisible: !navController.navBar.isVisible}">' +
template: '<header class="bar bar-header nav-bar" ng-class="{invisible: !showNavBar}">' +
'<div class="buttons"> ' +
'<button view-back class="button" ng-if="enableBackButton" ng-class="backButtonClass" ng-bind-html="backButtonLabel"></button>' +
'<button ng-click="button.tap($event)" ng-repeat="button in leftButtons" class="button no-animation {{button.type}}" ng-bind-html="button.content"></button>' +
@@ -77,7 +77,7 @@ angular.module('ionic.ui.viewState', ['ionic.service.view', 'ionic.service.gestu
'<button ng-click="button.tap($event)" ng-repeat="button in rightButtons" class="button no-animation {{button.type}}" ng-bind-html="button.content"></button>' +
'</div>' +
'</header>',
link: function($scope, $element, $attr, navCtrl) {
link: function($scope, $element, $attr) {
// Create the back button content and show/hide it based on scope settings
$scope.enableBackButton = true;
@@ -86,8 +86,10 @@ angular.module('ionic.ui.viewState', ['ionic.service.view', 'ionic.service.gestu
$scope.backButtonClass += ' icon ' + $attr.backButtonIcon;
}
// Store a reference to our nav controller
$scope.navController = navCtrl;
$scope.showNavBar = true;
$rootScope.$on('viewState.showNavBar', function(e, data) {
$scope.showNavBar = data;
});
// Initialize our header bar view which will handle resizing and aligning our title labels
var hb = new ionic.views.HeaderBar({
@@ -174,24 +176,29 @@ 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);
$scope.hideNavBar = $scope.$eval($scope.hideNavBar);
if($scope.hideBackButton === true) {
$scope.$emit('viewState.hideBackButton');
} else {
$scope.$emit('viewState.showBackButton');
if($scope.hideBackButton) {
$rootScope.$broadcast('viewState.showBackButton', false);
}
// Should the nav bar be hidden for this view or not?
$scope.hideNavBar = $scope.$eval($scope.hideNavBar);
$rootScope.$broadcast('viewState.showNavBar', !$scope.hideNavBar);
// watch for changes in the left buttons
$scope.$watch('leftButtons', function(value) {
var deregLeftButtons = $scope.$watch('leftButtons', function(value) {
$scope.$emit('viewState.leftButtonsChanged', $scope.leftButtons);
});
$scope.$watch('rightButtons', function(val) {
var deregRightButtons = $scope.$watch('rightButtons', function(val) {
$scope.$emit('viewState.rightButtonsChanged', $scope.rightButtons);
});
$scope.$on('$destroy', function(){
// deregister on destroy
deregLeftButtons();
deregRightButtons();
});
};
}
};
@@ -212,14 +219,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);
});
};

View File

@@ -0,0 +1,71 @@
'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);
});
it('should show/hide navBar', function() {
var element = compile('<nav-bar></nav-bar>')(scope);
expect(element.hasClass('invisible')).toEqual(false);
scope.$broadcast('viewState.showNavBar', false);
scope.$digest();
expect(element.hasClass('invisible')).toEqual(true);
scope.$broadcast('viewState.showNavBar', true);
scope.$digest();
expect(element.hasClass('invisible')).toEqual(false);
});
it('should hide navBar when using view attr', function() {
var element = compile('<div><nav-bar></nav-bar><view hide-nav-bar="true"></view></div>')(scope);
scope.$digest();
var navBar = element.find('header')
expect(navBar.hasClass('invisible')).toEqual(true);
element = compile('<div><nav-bar></nav-bar><view></view></div>')(scope);
scope.$digest();
navBar = element.find('header')
expect(navBar.hasClass('invisible')).toEqual(false);
});
});

View File

@@ -58,10 +58,13 @@
</script>
<script id="forgot-password.html" type="text/ng-template">
<view title="'Forgot Password'">
<view title="'Forgot Password'" hide-nav-bar="true">
<content has-header="true" padding="true">
<p>Seriously!? Again?!</p>
<p>How about I just give you a password, hows this: <br><code>{{password}}</code></p>
<p>This view hides the nav bar using the hideNavBar attribute.</p>
<p>
<button ng-click="hideNavBar()">Hide Nav Bar</button>
<button ng-click="showNavBar()">Show Nav Bar</button>
</p>
<p>
<button ng-click="clearViewHistory()">Clear View History</button>
</p>
@@ -80,8 +83,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 +183,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>
@@ -299,19 +307,23 @@
})
.controller('SignInCtrl', function($scope, $state) {
//console.log('SignInCtrl');
$scope.signIn = function(user) {
$state.go('tabs.autolist');
};
})
.controller('ForgotPasswordCtrl', function(ViewService, $scope, $state) {
$scope.password = Math.round(Math.random() * 10000);
.controller('ForgotPasswordCtrl', function(ViewService, $rootScope, $scope, $state) {
$scope.clearViewHistory = function() {
ViewService.clearHistory();
};
$scope.hideNavBar = function() {
$rootScope.$broadcast('viewState.showNavBar', false);
};
$scope.showNavBar = function() {
$rootScope.$broadcast('viewState.showNavBar', true);
};
})
.controller('AutoListCtrl', function($scope, $state) {
@@ -326,6 +338,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];
})