Sha256: 7ad041cae37d6c1b3859a3d73075284f239dc9277823b6df26dbd69ef48a5445

Contents?: true

Size: 880 Bytes

Versions: 8

Compression:

Stored size: 880 Bytes

Contents

import { getAlpineData } from "../lib/utils";

export default function nav() {
  return {
    empty: false,
    init() {
      this.$watch("$store.filter.text", () => this.filter());
      this.$nextTick(() => {
        this.setActive();
        this.filter();
      });
    },
    filter() {
      this.empty = true;
      this.getChildren().forEach((child) => {
        const data = getAlpineData(child);
        data.filter(this.$store.filter.text);
        if (!data.hidden) {
          this.empty = false;
        }
      });
    },
    getChildren() {
      return this.$refs.items
        ? Array.from(this.$refs.items.querySelectorAll(":scope > li > div"))
        : [];
    },
    setActive() {
      const target = this.$el.querySelector(
        `[data-path="${window.location.pathname}"]`
      );
      this.$store.nav.active = target ? target.id : "";
    },
  };
}

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
lookbook-0.6.1 app/assets/lookbook/js/components/nav.js
lookbook-0.6.0 app/assets/lookbook/js/components/nav.js
lookbook-0.5.2 app/assets/lookbook/js/components/nav.js
lookbook-0.5.1 app/assets/lookbook/js/components/nav.js
lookbook-0.5.0 app/assets/lookbook/js/components/nav.js
lookbook-0.5.0.beta.2 app/assets/lookbook/js/components/nav.js
lookbook-0.5.0.beta.1 app/assets/lookbook/js/components/nav.js
lookbook-0.5.0.beta.0 app/assets/lookbook/js/components/nav.js