diff --git a/angular.json b/angular.json index 09b885e0..ea3d9500 100644 --- a/angular.json +++ b/angular.json @@ -42,7 +42,6 @@ "node_modules/@popperjs/core/dist/umd/popper.min.js", "node_modules/bootstrap/dist/js/bootstrap.min.js", "node_modules/golden-layout/dist/goldenlayout.min.js", - "src/assets/js/utils.js", ] }, "configurations": { @@ -110,7 +109,6 @@ "node_modules/@popperjs/core/dist/umd/popper.min.js", "node_modules/bootstrap/dist/js/bootstrap.min.js", "node_modules/golden-layout/dist/goldenlayout.min.js", - "src/assets/js/utils.js", ] } }, diff --git a/src/app/instructions/components/instructions.component.ts b/src/app/instructions/components/instructions.component.ts index 568b88be..e12029b7 100644 --- a/src/app/instructions/components/instructions.component.ts +++ b/src/app/instructions/components/instructions.component.ts @@ -4,9 +4,6 @@ import { Component } from '@angular/core'; import { AppConfig, Brand, Dashboard } from '@gcv/core/models'; -declare var scrollToSelector: any; // src/assets/js/utils - - @Component({ selector: 'gcv-instructions', styleUrls: [ './instructions.component.scss' ], @@ -26,7 +23,11 @@ export class InstructionsComponent { scrollTo(event): void { event.preventDefault(); const selector = event.target.hash; - scrollToSelector(selector); + const element = document.querySelector(selector); + if (element != null) { + const options = {behavior: "smooth", block: "start", inline: "nearest"}; + element.scrollIntoView(options); + } } } diff --git a/src/assets/js/utils.js b/src/assets/js/utils.js deleted file mode 100644 index dc6142b3..00000000 --- a/src/assets/js/utils.js +++ /dev/null @@ -1,78 +0,0 @@ -var documentReadyPromise = function () { - return new Promise((resolve) => { - document.addEventListener("readystatechange", (event) => { - if (event.target.readyState === "complete") { - resolve(); - } - }); - }); -}; - -var isVisible = function (selector) { - const element = document.querySelector(selector); - return element != null && - window.getComputedStyle(element).visibility == "visible" && - element.offsetWidth > 0; -}; - -var waitForElement = function (selector, options={}) { - options.callback = options.callback || ((element) => {}); - options.timeout = options.timeout || Infinity; - options.error = options.error || (() => {}); - var ms = 100; - const element = document.querySelector(selector); - if (element != null) { - options.callback(element); - } else if (options.timeout > 0) { - setTimeout(() => { - options.timeout -= ms; - waitForElement(selector, options); - }, ms); - } else { - options.error(); - } -}; - -var dispatchMouseEvent = function (mouseEvent, element) { - let e = document.createEvent("UIEvents"); - e.initUIEvent(mouseEvent, true, true, window, 1); - element.dispatchEvent(e); -}; - -var universalMouseEvent = function (mouseEvent, selector, options={}) { - var callback = options.callback || ((element) => {}); - options.callback = (element) => { - dispatchMouseEvent(mouseEvent, element); - callback(); - }; - options.timeout = options.timeout || 0; - options.error = options.error || (() => {}); - const element = document.querySelector(selector); - if (element !== null) { - options.callback(element); - } else if (options.timeout > 0) { - waitForElement(selector, options); - } -}; - -var universalMouseover = function (selector, options={}) { - universalMouseEvent("mouseover", selector, options); -}; - -var universalMouseout = function (selector, options={}) { - universalMouseEvent("mouseout", selector, options); -}; - -var universalClick = function (selector, options={}) { - universalMouseEvent("click", selector, options); -}; - -var scrollToSelector = function (selector, options={}) { - options.behavior = options.behavior || "smooth"; - options.block = options.block || "start"; - options.inline = options.inline || "nearest"; - const element = document.querySelector(selector); - if (element != null) { - element.scrollIntoView(options); - } -};