mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
test(sideMenu2): update test to reflect changes
This commit is contained in:
@@ -6,7 +6,7 @@ angular.module('ionic.ui.scroll')
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
.controller('$ionicScroll', ['$scope', 'scrollViewOptions', '$timeout', '$ionicScrollDelegate', '$window', function($scope, scrollViewOptions, $timeout, $ionicScrollDelegate, $window) {
|
||||
.controller('$ionicScroll', ['$scope', 'scrollViewOptions', '$timeout', '$ionicScrollDelegate', '$window', '$ionicViewService', function($scope, scrollViewOptions, $timeout, $ionicScrollDelegate, $window, $ionicViewService) {
|
||||
|
||||
var self = this;
|
||||
|
||||
@@ -31,13 +31,17 @@ angular.module('ionic.ui.scroll')
|
||||
//Register delegate for event handling
|
||||
$ionicScrollDelegate.register($scope, $element, scrollView);
|
||||
|
||||
var resize = angular.bind(scrollView, scrollView.resize);
|
||||
$window.addEventListener('resize', resize);
|
||||
|
||||
$scope.$on('$destroy', function() {
|
||||
$window.removeEventListener('resize', resize);
|
||||
|
||||
var view = $ionicViewService.getCurrentView();
|
||||
if (view) {
|
||||
view.rememberedScrollValues = scrollView.getValues();
|
||||
}
|
||||
});
|
||||
function resize() {
|
||||
scrollView.resize();
|
||||
}
|
||||
|
||||
this.setRefresher = function(refresherScope, refresherElement) {
|
||||
var refresher = this.refresher = refresherElement;
|
||||
|
||||
17
js/ext/angular/src/directive/ionicContent.js
vendored
17
js/ext/angular/src/directive/ionicContent.js
vendored
@@ -136,21 +136,8 @@ function($parse, $timeout, $ionicScrollDelegate, $controller, $ionicBind) {
|
||||
//Publish scrollView to parent so children can access it
|
||||
scrollView = $scope.$parent.scrollView = scrollCtrl.scrollView;
|
||||
|
||||
$scope.$on('$viewContentLoaded', function(e, viewHistoryData) {
|
||||
viewHistoryData || (viewHistoryData = {});
|
||||
var scroll = viewHistoryData.scrollValues;
|
||||
if (scroll) {
|
||||
$timeout(function() {
|
||||
scrollView.scrollTo(+scroll.left || null, +scroll.top || null);
|
||||
}, 0);
|
||||
}
|
||||
|
||||
//Save scroll onto viewHistoryData when scope is destroyed
|
||||
$scope.$on('$destroy', function() {
|
||||
viewHistoryData.scrollValues = scrollView.getValues();
|
||||
});
|
||||
});
|
||||
|
||||
var delegate = $ionicScrollDelegate($scope);
|
||||
delegate.rememberScrollPosition();
|
||||
}
|
||||
|
||||
transclude($scope, function(clone) {
|
||||
|
||||
@@ -34,7 +34,7 @@ angular.module('ionic.ui.service.scrollDelegate', [])
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
.factory('$ionicScrollDelegate', ['$rootScope', '$timeout', '$location', function($rootScope, $timeout, $location) {
|
||||
.factory('$ionicScrollDelegate', ['$rootScope', '$timeout', '$location', '$ionicViewService', function($rootScope, $timeout, $location, $ionicViewService) {
|
||||
|
||||
function getScrollCtrl($scope) {
|
||||
var ctrl;
|
||||
@@ -131,6 +131,18 @@ angular.module('ionic.ui.service.scrollDelegate', [])
|
||||
}, element[0]);
|
||||
},
|
||||
|
||||
/**
|
||||
* @ngdoc method
|
||||
* @name $ionicScrollDelegate#rememberScrollPosition
|
||||
* @description Used on an instance of $ionicScrollDelegate.
|
||||
*
|
||||
* If this scroll area is associated with a view in the history,
|
||||
* load the last scroll position from the last time this view was shown.
|
||||
*/
|
||||
rememberScrollPosition: function(animate) {
|
||||
scrollScope.$broadcast('scroll.rememberPosition', !!animate);
|
||||
},
|
||||
|
||||
/**
|
||||
* @private
|
||||
* Attempt to get the current scroll view in scope (if any)
|
||||
@@ -204,6 +216,15 @@ angular.module('ionic.ui.service.scrollDelegate', [])
|
||||
}
|
||||
});
|
||||
});
|
||||
$scope.$on('scroll.rememberPosition', function(e, animate) {
|
||||
scrollViewResize().then(function() {
|
||||
var view = $ionicViewService.getCurrentView();
|
||||
var values = view && view.rememberedScrollValues;
|
||||
if (view && values) {
|
||||
scrollView.scrollTo(+values.left || null, +values.top || null, animate);
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
return ionicScrollDelegate;
|
||||
|
||||
2
js/ext/angular/src/service/ionicView.js
vendored
2
js/ext/angular/src/service/ionicView.js
vendored
@@ -231,7 +231,7 @@ angular.module('ionic.service.view', ['ui.router', 'ionic.service.platform'])
|
||||
stateName: this.getCurrentStateName(),
|
||||
stateParams: this.getCurrentStateParams(),
|
||||
url: $location.url(),
|
||||
scrollValues: null
|
||||
rememberedScrollValues: null
|
||||
});
|
||||
|
||||
// add the new view to this history's stack
|
||||
|
||||
@@ -190,7 +190,7 @@
|
||||
$urlRouterProvider.otherwise("/event/home");
|
||||
})
|
||||
|
||||
.controller('MainCtrl', function($scope, $ionicSideMenuDelegate) {
|
||||
.controller('MainCtrl', function($scope) {
|
||||
console.log('MainCtrl');
|
||||
|
||||
$scope.data = {
|
||||
@@ -198,7 +198,7 @@
|
||||
};
|
||||
|
||||
$scope.closeMenu = function() {
|
||||
$ionicSideMenuDelegate.close($scope);
|
||||
$scope.sideMenuController.toggleLeft(false);
|
||||
};
|
||||
|
||||
setTimeout(function(){
|
||||
|
||||
Reference in New Issue
Block a user