Sha256: fd975103c6dc4f2524f4f064a8c53a73052382ddc8504376cbe390678ff6defb

Contents?: true

Size: 1.02 KB

Versions: 8

Compression:

Stored size: 1.02 KB

Contents

function ready(callback: () => void) {
  if (document.readyState === "complete" ||
    (document.readyState !== "loading" && !document.documentElement.doScroll)) {
      callback();
    } else {
      document.addEventListener("DOMContentLoaded", callback);
    }
}

function applyGrid () {
  let showGrid = false;
  const gridOverlay = document.querySelector(".grid-overlay");

  const setState = (newState: boolean) => {
    showGrid = newState;

    if (newState) {
      window.localStorage.setItem("showGrid", "true");
      gridOverlay.classList.add("grid-overlay--active");
    } else {
      window.localStorage.removeItem("showGrid");
      gridOverlay.classList.remove("grid-overlay--active");
    }
  };

  if (gridOverlay) {
    setState(window.localStorage.getItem("showGrid") == "true");

    // Keyboard toggle
    document.addEventListener("keyup", (evt: KeyboardEvent) => {
      if (evt.ctrlKey && evt.which == 71) {
        setState(!showGrid);
      }
    });
  }
}

export default function gridOverlay() {
  ready(applyGrid);
}

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
pages_core-3.14.0 lib/rails/generators/pages_core/frontend/templates/javascript/lib/gridOverlay.ts
pages_core-3.13.0 lib/rails/generators/pages_core/frontend/templates/javascript/lib/gridOverlay.ts
pages_core-3.12.7 lib/rails/generators/pages_core/frontend/templates/javascript/lib/gridOverlay.ts
pages_core-3.12.6 lib/rails/generators/pages_core/frontend/templates/javascript/lib/gridOverlay.ts
pages_core-3.12.5 lib/rails/generators/pages_core/frontend/templates/javascript/lib/gridOverlay.ts
pages_core-3.12.4 lib/rails/generators/pages_core/frontend/templates/javascript/lib/gridOverlay.ts
pages_core-3.12.3 lib/rails/generators/pages_core/frontend/templates/javascript/lib/gridOverlay.ts
pages_core-3.12.2 lib/rails/generators/pages_core/frontend/templates/javascript/lib/gridOverlay.ts