Sha256: 6fa1c623ecf5af4a995bb7d9896a8f67284af0b9abcf6f7b5a677840a205365e

Contents?: true

Size: 1001 Bytes

Versions: 2

Compression:

Stored size: 1001 Bytes

Contents

import morph from "./utils/morph";

export default function page() {
  const store = Alpine.store("page");
  return {
    ready: false,
    sidebarOpenMobile: false,
    init() {
      this.$nextTick(() => (this.ready = true));
    },
    splitProps: {
      minSize: 200,
      onDrag(splits) {
        Alpine.store("nav").width = Math.min(splits[0], 500);
      },
    },
    async fetchHTML() {
      const response = await fetch(window.document.location);
      if (!response.ok) return window.location.reload();
      const html = await response.text();
      store.doc = new DOMParser().parseFromString(html, "text/html");
      return store.doc;
    },
    updateTitle() {
      document.title = store.doc.title;
    },
    render() {
      if (this.ready) {
        morph(this.$el, store.doc.getElementById(this.$el.id));
        this.$dispatch("document:patched");
      }
    },
    navigateTo(path) {
      history.pushState({}, null, path);
      this.$dispatch("popstate");
    },
  };
}

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
lookbook-0.4.6 app/assets/lookbook/js/page.js
lookbook-0.4.5 app/assets/lookbook/js/page.js