All Downloads are FREE. Search and download functionalities are using the official Maven repository.

dotty_res.scripts.common.utils.js Maven / Gradle / Ivy

There is a newer version: 3.6.0-RC1-bin-20240903-21a3d39-NIGHTLY
Show newest version
const findRef = (searchBy, element = document) =>
  element.querySelector(searchBy);

const findRefs = (searchBy, element = document) =>
  element ? [...element.querySelectorAll(searchBy)] : [];

const withEvent = (element, listener, callback) => {
  element && element.addEventListener(listener, callback);
  return () => element && element.removeEventListener(listener, callback);
};

const attachDOM = (element, html) => {
  if (element) {
    element.innerHTML = htmlToString(html);
  }
};

const htmlToString = (html) => {
  if (Array.isArray(html)) {
    return html.join("");
  }
  return html;
};

const isFilterData = key => key.startsWith("f")

const getFilterKey = key => `f${key.charAt(0).toUpperCase()}${key.slice(1)}`

const attachListeners = (elementsRefs, type, callback) =>
  elementsRefs.map((elRef) => withEvent(elRef, type, callback));

const getElementTextContent = (element) => (element ? element.textContent : "");

const getElementDescription = (elementRef) =>
  findRef(".documentableBrief", elementRef);

const getElementNameRef = (elementRef) =>
  findRef(".documentableName", elementRef);




© 2015 - 2024 Weber Informatics LLC | Privacy Policy