source: trip-planner-front/node_modules/@angular/cdk/esm2015/overlay/scroll/block-scroll-strategy.js

Last change on this file was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 12.5 KB
Line 
1/**
2 * @license
3 * Copyright Google LLC All Rights Reserved.
4 *
5 * Use of this source code is governed by an MIT-style license that can be
6 * found in the LICENSE file at https://angular.io/license
7 */
8import { coerceCssPixelValue } from '@angular/cdk/coercion';
9import { supportsScrollBehavior } from '@angular/cdk/platform';
10const scrollBehaviorSupported = supportsScrollBehavior();
11/**
12 * Strategy that will prevent the user from scrolling while the overlay is visible.
13 */
14export class BlockScrollStrategy {
15 constructor(_viewportRuler, document) {
16 this._viewportRuler = _viewportRuler;
17 this._previousHTMLStyles = { top: '', left: '' };
18 this._isEnabled = false;
19 this._document = document;
20 }
21 /** Attaches this scroll strategy to an overlay. */
22 attach() { }
23 /** Blocks page-level scroll while the attached overlay is open. */
24 enable() {
25 if (this._canBeEnabled()) {
26 const root = this._document.documentElement;
27 this._previousScrollPosition = this._viewportRuler.getViewportScrollPosition();
28 // Cache the previous inline styles in case the user had set them.
29 this._previousHTMLStyles.left = root.style.left || '';
30 this._previousHTMLStyles.top = root.style.top || '';
31 // Note: we're using the `html` node, instead of the `body`, because the `body` may
32 // have the user agent margin, whereas the `html` is guaranteed not to have one.
33 root.style.left = coerceCssPixelValue(-this._previousScrollPosition.left);
34 root.style.top = coerceCssPixelValue(-this._previousScrollPosition.top);
35 root.classList.add('cdk-global-scrollblock');
36 this._isEnabled = true;
37 }
38 }
39 /** Unblocks page-level scroll while the attached overlay is open. */
40 disable() {
41 if (this._isEnabled) {
42 const html = this._document.documentElement;
43 const body = this._document.body;
44 const htmlStyle = html.style;
45 const bodyStyle = body.style;
46 const previousHtmlScrollBehavior = htmlStyle.scrollBehavior || '';
47 const previousBodyScrollBehavior = bodyStyle.scrollBehavior || '';
48 this._isEnabled = false;
49 htmlStyle.left = this._previousHTMLStyles.left;
50 htmlStyle.top = this._previousHTMLStyles.top;
51 html.classList.remove('cdk-global-scrollblock');
52 // Disable user-defined smooth scrolling temporarily while we restore the scroll position.
53 // See https://developer.mozilla.org/en-US/docs/Web/CSS/scroll-behavior
54 // Note that we don't mutate the property if the browser doesn't support `scroll-behavior`,
55 // because it can throw off feature detections in `supportsScrollBehavior` which
56 // checks for `'scrollBehavior' in documentElement.style`.
57 if (scrollBehaviorSupported) {
58 htmlStyle.scrollBehavior = bodyStyle.scrollBehavior = 'auto';
59 }
60 window.scroll(this._previousScrollPosition.left, this._previousScrollPosition.top);
61 if (scrollBehaviorSupported) {
62 htmlStyle.scrollBehavior = previousHtmlScrollBehavior;
63 bodyStyle.scrollBehavior = previousBodyScrollBehavior;
64 }
65 }
66 }
67 _canBeEnabled() {
68 // Since the scroll strategies can't be singletons, we have to use a global CSS class
69 // (`cdk-global-scrollblock`) to make sure that we don't try to disable global
70 // scrolling multiple times.
71 const html = this._document.documentElement;
72 if (html.classList.contains('cdk-global-scrollblock') || this._isEnabled) {
73 return false;
74 }
75 const body = this._document.body;
76 const viewport = this._viewportRuler.getViewportSize();
77 return body.scrollHeight > viewport.height || body.scrollWidth > viewport.width;
78 }
79}
80//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYmxvY2stc2Nyb2xsLXN0cmF0ZWd5LmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vLi4vLi4vLi4vc3JjL2Nkay9vdmVybGF5L3Njcm9sbC9ibG9jay1zY3JvbGwtc3RyYXRlZ3kudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7Ozs7OztHQU1HO0FBSUgsT0FBTyxFQUFDLG1CQUFtQixFQUFDLE1BQU0sdUJBQXVCLENBQUM7QUFDMUQsT0FBTyxFQUFDLHNCQUFzQixFQUFDLE1BQU0sdUJBQXVCLENBQUM7QUFFN0QsTUFBTSx1QkFBdUIsR0FBRyxzQkFBc0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