From 46cbaf9527f6432a645147224d9d72dcec7c91dd Mon Sep 17 00:00:00 2001 From: Adam Bradley Date: Tue, 18 Nov 2014 16:07:55 -0600 Subject: [PATCH] fix(scroll): find delegate by historyId Closes #2572 --- js/angular/controller/navBarController.js | 3 ++- js/angular/controller/scrollController.js | 5 +++-- js/angular/controller/viewController.js | 6 +----- js/angular/service/delegateService.js | 6 +++++- js/angular/service/history.js | 10 ++++++++++ js/angular/service/scrollDelegate.js | 1 - 6 files changed, 21 insertions(+), 10 deletions(-) diff --git a/js/angular/controller/navBarController.js b/js/angular/controller/navBarController.js index 6cac3bf621..53b90d9654 100644 --- a/js/angular/controller/navBarController.js +++ b/js/angular/controller/navBarController.js @@ -335,11 +335,12 @@ function($scope, $element, $attrs, $compile, $timeout, $ionicNavBarDelegate, $io self.title = function(newTitleText, headerBar) { - if (arguments.length) { + if (isDefined(newTitleText)) { newTitleText = newTitleText || ''; headerBar = headerBar || getOnScreenHeaderBar(); headerBar && headerBar.title(newTitleText); $scope.$title = newTitleText; + $ionicHistory.currentTitle(newTitleText); } return $scope.$title; }; diff --git a/js/angular/controller/scrollController.js b/js/angular/controller/scrollController.js index 832a497e3a..42f6c1e560 100644 --- a/js/angular/controller/scrollController.js +++ b/js/angular/controller/scrollController.js @@ -11,7 +11,8 @@ IonicModule '$location', '$document', '$ionicScrollDelegate', -function($scope, scrollViewOptions, $timeout, $window, $location, $document, $ionicScrollDelegate) { + '$ionicHistory', +function($scope, scrollViewOptions, $timeout, $window, $location, $document, $ionicScrollDelegate, $ionicHistory) { var self = this; // for testing @@ -31,7 +32,7 @@ function($scope, scrollViewOptions, $timeout, $window, $location, $document, $io var deregisterInstance = $ionicScrollDelegate._registerInstance( self, scrollViewOptions.delegateHandle, function() { - return !$scope.$$disconnected; + return !$scope.$$disconnected && $ionicHistory.currentHistoryId() == $scope.$historyId; } ); diff --git a/js/angular/controller/viewController.js b/js/angular/controller/viewController.js index 28e486e36b..3be14b5a80 100644 --- a/js/angular/controller/viewController.js +++ b/js/angular/controller/viewController.js @@ -4,9 +4,8 @@ IonicModule '$element', '$attrs', '$compile', - '$ionicHistory', '$ionicViewSwitcher', -function($scope, $element, $attrs, $compile, $ionicHistory, $ionicViewSwitcher) { +function($scope, $element, $attrs, $compile, $ionicViewSwitcher) { var self = this; var navElementHtml = {}; var navViewCtrl; @@ -44,8 +43,6 @@ function($scope, $element, $attrs, $compile, $ionicHistory, $ionicViewSwitcher) var viewTitle = $attrs.viewTitle || $attrs.title; - $ionicHistory.currentTitle(viewTitle); - var buttons = {}; for (var n in navElementHtml) { buttons[n] = generateButton(navElementHtml[n]); @@ -77,7 +74,6 @@ function($scope, $element, $attrs, $compile, $ionicHistory, $ionicViewSwitcher) if (viewTitleAttr) { deregisters.push($attrs.$observe(viewTitleAttr, function(val) { navViewCtrl.title(val); - $ionicHistory.currentTitle(val); })); } diff --git a/js/angular/service/delegateService.js b/js/angular/service/delegateService.js index 7ed6c76652..ff61d2c31d 100644 --- a/js/angular/service/delegateService.js +++ b/js/angular/service/delegateService.js @@ -1,5 +1,9 @@ function delegateService(methodNames) { + if (methodNames.indexOf('$getByHandle') > -1) { + throw new Error("Method '$getByHandle' is implicitly added to each delegate service. Do not list it as a method."); + } + function trueFn() { return true; } return ['$log', function($log) { @@ -90,7 +94,7 @@ function delegateService(methodNames) { //This logic is repeated above instances.forEach(function(instance, index) { - if (instance.$$filterFn()) { + if (instance.$$filterFn(instance)) { matchingInstancesFound++; result = instance[methodName].apply(instance, args); //Only return the value from the first call diff --git a/js/angular/service/history.js b/js/angular/service/history.js index d955622e73..3aaeab5a7c 100644 --- a/js/angular/service/history.js +++ b/js/angular/service/history.js @@ -444,6 +444,16 @@ function($rootScope, $state, $location, $window, $ionicViewSwitcher) { return viewHistory.currentView; }, + /** + * @ngdoc method + * @name $ionicHistory#currentHistoryId + * @description The ID of the history stack which is the parent container of the current view. + * @returns {string} Returns the current history ID. + */ + currentHistoryId: function() { + return viewHistory.currentView ? viewHistory.currentView.historyId : null; + }, + /** * @ngdoc method * @name $ionicHistory#currentTitle diff --git a/js/angular/service/scrollDelegate.js b/js/angular/service/scrollDelegate.js index f64d3ad785..c35f2158af 100644 --- a/js/angular/service/scrollDelegate.js +++ b/js/angular/service/scrollDelegate.js @@ -145,6 +145,5 @@ IonicModule * * Example: `$ionicScrollDelegate.$getByHandle('my-handle').scrollTop();` */ - '$getByHandle' ]));