aboutsummaryrefslogtreecommitdiffstats
path: root/deprecated-workflow-designer/sdc-workflow-designer-ui/src/app/paletx/core/overlay/scroll/block-scroll-strategy.ts
diff options
context:
space:
mode:
authorvempo <vitaliy.emporopulo@amdocs.com>2018-07-24 17:34:04 +0300
committervempo <vitaliy.emporopulo@amdocs.com>2018-07-25 11:39:10 +0300
commita52d50e788792a63e97a9176ab319d53db7a2853 (patch)
treeb1c2222cacf4b8192aea16d1e0315b1f005c5347 /deprecated-workflow-designer/sdc-workflow-designer-ui/src/app/paletx/core/overlay/scroll/block-scroll-strategy.ts
parent3c2665debb400aef7f0ed9e235698d2ff9f859db (diff)
Replaced old implementation at root
Old project files and directories has been moved under 'deprecated-workflow-designer'. The old project is not built by the CI anymore, but can be still built manually. New modules/directories have been moved up and integrated with the CI system. Change-Id: I1528c792bcbcce9e50bfc294a1328a20e72c91cf Issue-ID: SDC-1559 Signed-off-by: vempo <vitaliy.emporopulo@amdocs.com>
Diffstat (limited to 'deprecated-workflow-designer/sdc-workflow-designer-ui/src/app/paletx/core/overlay/scroll/block-scroll-strategy.ts')
-rw-r--r--deprecated-workflow-designer/sdc-workflow-designer-ui/src/app/paletx/core/overlay/scroll/block-scroll-strategy.ts77
1 files changed, 77 insertions, 0 deletions
diff --git a/deprecated-workflow-designer/sdc-workflow-designer-ui/src/app/paletx/core/overlay/scroll/block-scroll-strategy.ts b/deprecated-workflow-designer/sdc-workflow-designer-ui/src/app/paletx/core/overlay/scroll/block-scroll-strategy.ts
new file mode 100644
index 00000000..d1c1d401
--- /dev/null
+++ b/deprecated-workflow-designer/sdc-workflow-designer-ui/src/app/paletx/core/overlay/scroll/block-scroll-strategy.ts
@@ -0,0 +1,77 @@
+/**
+ * @license
+ * Copyright Google Inc. All Rights Reserved.
+ *
+ * Use of this source code is governed by an MIT-style license that can be
+ * found in the LICENSE file at https://angular.io/license
+ */
+/* tslint:disable:array-type member-access variable-name typedef
+ only-arrow-functions directive-class-suffix component-class-suffix
+ component-selector*/
+import {ViewportRuler} from '../position/viewport-ruler';
+
+import {ScrollStrategy} from './scroll-strategy';
+
+/**
+ * Strategy that will prevent the user from scrolling while the overlay is
+ * visible.
+ */
+export class BlockScrollStrategy implements ScrollStrategy {
+ private _previousHTMLStyles = {top: '', left: ''};
+ private _previousScrollPosition: {top: number, left: number};
+ private _isEnabled = false;
+
+ constructor(private _viewportRuler: ViewportRuler) {}
+
+ attach() {
+ //
+ }
+
+ enable() {
+ if (this._canBeEnabled()) {
+ const root = document.documentElement;
+
+ this._previousScrollPosition =
+ this._viewportRuler.getViewportScrollPosition();
+
+ // Cache the previous inline styles in case the user had set them.
+ this._previousHTMLStyles.left = root.style.left || '';
+ this._previousHTMLStyles.top = root.style.top || '';
+
+ // Note: we're using the `html` node, instead of the `body`, because the
+ // `body` may have the user agent margin, whereas the `html` is guaranteed
+ // not to have one.
+ root.style.left = `${- this._previousScrollPosition.left}px`;
+ root.style.top = `${- this._previousScrollPosition.top}px`;
+ root.classList.add('cdk-global-scrollblock');
+ this._isEnabled = true;
+ }
+ }
+
+ disable() {
+ if (this._isEnabled) {
+ this._isEnabled = false;
+ document.documentElement.style.left = this._previousHTMLStyles.left;
+ document.documentElement.style.top = this._previousHTMLStyles.top;
+ document.documentElement.classList.remove('cdk-global-scrollblock');
+ window.scroll(
+ this._previousScrollPosition.left, this._previousScrollPosition.top);
+ }
+ }
+
+ private _canBeEnabled(): boolean {
+ // Since the scroll strategies can't be singletons, we have to use a global
+ // CSS class
+ // (`cdk-global-scrollblock`) to make sure that we don't try to disable
+ // global scrolling multiple times.
+ if (document.documentElement.classList.contains('cdk-global-scrollblock') ||
+ this._isEnabled) {
+ return false;
+ }
+
+ const body = document.body;
+ const viewport = this._viewportRuler.getViewportRect();
+ return body.scrollHeight > viewport.height ||
+ body.scrollWidth > viewport.width;
+ }
+}