-
Notifications
You must be signed in to change notification settings - Fork 3k
/
Copy pathviewScroll.ts
46 lines (40 loc) · 1.2 KB
/
viewScroll.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/** @publicapi @module ng1 */ /** */
import { ng as angular } from './angular';
import { IServiceProviderFactory } from 'angular';
import IAnchorScrollService = angular.IAnchorScrollService;
import ITimeoutService = angular.ITimeoutService;
export interface UIViewScrollProvider {
/**
* Uses standard anchorScroll behavior
*
* Reverts [[$uiViewScroll]] back to using the core [`$anchorScroll`](http://docs.angularjs.org/api/ng.$anchorScroll)
* service for scrolling based on the url anchor.
*/
useAnchorScroll(): void;
}
/** @hidden */
function $ViewScrollProvider() {
let useAnchorScroll = false;
this.useAnchorScroll = function () {
useAnchorScroll = true;
};
this.$get = [
'$anchorScroll',
'$timeout',
function ($anchorScroll: IAnchorScrollService, $timeout: ITimeoutService): Function {
if (useAnchorScroll) {
return $anchorScroll;
}
return function ($element: JQuery) {
return $timeout(
function () {
$element[0].scrollIntoView();
},
0,
false
);
};
},
];
}
angular.module('ui.router.state').provider('$uiViewScroll', <IServiceProviderFactory>$ViewScrollProvider);