mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
feat($ionicScrollDelegate): rememberScrollPosition, scrollToRememberedPosition
/**
* @ngdoc method
* @name $ionicScrollDelegate#rememberScrollPosition
* @description
*
* When this scroll area is destroyed, its last scroll position will be
* saved using the given id.
*
* @param {string} id The identifier for this saved scroll position.
*/
/**
* @ngdoc method
* @name $ionicScrollDelegate#scrollToRememberedPosition
* @description
*
* If a scroll position was remembered using the given id, loads the
* remembered scroll position and scrolls there.
*
* @param {string} id The identifier for this saved scroll position.
* @param {boolean=} shouldAnimate Whether to animate the scroll.
*/
This commit is contained in:
@@ -81,63 +81,6 @@ describe('Ionic Content directive', function() {
|
||||
expect(vals.top).toBe(300);
|
||||
});
|
||||
|
||||
describe('save scroll', function() {
|
||||
|
||||
function compileWithParent() {
|
||||
var parent = angular.element('<div>');
|
||||
//Make a phony element that tells the world it's a navView when in reality it's just a div
|
||||
parent.data('$navViewController', true);
|
||||
parent.append('<ion-content><br/><div>hello</div><br/></ion-content>');
|
||||
compile(parent)(scope);
|
||||
scope.$apply();
|
||||
|
||||
/* Mock setting and getting scroll because we don't have time for the dom to load */
|
||||
var scrollValues = {};
|
||||
spyOn(scope.scrollView, 'scrollTo').andCallFake(function(left, top, a, zoom) {
|
||||
scrollValues = {
|
||||
left: left || 0,
|
||||
top: top || 0,
|
||||
zoom: zoom || 1
|
||||
};
|
||||
});
|
||||
spyOn(scope.scrollView, 'getValues').andCallFake(function() {
|
||||
return scrollValues;
|
||||
});
|
||||
}
|
||||
|
||||
it('should set x and y with historyData.scrollValues passed in through $viewContentLoaded', function() {
|
||||
compileWithParent();
|
||||
var scrollValues = { top: 40, left: -20, zoom: 3 };
|
||||
scope.$broadcast('$viewContentLoaded', {
|
||||
scrollValues: scrollValues
|
||||
});
|
||||
timeout.flush();
|
||||
expect(scope.scrollView.scrollTo.mostRecentCall.args).toEqual([-20, 40]);
|
||||
});
|
||||
|
||||
it('should set null with historyData.scrollValues not valid', function() {
|
||||
compileWithParent();
|
||||
var scrollValues = { left: 'bar', top: 'foo' };
|
||||
scope.$broadcast('$viewContentLoaded', { scrollValues: scrollValues });
|
||||
timeout.flush();
|
||||
expect(scope.scrollView.scrollTo.mostRecentCall.args).toEqual([null, null]);
|
||||
});
|
||||
|
||||
it('should save scroll on the historyData passed in on $destroy', function() {
|
||||
compileWithParent();
|
||||
var historyData = {};
|
||||
scope.$broadcast('$viewContentLoaded', historyData);
|
||||
timeout.flush();
|
||||
scope.scrollView.scrollTo(null, 9, false);
|
||||
expect(historyData.scrollValues).toBeUndefined(); //sanity test
|
||||
scope.$destroy();
|
||||
expect(historyData.scrollValues).toEqual({
|
||||
left: 0,
|
||||
top: 9,
|
||||
zoom: 1
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
/* Tests #555 */
|
||||
describe('Ionic Content Directive scoping', function() {
|
||||
|
||||
Reference in New Issue
Block a user