Verified Commit 93279d3c authored by Théodore Biadala's avatar Théodore Biadala
Browse files

Issue #3531994 by tom konda: Replace for loop with forEach in active-links.js and displace.js

parent 42209999
Loading
Loading
Loading
Loading
Loading
+10 −15
Original line number Diff line number Diff line
@@ -50,24 +50,19 @@
      // Add query string selector for pagers, exposed filters.
      selectors = selectors.map((current) => current + querySelector);

      // Query the DOM.
      const activeLinks = context.querySelectorAll(selectors.join(','));
      const il = activeLinks.length;
      for (let i = 0; i < il; i++) {
        activeLinks[i].classList.add('is-active');
        activeLinks[i].setAttribute('aria-current', 'page');
      }
      context.querySelectorAll(selectors.join(',')).forEach((activeLink) => {
        activeLink.classList.add('is-active');
        activeLink.setAttribute('aria-current', 'page');
      });
    },
    detach(context, settings, trigger) {
      if (trigger === 'unload') {
        const activeLinks = context.querySelectorAll(
          '[data-drupal-link-system-path].is-active',
        );
        const il = activeLinks.length;
        for (let i = 0; i < il; i++) {
          activeLinks[i].classList.remove('is-active');
          activeLinks[i].removeAttribute('aria-current');
        }
        context
          .querySelectorAll('[data-drupal-link-system-path].is-active')
          .forEach((activeLink) => {
            activeLink.classList.remove('is-active');
            activeLink.removeAttribute('aria-current');
          });
      }
    },
  };
+3 −8
Original line number Diff line number Diff line
@@ -153,15 +153,10 @@
   */
  function calculateOffset(edge) {
    let edgeOffset = 0;
    const displacingElements = document.querySelectorAll(
      `[data-offset-${edge}]`,
    );
    const n = displacingElements.length;
    for (let i = 0; i < n; i++) {
      const el = displacingElements[i];
    document.querySelectorAll(`[data-offset-${edge}]`).forEach((el) => {
      // If the element is not visible, do consider its dimensions.
      if (el.style.display === 'none') {
        continue;
        return;
      }
      // If the offset data attribute contains a displacing value, use it.
      let displacement = parseInt(el.getAttribute(`data-offset-${edge}`), 10);
@@ -175,7 +170,7 @@
      // If the displacement value is larger than the current value for this
      // edge, use the displacement value.
      edgeOffset = Math.max(edgeOffset, displacement);
    }
    });

    return edgeOffset;
  }