parent
cee7448efc
commit
cf8ad24dcf
|
@ -11,7 +11,7 @@ import {defineInjectable, inject} from '@angular/core';
|
|||
import {DOCUMENT} from './dom_tokens';
|
||||
|
||||
/**
|
||||
* @whatItDoes Manages the scroll position.
|
||||
* Manages the scroll position.
|
||||
*/
|
||||
export abstract class ViewportScroller {
|
||||
// De-sugared tree-shakable injection
|
||||
|
@ -21,7 +21,7 @@ export abstract class ViewportScroller {
|
|||
{providedIn: 'root', factory: () => new BrowserViewportScroller(inject(DOCUMENT), window)});
|
||||
|
||||
/**
|
||||
* @whatItDoes Configures the top offset used when scrolling to an anchor.
|
||||
* Configures the top offset used when scrolling to an anchor.
|
||||
*
|
||||
* When given a tuple with two number, the service will always use the numbers.
|
||||
* When given a function, the service will invoke the function every time it restores scroll
|
||||
|
@ -30,22 +30,24 @@ export abstract class ViewportScroller {
|
|||
abstract setOffset(offset: [number, number]|(() => [number, number])): void;
|
||||
|
||||
/**
|
||||
* @whatItDoes Returns the current scroll position.
|
||||
* Returns the current scroll position.
|
||||
*/
|
||||
abstract getScrollPosition(): [number, number];
|
||||
|
||||
/**
|
||||
* @whatItDoes Sets the scroll position.
|
||||
* Sets the scroll position.
|
||||
*/
|
||||
abstract scrollToPosition(position: [number, number]): void;
|
||||
|
||||
/**
|
||||
* @whatItDoes Scrolls to the provided anchor.
|
||||
* Scrolls to the provided anchor.
|
||||
*/
|
||||
abstract scrollToAnchor(anchor: string): void;
|
||||
|
||||
/**
|
||||
* @whatItDoes Disables automatic scroll restoration provided by the browser.
|
||||
*
|
||||
* Disables automatic scroll restoration provided by the browser.
|
||||
*
|
||||
* See also [window.history.scrollRestoration
|
||||
* info](https://developers.google.com/web/updates/2015/09/history-api-scroll-restoration)
|
||||
*/
|
||||
|
@ -53,7 +55,7 @@ export abstract class ViewportScroller {
|
|||
}
|
||||
|
||||
/**
|
||||
* @whatItDoes Manages the scroll position.
|
||||
* Manages the scroll position.
|
||||
*/
|
||||
export class BrowserViewportScroller implements ViewportScroller {
|
||||
private offset: () => [number, number] = () => [0, 0];
|
||||
|
@ -61,7 +63,7 @@ export class BrowserViewportScroller implements ViewportScroller {
|
|||
constructor(private document: any, private window: any) {}
|
||||
|
||||
/**
|
||||
* @whatItDoes Configures the top offset used when scrolling to an anchor.
|
||||
* Configures the top offset used when scrolling to an anchor.
|
||||
*
|
||||
* * When given a number, the service will always use the number.
|
||||
* * When given a function, the service will invoke the function every time it restores scroll
|
||||
|
@ -76,7 +78,7 @@ export class BrowserViewportScroller implements ViewportScroller {
|
|||
}
|
||||
|
||||
/**
|
||||
* @whatItDoes Returns the current scroll position.
|
||||
* Returns the current scroll position.
|
||||
*/
|
||||
getScrollPosition(): [number, number] {
|
||||
if (this.supportScrollRestoration()) {
|
||||
|
@ -87,7 +89,7 @@ export class BrowserViewportScroller implements ViewportScroller {
|
|||
}
|
||||
|
||||
/**
|
||||
* @whatItDoes Sets the scroll position.
|
||||
* Sets the scroll position.
|
||||
*/
|
||||
scrollToPosition(position: [number, number]): void {
|
||||
if (this.supportScrollRestoration()) {
|
||||
|
@ -96,7 +98,7 @@ export class BrowserViewportScroller implements ViewportScroller {
|
|||
}
|
||||
|
||||
/**
|
||||
* @whatItDoes Scrolls to the provided anchor.
|
||||
* Scrolls to the provided anchor.
|
||||
*/
|
||||
scrollToAnchor(anchor: string): void {
|
||||
if (this.supportScrollRestoration()) {
|
||||
|
@ -114,7 +116,7 @@ export class BrowserViewportScroller implements ViewportScroller {
|
|||
}
|
||||
|
||||
/**
|
||||
* @whatItDoes Disables automatic scroll restoration provided by the browser.
|
||||
* Disables automatic scroll restoration provided by the browser.
|
||||
*/
|
||||
setHistoryScrollRestoration(scrollRestoration: 'auto'|'manual'): void {
|
||||
if (this.supportScrollRestoration()) {
|
||||
|
@ -152,32 +154,32 @@ export class BrowserViewportScroller implements ViewportScroller {
|
|||
|
||||
|
||||
/**
|
||||
* @whatItDoes Provides an empty implementation of the viewport scroller. This will
|
||||
* Provides an empty implementation of the viewport scroller. This will
|
||||
* live in @angular/common as it will be used by both platform-server and platform-webworker.
|
||||
*/
|
||||
export class NullViewportScroller implements ViewportScroller {
|
||||
/**
|
||||
* @whatItDoes empty implementation
|
||||
* Empty implementation
|
||||
*/
|
||||
setOffset(offset: [number, number]|(() => [number, number])): void {}
|
||||
|
||||
/**
|
||||
* @whatItDoes empty implementation
|
||||
* Empty implementation
|
||||
*/
|
||||
getScrollPosition(): [number, number] { return [0, 0]; }
|
||||
|
||||
/**
|
||||
* @whatItDoes empty implementation
|
||||
* Empty implementation
|
||||
*/
|
||||
scrollToPosition(position: [number, number]): void {}
|
||||
|
||||
/**
|
||||
* @whatItDoes empty implementation
|
||||
* Empty implementation
|
||||
*/
|
||||
scrollToAnchor(anchor: string): void {}
|
||||
|
||||
/**
|
||||
* @whatItDoes empty implementation
|
||||
* Empty implementation
|
||||
*/
|
||||
setHistoryScrollRestoration(scrollRestoration: 'auto'|'manual'): void {}
|
||||
}
|
Loading…
Reference in New Issue