You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lo...@apache.org on 2021/10/21 10:01:42 UTC
[myfaces-tobago] branch master updated: refactor: cleanup
This is an automated email from the ASF dual-hosted git repository.
lofwyr pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/myfaces-tobago.git
The following commit(s) were added to refs/heads/master by this push:
new d9d5c30 refactor: cleanup
d9d5c30 is described below
commit d9d5c3084b321bb8bfd4673524f6ae31193ee71d
Author: Udo Schnurpfeil <ud...@irian.eu>
AuthorDate: Thu Oct 21 11:16:39 2021 +0200
refactor: cleanup
---
.../tobago-theme-standard/src/main/js/tobago.js | 69 +++++-----------------
.../src/main/js/tobago.js.map | 2 +-
.../src/main/js/tobago.min.js | 4 +-
.../src/main/js/tobago.min.js.map | 2 +-
.../src/main/resources/META-INF/tobago-config.xml | 28 ---------
.../src/main/ts/tobago-all.ts | 1 -
.../src/main/ts/tobago-bar.ts | 18 ++++--
.../src/main/ts/tobago-behavior.ts | 8 ++-
.../src/main/ts/tobago-focus.ts | 1 -
.../src/main/ts/tobago-select-boolean-checkbox.ts | 1 -
.../src/main/ts/tobago-select-one-choice.ts | 1 -
.../src/main/ts/tobago-stars.ts | 4 +-
.../src/main/ts/tobago-textarea.ts | 1 -
.../src/main/ts/tobago-tree-listbox.ts | 2 -
.../src/main/ts/tobago-utils.ts | 51 ----------------
15 files changed, 40 insertions(+), 153 deletions(-)
diff --git a/tobago-theme/tobago-theme-standard/src/main/js/tobago.js b/tobago-theme/tobago-theme-standard/src/main/js/tobago.js
index 501bd97..4302b8f 100644
--- a/tobago-theme/tobago-theme-standard/src/main/js/tobago.js
+++ b/tobago-theme/tobago-theme-standard/src/main/js/tobago.js
@@ -19,55 +19,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
- // XXX remove me, for cleanup
- class DomUtils {
- /**
- * Find all elements (and also self) which have the attribute "attributeName".
- * @param element Starting element in DOM to collect.
- * @param selectors Name of the attribute of the elements to find.
- */
- // todo: may return NodeListOf<HTMLElementTagNameMap[K]> or something like that.
- static selfOrQuerySelectorAll(element, selectors) {
- const result = new Array();
- if (!element) {
- element = document.documentElement;
- }
- if (element.matches(selectors)) {
- result.push(element);
- }
- for (const found of element.querySelectorAll(selectors)) {
- result.push(found);
- }
- return result;
- }
- /**
- * @param element with transition
- * @return transition time in milliseconds
- */
- static getTransitionTime(element) {
- const style = window.getComputedStyle(element);
- const delay = Number.parseFloat(style.transitionDelay);
- const duration = Number.parseFloat(style.transitionDuration);
- return (delay + duration) * 1000;
- }
- }
-
- /*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
class Bar extends HTMLElement {
constructor() {
super();
@@ -95,7 +46,7 @@
this.navbarContent.classList.remove(this.CssClass.COLLAPSING);
this.navbarContent.classList.add(this.CssClass.COLLAPSE);
this.toggleButton.ariaExpanded = "false";
- }, DomUtils.getTransitionTime(this.navbarContent));
+ }, this.evaluateTransitionTime());
}
else {
this.expanded = true;
@@ -108,9 +59,20 @@
this.navbarContent.classList.add(this.CssClass.SHOW);
this.navbarContent.style.height = null;
this.toggleButton.ariaExpanded = "true";
- }, DomUtils.getTransitionTime(this.navbarContent));
+ }, this.evaluateTransitionTime());
}
}
+ /**
+ * Evaluates the transition time of the content from CSS properties.
+ *
+ * @return transition time in milliseconds
+ */
+ evaluateTransitionTime() {
+ const style = window.getComputedStyle(this.navbarContent);
+ const delay = Number.parseFloat(style.transitionDelay);
+ const duration = Number.parseFloat(style.transitionDuration);
+ return (delay + duration) * 1000;
+ }
get toggleButton() {
return this.querySelector(".navbar-toggler");
}
@@ -7274,7 +7236,7 @@
case "resize":
document.body.addEventListener(this.event, this.callback.bind(this));
break;
- default:
+ default: {
const eventElement = this.eventElement;
if (eventElement) {
eventElement.addEventListener(this.event, this.callback.bind(this));
@@ -7285,6 +7247,7 @@
// todo: not sure if this warning can be removed;
console.warn("Can't find an element for the event. Use parentElement instead.", this);
}
+ }
}
}
callback(event) {
@@ -7355,7 +7318,7 @@
const overlay = this.closest("body").querySelector(`tobago-overlay[for='${page.id}']`);
overlay.remove();
page.submitActive = false;
- alert(`Submit failed: ${e}`); // XXX localization, better error handling
+ alert("Submit failed!"); // XXX localization, better error handling
}
if (this.target) {
if (oldTarget) {
diff --git a/tobago-theme/tobago-theme-standard/src/main/js/tobago.js.map b/tobago-theme/tobago-theme-standard/src/main/js/tobago.js.map
index b74d3ce..583f95e 100644
--- a/tobago-theme/tobago-theme-standard/src/main/js/tobago.js.map
+++ b/tobago-theme/tobago-theme-standard/src/main/js/tobago.js.map
@@ -1 +1 @@
-{"version":3,"file":"tobago.js","sources":["../ts/tobago-utils.ts","../ts/tobago-bar.ts","../../../../node_modules/@popperjs/core/lib/enums.js","../../../../node_modules/@popperjs/core/lib/dom-utils/getNodeName.js","../../../../node_modules/@popperjs/core/lib/dom-utils/getWindow.js","../../../../node_modules/@popperjs/core/lib/dom-utils/instanceOf.js","../../../../node_modules/@popperjs/core/lib/modifiers/applyStyles.js","../../../../node_modules/@popperjs/core/lib/utils/getBasePlacement [...]
\ No newline at end of file
+{"version":3,"file":"tobago.js","sources":["../ts/tobago-bar.ts","../../../../node_modules/@popperjs/core/lib/enums.js","../../../../node_modules/@popperjs/core/lib/dom-utils/getNodeName.js","../../../../node_modules/@popperjs/core/lib/dom-utils/getWindow.js","../../../../node_modules/@popperjs/core/lib/dom-utils/instanceOf.js","../../../../node_modules/@popperjs/core/lib/modifiers/applyStyles.js","../../../../node_modules/@popperjs/core/lib/utils/getBasePlacement.js","../../../../node_m [...]
\ No newline at end of file
diff --git a/tobago-theme/tobago-theme-standard/src/main/js/tobago.min.js b/tobago-theme/tobago-theme-standard/src/main/js/tobago.min.js
index 40b5d0a..dd229e0 100644
--- a/tobago-theme/tobago-theme-standard/src/main/js/tobago.min.js
+++ b/tobago-theme/tobago-theme-standard/src/main/js/tobago.min.js
@@ -1,8 +1,8 @@
-!function(e){"function"==typeof define&&define.amd?define(e):e()}((function(){"use strict";class e{static selfOrQuerySelectorAll(e,t){const s=new Array;e||(e=document.documentElement),e.matches(t)&&s.push(e);for(const n of e.querySelectorAll(t))s.push(n);return s}static getTransitionTime(e){const t=window.getComputedStyle(e);return 1e3*(Number.parseFloat(t.transitionDelay)+Number.parseFloat(t.transitionDuration))}}class t extends HTMLElement{constructor(){super(),this.CssClass={SHOW:"sho [...]
+!function(e){"function"==typeof define&&define.amd?define(e):e()}((function(){"use strict";class e extends HTMLElement{constructor(){super(),this.CssClass={SHOW:"show",COLLAPSE:"collapse",COLLAPSING:"collapsing"},this.toggleButton.addEventListener("click",this.toggleCollapse.bind(this))}connectedCallback(){this.expanded="true"===this.toggleButton.ariaExpanded}toggleCollapse(e){window.clearTimeout(this.timeout),this.expanded?(this.expanded=!1,this.navbarContent.style.height=`${this.navbar [...]
/*!
* Bootstrap v5.1.3 (https://getbootstrap.com/)
* Copyright 2011-2021 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
*/
-const Re="transitionend",De=e=>{let t=e.getAttribute("data-bs-target");if(!t||"#"===t){let s=e.getAttribute("href");if(!s||!s.includes("#")&&!s.startsWith("."))return null;s.includes("#")&&!s.startsWith("#")&&(s=`#${s.split("#")[1]}`),t=s&&"#"!==s?s.trim():null}return t},Me=e=>{const t=De(e);return t&&document.querySelector(t)?t:null},je=e=>{const t=De(e);return t?document.querySelector(t):null},He=e=>{e.dispatchEvent(new Event(Re))},Be=e=>!(!e||"object"!=typeof e)&&(void 0!==e.jquery&&( [...]
+const Ne="transitionend",Re=e=>{let t=e.getAttribute("data-bs-target");if(!t||"#"===t){let s=e.getAttribute("href");if(!s||!s.includes("#")&&!s.startsWith("."))return null;s.includes("#")&&!s.startsWith("#")&&(s=`#${s.split("#")[1]}`),t=s&&"#"!==s?s.trim():null}return t},De=e=>{const t=Re(e);return t&&document.querySelector(t)?t:null},Me=e=>{const t=Re(e);return t?document.querySelector(t):null},je=e=>{e.dispatchEvent(new Event(Ne))},He=e=>!(!e||"object"!=typeof e)&&(void 0!==e.jquery&&( [...]
//# sourceMappingURL=tobago.min.js.map
diff --git a/tobago-theme/tobago-theme-standard/src/main/js/tobago.min.js.map b/tobago-theme/tobago-theme-standard/src/main/js/tobago.min.js.map
index de9aa24..43f3a72 100644
--- a/tobago-theme/tobago-theme-standard/src/main/js/tobago.min.js.map
+++ b/tobago-theme/tobago-theme-standard/src/main/js/tobago.min.js.map
@@ -1 +1 @@
-{"version":3,"file":"tobago.min.js","sources":["../ts/tobago-utils.ts","../ts/tobago-bar.ts","../../../../node_modules/@popperjs/core/lib/enums.js","../../../../node_modules/@popperjs/core/lib/dom-utils/getNodeName.js","../../../../node_modules/@popperjs/core/lib/dom-utils/getWindow.js","../../../../node_modules/@popperjs/core/lib/dom-utils/instanceOf.js","../../../../node_modules/@popperjs/core/lib/modifiers/applyStyles.js","../../../../node_modules/@popperjs/core/lib/utils/getBasePlace [...]
\ No newline at end of file
+{"version":3,"file":"tobago.min.js","sources":["../ts/tobago-bar.ts","../../../../node_modules/@popperjs/core/lib/enums.js","../../../../node_modules/@popperjs/core/lib/dom-utils/getNodeName.js","../../../../node_modules/@popperjs/core/lib/dom-utils/getWindow.js","../../../../node_modules/@popperjs/core/lib/dom-utils/instanceOf.js","../../../../node_modules/@popperjs/core/lib/modifiers/applyStyles.js","../../../../node_modules/@popperjs/core/lib/utils/getBasePlacement.js","../../../../no [...]
\ No newline at end of file
diff --git a/tobago-theme/tobago-theme-standard/src/main/resources/META-INF/tobago-config.xml b/tobago-theme/tobago-theme-standard/src/main/resources/META-INF/tobago-config.xml
index b19cde9..11b9cee 100644
--- a/tobago-theme/tobago-theme-standard/src/main/resources/META-INF/tobago-config.xml
+++ b/tobago-theme/tobago-theme-standard/src/main/resources/META-INF/tobago-config.xml
@@ -48,34 +48,6 @@
<includes>
<script name="/tobago/standard/${project.version}/js/jsf-development.js"/>
<script type="module" name="/tobago/standard/${project.version}/js/tobago.js"/>
-<!--
- <script name="/tobago/standard/${project.version}/js/ext-bootstrap.js"/>
- <script name="/tobago/standard/${project.version}/js/tobago-listener.js"/>
- <script name="/tobago/standard/${project.version}/js/tobago-core.js"/>
- <script name="/tobago/standard/${project.version}/js/tobago-dropdown.js"/>
- <script name="/tobago/standard/${project.version}/js/tobago-date.js"/>
- <script name="/tobago/standard/${project.version}/js/tobago-command.js"/>
- <script name="/tobago/standard/${project.version}/js/tobago-file.js"/>
- <script name="/tobago/standard/${project.version}/js/tobago-focus.js"/>
- <script name="/tobago/standard/${project.version}/js/tobago-header-footer.js"/>
- <script name="/tobago/standard/${project.version}/js/tobago-in.js"/>
- <script name="/tobago/standard/${project.version}/js/tobago-jsf.js"/>
- <script name="/tobago/standard/${project.version}/js/tobago-overlay.js"/>
- <script name="/tobago/standard/${project.version}/js/tobago-panel.js"/>
- <script name="/tobago/standard/${project.version}/js/tobago-popover.js"/>
- <script name="/tobago/standard/${project.version}/js/tobago-popup.js"/>
- <script name="/tobago/standard/${project.version}/js/tobago-reload.js"/>
- <script name="/tobago/standard/${project.version}/js/tobago-scroll.js"/>
- <script name="/tobago/standard/${project.version}/js/tobago-select-....js"/>
- <script name="/tobago/standard/${project.version}/js/tobago-sheet.js"/>
- <script name="/tobago/standard/${project.version}/js/tobago-split-layout.js"/>
- <script name="/tobago/standard/${project.version}/js/tobago-stars.js"/>
- <script name="/tobago/standard/${project.version}/js/tobago-suggest.js"/>
- <script name="/tobago/standard/${project.version}/js/tobago-tab.js"/>
- <script name="/tobago/standard/${project.version}/js/tobago-tree.js"/>
- <script name="/tobago/standard/${project.version}/js/tobago-tree-listbox.js"/>
- <script name="/tobago/standard/${project.version}/js/tobago-utils.js"/>
--->
<style name="/tobago/standard/${project.version}/css/tobago.css"/>
<style name="/tobago/standard/${project.version}/css/bootstrap-icons.css"/>
</includes>
diff --git a/tobago-theme/tobago-theme-standard/src/main/ts/tobago-all.ts b/tobago-theme/tobago-theme-standard/src/main/ts/tobago-all.ts
index 8f41cef..15bd6e2 100644
--- a/tobago-theme/tobago-theme-standard/src/main/ts/tobago-all.ts
+++ b/tobago-theme/tobago-theme-standard/src/main/ts/tobago-all.ts
@@ -52,7 +52,6 @@ import "./tobago-tree";
import "./tobago-tree-listbox";
import "./tobago-tree-node";
import "./tobago-tree-select";
-import "./tobago-utils";
if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded",
diff --git a/tobago-theme/tobago-theme-standard/src/main/ts/tobago-bar.ts b/tobago-theme/tobago-theme-standard/src/main/ts/tobago-bar.ts
index fa0ebe9..ebc3f4c 100644
--- a/tobago-theme/tobago-theme-standard/src/main/ts/tobago-bar.ts
+++ b/tobago-theme/tobago-theme-standard/src/main/ts/tobago-bar.ts
@@ -15,8 +15,6 @@
* limitations under the License.
*/
-import {DomUtils} from "./tobago-utils";
-
class Bar extends HTMLElement {
private readonly CssClass = {
@@ -53,7 +51,7 @@ class Bar extends HTMLElement {
this.navbarContent.classList.remove(this.CssClass.COLLAPSING);
this.navbarContent.classList.add(this.CssClass.COLLAPSE);
this.toggleButton.ariaExpanded = "false";
- }, DomUtils.getTransitionTime(this.navbarContent));
+ }, this.evaluateTransitionTime());
} else {
this.expanded = true;
this.navbarContent.classList.remove(this.CssClass.COLLAPSE);
@@ -66,10 +64,22 @@ class Bar extends HTMLElement {
this.navbarContent.classList.add(this.CssClass.SHOW);
this.navbarContent.style.height = null;
this.toggleButton.ariaExpanded = "true";
- }, DomUtils.getTransitionTime(this.navbarContent));
+ }, this.evaluateTransitionTime());
}
}
+ /**
+ * Evaluates the transition time of the content from CSS properties.
+ *
+ * @return transition time in milliseconds
+ */
+ private evaluateTransitionTime(): number {
+ const style = window.getComputedStyle(this.navbarContent);
+ const delay: number = Number.parseFloat(style.transitionDelay);
+ const duration: number = Number.parseFloat(style.transitionDuration);
+ return (delay + duration) * 1000;
+ }
+
private get toggleButton(): HTMLButtonElement {
return this.querySelector(".navbar-toggler");
}
diff --git a/tobago-theme/tobago-theme-standard/src/main/ts/tobago-behavior.ts b/tobago-theme/tobago-theme-standard/src/main/ts/tobago-behavior.ts
index 4eb8b2d..841750f 100644
--- a/tobago-theme/tobago-theme-standard/src/main/ts/tobago-behavior.ts
+++ b/tobago-theme/tobago-theme-standard/src/main/ts/tobago-behavior.ts
@@ -34,7 +34,7 @@ class Behavior extends HTMLElement {
case "resize":
document.body.addEventListener(this.event, this.callback.bind(this));
break;
- default:
+ default: {
const eventElement = this.eventElement;
if (eventElement) {
eventElement.addEventListener(this.event, this.callback.bind(this));
@@ -44,6 +44,7 @@ class Behavior extends HTMLElement {
// todo: not sure if this warning can be removed;
console.warn("Can't find an element for the event. Use parentElement instead.", this);
}
+ }
}
}
@@ -70,7 +71,8 @@ class Behavior extends HTMLElement {
const partialId = partialIds[i];
const partialElement = document.getElementById(partialId);
if (partialElement) {
- partialElement.insertAdjacentHTML("beforeend", `<tobago-overlay for='${partialElement.id}'></tobago-overlay>`);
+ partialElement.insertAdjacentHTML(
+ "beforeend", `<tobago-overlay for='${partialElement.id}'></tobago-overlay>`);
} else {
console.warn("No element found by id='%s' for overlay!", partialId);
}
@@ -124,7 +126,7 @@ class Behavior extends HTMLElement {
const overlay = this.closest("body").querySelector(`tobago-overlay[for='${page.id}']`);
overlay.remove();
page.submitActive = false;
- alert(`Submit failed: ${e}`); // XXX localization, better error handling
+ alert("Submit failed!"); // XXX localization, better error handling
}
if (this.target) {
if (oldTarget) {
diff --git a/tobago-theme/tobago-theme-standard/src/main/ts/tobago-focus.ts b/tobago-theme/tobago-theme-standard/src/main/ts/tobago-focus.ts
index c5c486b..30f648c 100644
--- a/tobago-theme/tobago-theme-standard/src/main/ts/tobago-focus.ts
+++ b/tobago-theme/tobago-theme-standard/src/main/ts/tobago-focus.ts
@@ -16,7 +16,6 @@
*/
import {Page} from "./tobago-page";
-import {DomUtils} from "./tobago-utils";
export class Focus extends HTMLElement {
diff --git a/tobago-theme/tobago-theme-standard/src/main/ts/tobago-select-boolean-checkbox.ts b/tobago-theme/tobago-theme-standard/src/main/ts/tobago-select-boolean-checkbox.ts
index c087860..1dc20f3 100644
--- a/tobago-theme/tobago-theme-standard/src/main/ts/tobago-select-boolean-checkbox.ts
+++ b/tobago-theme/tobago-theme-standard/src/main/ts/tobago-select-boolean-checkbox.ts
@@ -15,7 +15,6 @@
* limitations under the License.
*/
-import {DomUtils} from "./tobago-utils";
import {Focus} from "./tobago-focus";
export class SelectBooleanCheckbox extends HTMLElement {
diff --git a/tobago-theme/tobago-theme-standard/src/main/ts/tobago-select-one-choice.ts b/tobago-theme/tobago-theme-standard/src/main/ts/tobago-select-one-choice.ts
index 0e2d0e5..ee3435d 100644
--- a/tobago-theme/tobago-theme-standard/src/main/ts/tobago-select-one-choice.ts
+++ b/tobago-theme/tobago-theme-standard/src/main/ts/tobago-select-one-choice.ts
@@ -15,7 +15,6 @@
* limitations under the License.
*/
-import {DomUtils} from "./tobago-utils";
import {Focus} from "./tobago-focus";
class SelectOneChoice extends HTMLElement {
diff --git a/tobago-theme/tobago-theme-standard/src/main/ts/tobago-stars.ts b/tobago-theme/tobago-theme-standard/src/main/ts/tobago-stars.ts
index 95116fb..6e825c2 100644
--- a/tobago-theme/tobago-theme-standard/src/main/ts/tobago-stars.ts
+++ b/tobago-theme/tobago-theme-standard/src/main/ts/tobago-stars.ts
@@ -15,8 +15,6 @@
* limitations under the License.
*/
-import {DomUtils} from "./tobago-utils";
-
class Stars extends HTMLElement {
constructor() {
@@ -173,6 +171,6 @@ class Stars extends HTMLElement {
}
}
-document.addEventListener("DOMContentLoaded", function (event:Event): void {
+document.addEventListener("DOMContentLoaded", function (event: Event): void {
window.customElements.define("tobago-stars", Stars);
});
diff --git a/tobago-theme/tobago-theme-standard/src/main/ts/tobago-textarea.ts b/tobago-theme/tobago-theme-standard/src/main/ts/tobago-textarea.ts
index bd27f61..1adca83 100644
--- a/tobago-theme/tobago-theme-standard/src/main/ts/tobago-textarea.ts
+++ b/tobago-theme/tobago-theme-standard/src/main/ts/tobago-textarea.ts
@@ -15,7 +15,6 @@
* limitations under the License.
*/
-import {DomUtils} from "./tobago-utils";
import {Focus} from "./tobago-focus";
class Textarea extends HTMLElement {
diff --git a/tobago-theme/tobago-theme-standard/src/main/ts/tobago-tree-listbox.ts b/tobago-theme/tobago-theme-standard/src/main/ts/tobago-tree-listbox.ts
index 1f03612..ed3a80e 100644
--- a/tobago-theme/tobago-theme-standard/src/main/ts/tobago-tree-listbox.ts
+++ b/tobago-theme/tobago-theme-standard/src/main/ts/tobago-tree-listbox.ts
@@ -15,8 +15,6 @@
* limitations under the License.
*/
-import {DomUtils} from "./tobago-utils";
-
class TreeListbox extends HTMLElement {
constructor() {
diff --git a/tobago-theme/tobago-theme-standard/src/main/ts/tobago-utils.ts b/tobago-theme/tobago-theme-standard/src/main/ts/tobago-utils.ts
deleted file mode 100644
index 55c84e7..0000000
--- a/tobago-theme/tobago-theme-standard/src/main/ts/tobago-utils.ts
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-// XXX remove me, for cleanup
-export class DomUtils {
-
- /**
- * Find all elements (and also self) which have the attribute "attributeName".
- * @param element Starting element in DOM to collect.
- * @param selectors Name of the attribute of the elements to find.
- */
- // todo: may return NodeListOf<HTMLElementTagNameMap[K]> or something like that.
- static selfOrQuerySelectorAll(element: HTMLElement, selectors: string): Array<HTMLElement> {
- const result: Array<HTMLElement> = new Array<HTMLElement>();
- if (!element) {
- element = document.documentElement;
- }
- if (element.matches(selectors)) {
- result.push(element);
- }
- for (const found of element.querySelectorAll(selectors)) {
- result.push(found as HTMLElement);
- }
- return result;
- }
-
- /**
- * @param element with transition
- * @return transition time in milliseconds
- */
- static getTransitionTime(element: HTMLElement): number {
- const style = window.getComputedStyle(element);
- const delay: number = Number.parseFloat(style.transitionDelay);
- const duration: number = Number.parseFloat(style.transitionDuration);
- return (delay + duration) * 1000;
- }
-}