Sha256: 3c00dd185f07ba2f6efa289b4f2b6012abcf1c75fd5828c12260ca900f9fb9d0

Contents?: true

Size: 1.31 KB

Versions: 17

Compression:

Stored size: 1.31 KB

Contents

export default function preview() {
  const app = Alpine.store("page");
  const preview = Alpine.store("preview");
  return {
    init() {
      this.root = this.$el;
    },
    onResize(e) {
      const size =
        this.resizeStartSize - (this.resizeStartPosition - e.pageX) * 2;
      const parentSize = this.root.parentElement.clientWidth;
      const percentSize = (Math.round(size) / parentSize) * 100;
      const minWidth = (300 / parentSize) * 100;
      preview.width = `${Math.min(Math.max(percentSize, minWidth), 100)}%`;
    },
    onResizeStart(e) {
      app.reflowing = true;
      this.onResize = this.onResize.bind(this);
      this.onResizeEnd = this.onResizeEnd.bind(this);
      this.resizeStartPosition = e.pageX;
      this.resizeStartSize = this.root.clientWidth;
      window.addEventListener("pointermove", this.onResize);
      window.addEventListener("pointerup", this.onResizeEnd);
    },
    onResizeEnd() {
      window.removeEventListener("pointermove", this.onResize);
      window.removeEventListener("pointerup", this.onResizeEnd);
      app.reflowing = false;
    },
    toggleFullWidth() {
      if (preview.width === "100%" && preview.lastWidth) {
        preview.width = preview.lastWidth;
      } else {
        preview.lastWidth = preview.width;
        preview.width = "100%";
      }
    },
  };
}

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
lookbook-0.4.6 app/assets/lookbook/js/workbench/preview.js
lookbook-0.4.5 app/assets/lookbook/js/workbench/preview.js
lookbook-0.4.4 app/assets/lookbook/js/workbench/preview.js
lookbook-0.4.3 app/assets/lookbook/js/workbench/preview.js
lookbook-0.4.2 app/assets/lookbook/js/workbench/preview.js
lookbook-0.4.1 app/assets/lookbook/js/workbench/preview.js
lookbook-0.3.5 app/assets/lookbook/js/workbench/preview.js
lookbook-0.4.0.beta.2 app/assets/lookbook/js/workbench/preview.js
lookbook-0.4.0.beta.1 app/assets/lookbook/js/workbench/preview.js
lookbook-0.3.4 app/assets/lookbook/js/workbench/preview.js
lookbook-0.3.3 app/assets/lookbook/js/workbench/preview.js
lookbook-0.3.2 app/assets/lookbook/js/workbench/preview.js
lookbook-0.3.1 app/assets/lookbook/js/workbench/preview.js
lookbook-0.3.0 app/assets/lookbook/js/workbench/preview.js
lookbook-0.3.0.beta.2 app/assets/lookbook/js/workbench/preview.js
lookbook-0.3.0.beta.1 app/assets/lookbook/js/workbench/preview.js
lookbook-0.3.0.beta.0 app/assets/lookbook/js/workbench/preview.js