mirror of
https://github.com/zhigang1992/angular.js.git
synced 2026-01-12 22:45:52 +08:00
fix($anchorScroll): don't scroll to top when initializing and location hash is empty
Closes #8848 Closes #9393
This commit is contained in:
@@ -106,6 +106,12 @@ describe('$anchorScroll', function() {
|
||||
|
||||
describe('watcher', function() {
|
||||
|
||||
function initAnchorScroll() {
|
||||
return function($rootScope, $anchorScroll) {
|
||||
$rootScope.$digest();
|
||||
};
|
||||
}
|
||||
|
||||
function initLocation(config) {
|
||||
return function($provide, $locationProvider) {
|
||||
$provide.value('$sniffer', {history: config.historyApi});
|
||||
@@ -135,6 +141,7 @@ describe('$anchorScroll', function() {
|
||||
it('should scroll to element when hash change in hashbang mode', function() {
|
||||
module(initLocation({html5Mode: false, historyApi: true}));
|
||||
inject(
|
||||
initAnchorScroll(),
|
||||
addElements('id=some'),
|
||||
changeHashTo('some'),
|
||||
expectScrollingTo('id=some')
|
||||
@@ -145,6 +152,7 @@ describe('$anchorScroll', function() {
|
||||
it('should scroll to element when hash change in html5 mode with no history api', function() {
|
||||
module(initLocation({html5Mode: true, historyApi: false}));
|
||||
inject(
|
||||
initAnchorScroll(),
|
||||
addElements('id=some'),
|
||||
changeHashTo('some'),
|
||||
expectScrollingTo('id=some')
|
||||
@@ -152,9 +160,17 @@ describe('$anchorScroll', function() {
|
||||
});
|
||||
|
||||
|
||||
it('should not scroll to the top if $anchorScroll is initializing and location hash is empty',
|
||||
inject(
|
||||
initAnchorScroll(),
|
||||
expectNoScrolling())
|
||||
);
|
||||
|
||||
|
||||
it('should not scroll when element does not exist', function() {
|
||||
module(initLocation({html5Mode: false, historyApi: false}));
|
||||
inject(
|
||||
initAnchorScroll(),
|
||||
addElements('id=some'),
|
||||
changeHashTo('other'),
|
||||
expectNoScrolling()
|
||||
@@ -165,6 +181,7 @@ describe('$anchorScroll', function() {
|
||||
it('should scroll when html5 mode with history api', function() {
|
||||
module(initLocation({html5Mode: true, historyApi: true}));
|
||||
inject(
|
||||
initAnchorScroll(),
|
||||
addElements('id=some'),
|
||||
changeHashTo('some'),
|
||||
expectScrollingTo('id=some')
|
||||
|
||||
Reference in New Issue
Block a user