Sha256: 708b1973238c5782d0af0eaa56e3c0f733bb4f74d27b52eb8773e318b4c80b98

Contents?: true

Size: 1.13 KB

Versions: 41

Compression:

Stored size: 1.13 KB

Contents

function morph(from, to) {
  Alpine.morph(from, to, {
    key(el) {
      return el.getAttribute("key") ? el.getAttribute("key") : el.id;
    },
    lookahead: true,
    updating(el, toEl, childrenOnly, skip) {
      if (
        el.getAttribute &&
        el.getAttribute("data-morph-strategy") === "replace"
      ) {
        el.innerHTML = toEl.innerHTML;
        return skip();
      }
    },
  });
}

function getElementSize(el, opts = {}) {
  const style = window.getComputedStyle(el, null);
  return {
    width: opts.includeMargins
      ? el.offsetWidth +
        parseInt(style.getPropertyValue("margin-left")) +
        parseInt(style.getPropertyValue("margin-right"))
      : el.offsetWidth,
    height: opts.includeMargins
      ? el.offsetHeight +
        parseInt(style.getPropertyValue("margin-top")) +
        parseInt(style.getPropertyValue("margin-bottom"))
      : el.offsetHeight,
  };
}

function isExternalLink(link) {
  if (link.getAttribute("target") === "_blank") {
    return true;
  }
  if (link.href) {
    return link.host !== window.location.host;
  }
  return false;
}

export { morph, getElementSize, isExternalLink };

Version data entries

41 entries across 41 versions & 1 rubygems

Version Path
lookbook-1.5.5 app/assets/lookbook/js/helpers/dom.js
lookbook-1.5.4 app/assets/lookbook/js/helpers/dom.js
lookbook-1.5.3 app/assets/lookbook/js/helpers/dom.js
lookbook-1.5.2 app/assets/lookbook/js/helpers/dom.js
lookbook-1.5.1 app/assets/lookbook/js/helpers/dom.js
lookbook-1.5.0 app/assets/lookbook/js/helpers/dom.js
lookbook-1.4.5 app/assets/lookbook/js/helpers/dom.js
lookbook-1.4.4 app/assets/lookbook/js/helpers/dom.js
lookbook-1.4.3 app/assets/lookbook/js/helpers/dom.js
lookbook-1.4.2 app/assets/lookbook/js/helpers/dom.js
lookbook-1.4.1 app/assets/lookbook/js/helpers/dom.js
lookbook-1.4.0 app/assets/lookbook/js/helpers/dom.js
lookbook-1.3.4 app/assets/lookbook/js/helpers/dom.js
lookbook-1.3.3 app/assets/lookbook/js/helpers/dom.js
lookbook-1.3.1 app/assets/lookbook/js/helpers/dom.js
lookbook-1.3.0 app/assets/lookbook/js/helpers/dom.js
lookbook-1.2.1 app/assets/lookbook/js/helpers/dom.js
lookbook-1.2.0 app/assets/lookbook/js/helpers/dom.js
lookbook-1.1.1 app/assets/lookbook/js/helpers/dom.js
lookbook-1.1.0 app/assets/lookbook/js/helpers/dom.js