From bae368ce791304fce76cbd53f1fe5c36db143519 Mon Sep 17 00:00:00 2001 From: Max Lynch Date: Mon, 11 Nov 2013 21:29:55 -0600 Subject: [PATCH] Debounce back button for nav controller --- dist/js/ionic-angular.js | 48 +++++++++++++----------- js/ext/angular/src/directive/ionicNav.js | 48 +++++++++++++----------- 2 files changed, 54 insertions(+), 42 deletions(-) diff --git a/dist/js/ionic-angular.js b/dist/js/ionic-angular.js index 70d4024043..9b83827c3f 100644 --- a/dist/js/ionic-angular.js +++ b/dist/js/ionic-angular.js @@ -748,6 +748,31 @@ angular.module('ionic.ui.nav', ['ionic.service.templateLoad', 'ionic.service.ges angular.extend(this, ionic.controllers.NavController.prototype); + /** + * Push a template onto the navigation stack. + * @param {string} templateUrl the URL of the template to load. + */ + this.pushFromTemplate = ionic.debounce(function(templateUrl) { + var childScope = $scope.$new(); + childScope.isVisible = true; + + // Load the given template + TemplateLoader.load(templateUrl).then(function(templateString) { + + // Compile the template with the new scrope, and append it to the navigation's content area + var el = $compile(templateString)(childScope, function(cloned, scope) { + var content = angular.element($element[0].querySelector('.content, .scroll')); + $animate.enter(cloned, angular.element(content)); + }); + }); + }, 300, true); + + // Pop function, debounced + this.popController = ionic.debounce(function() { + _this.pop(); + }, 300, true); + + ionic.controllers.NavController.call(this, { content: { }, @@ -771,7 +796,7 @@ angular.module('ionic.ui.nav', ['ionic.service.templateLoad', 'ionic.service.ges // Support Android hardware back button (native only, not mobile web) var onHardwareBackButton = function(e) { $scope.$apply(function() { - _this.pop(); + _this.popController(); }); } Platform.onHardwareBackButton(onHardwareBackButton); @@ -784,25 +809,6 @@ angular.module('ionic.ui.nav', ['ionic.service.templateLoad', 'ionic.service.ges this.endDrag = function(e) { }; - /** - * Push a template onto the navigation stack. - * @param {string} templateUrl the URL of the template to load. - */ - this.pushFromTemplate = ionic.debounce(function(templateUrl) { - var childScope = $scope.$new(); - childScope.isVisible = true; - - // Load the given template - TemplateLoader.load(templateUrl).then(function(templateString) { - - // Compile the template with the new scrope, and append it to the navigation's content area - var el = $compile(templateString)(childScope, function(cloned, scope) { - var content = angular.element($element[0].querySelector('.content, .scroll')); - $animate.enter(cloned, angular.element(content)); - }); - }); - }, 100, true); - /** * Push a controller to the stack. This is called by the child * nav-content directive when it is linked to a scope on the page. @@ -849,7 +855,7 @@ angular.module('ionic.ui.nav', ['ionic.service.templateLoad', 'ionic.service.ges scope.$watch('navController.controllers.length', function(value) { }); scope.goBack = function() { - navCtrl.pop(); + navCtrl.popController(); }; } }; diff --git a/js/ext/angular/src/directive/ionicNav.js b/js/ext/angular/src/directive/ionicNav.js index 551ec9cff1..380ada41be 100644 --- a/js/ext/angular/src/directive/ionicNav.js +++ b/js/ext/angular/src/directive/ionicNav.js @@ -8,6 +8,31 @@ angular.module('ionic.ui.nav', ['ionic.service.templateLoad', 'ionic.service.ges angular.extend(this, ionic.controllers.NavController.prototype); + /** + * Push a template onto the navigation stack. + * @param {string} templateUrl the URL of the template to load. + */ + this.pushFromTemplate = ionic.debounce(function(templateUrl) { + var childScope = $scope.$new(); + childScope.isVisible = true; + + // Load the given template + TemplateLoader.load(templateUrl).then(function(templateString) { + + // Compile the template with the new scrope, and append it to the navigation's content area + var el = $compile(templateString)(childScope, function(cloned, scope) { + var content = angular.element($element[0].querySelector('.content, .scroll')); + $animate.enter(cloned, angular.element(content)); + }); + }); + }, 300, true); + + // Pop function, debounced + this.popController = ionic.debounce(function() { + _this.pop(); + }, 300, true); + + ionic.controllers.NavController.call(this, { content: { }, @@ -31,7 +56,7 @@ angular.module('ionic.ui.nav', ['ionic.service.templateLoad', 'ionic.service.ges // Support Android hardware back button (native only, not mobile web) var onHardwareBackButton = function(e) { $scope.$apply(function() { - _this.pop(); + _this.popController(); }); } Platform.onHardwareBackButton(onHardwareBackButton); @@ -44,25 +69,6 @@ angular.module('ionic.ui.nav', ['ionic.service.templateLoad', 'ionic.service.ges this.endDrag = function(e) { }; - /** - * Push a template onto the navigation stack. - * @param {string} templateUrl the URL of the template to load. - */ - this.pushFromTemplate = ionic.debounce(function(templateUrl) { - var childScope = $scope.$new(); - childScope.isVisible = true; - - // Load the given template - TemplateLoader.load(templateUrl).then(function(templateString) { - - // Compile the template with the new scrope, and append it to the navigation's content area - var el = $compile(templateString)(childScope, function(cloned, scope) { - var content = angular.element($element[0].querySelector('.content, .scroll')); - $animate.enter(cloned, angular.element(content)); - }); - }); - }, 100, true); - /** * Push a controller to the stack. This is called by the child * nav-content directive when it is linked to a scope on the page. @@ -109,7 +115,7 @@ angular.module('ionic.ui.nav', ['ionic.service.templateLoad', 'ionic.service.ges scope.$watch('navController.controllers.length', function(value) { }); scope.goBack = function() { - navCtrl.pop(); + navCtrl.popController(); }; } };