mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-30 21:10:29 +00:00
fix($autoScroll): scroll even if $location is in html5 mode
+ use autoscroll in docs (ng:include)
This commit is contained in:
parent
5164ae545b
commit
249c89c091
3 changed files with 10 additions and 15 deletions
|
|
@ -117,10 +117,8 @@
|
|||
|
||||
<div class="content-panel">
|
||||
<h2 ng:bind="partialTitle | title"></h2>
|
||||
<ng:include id="content"
|
||||
class="content-panel-content"
|
||||
src="getCurrentPartial()"
|
||||
onload="afterPartialLoaded()"></ng:include>
|
||||
<ng:include id="content" class="content-panel-content" autoscroll
|
||||
src="getCurrentPartial()" onload="afterPartialLoaded()"></ng:include>
|
||||
</div>
|
||||
|
||||
<div id="disqus" class="content-panel">
|
||||
|
|
|
|||
|
|
@ -10,9 +10,7 @@
|
|||
* according to rules specified in
|
||||
* {@link http://dev.w3.org/html5/spec/Overview.html#the-indicated-part-of-the-document Html5 spec}.
|
||||
*
|
||||
* If `$location` uses `hashbang` url (running in `hashbang` mode or `html5` mode on browser without
|
||||
* history API support), `$autoScroll` watches the `$location.hash()` and scroll whenever it
|
||||
* changes.
|
||||
* It also watches the `$location.hash()` and scroll whenever it changes to match any anchor.
|
||||
*
|
||||
* You can disable `$autoScroll` service by calling `disable()` on `$autoScrollProvider`.
|
||||
* Note: disabling is only possible before the service is instantiated !
|
||||
|
|
@ -54,12 +52,11 @@ function $AutoScrollProvider() {
|
|||
else if (hash === 'top') $window.scrollTo(0, 0);
|
||||
}
|
||||
|
||||
// scroll whenever hash changes (with hashbang url, regular urls are handled by browser)
|
||||
if ($location instanceof LocationHashbangUrl) {
|
||||
$rootScope.$watch(function() {return $location.hash();}, function() {
|
||||
$rootScope.$evalAsync(scroll);
|
||||
});
|
||||
}
|
||||
// does not scroll when user clicks on anchor link that is currently on
|
||||
// (no url change, no $locaiton.hash() change), browser native does scroll
|
||||
$rootScope.$watch(function() {return $location.hash();}, function() {
|
||||
$rootScope.$evalAsync(scroll);
|
||||
});
|
||||
|
||||
return scroll;
|
||||
}];
|
||||
|
|
|
|||
|
|
@ -169,12 +169,12 @@ describe('$autoScroll', function() {
|
|||
});
|
||||
|
||||
|
||||
it('should not scroll when html5 mode with history api', function() {
|
||||
it('should scroll when html5 mode with history api', function() {
|
||||
module(initLocation({html5Mode: true, historyApi: true}));
|
||||
inject(
|
||||
addElements('id=some'),
|
||||
changeHashAndDigest('some'),
|
||||
expectNoScrolling()
|
||||
expectScrollingTo('id=some')
|
||||
);
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue