Sha256: b4bd70debbdd4e5cc9555329a56f317fbaef42c8bc18726dd389eea12979e8a2

Contents?: true

Size: 1.3 KB

Versions: 11

Compression:

Stored size: 1.3 KB

Contents

import { Turbo } from "@hotwired/turbo-rails";

import DEBUG from "./debug";

import { StreamModal } from "./modals/stream_modal";
import { StreamRenderer } from "./utils/stream_renderer";

function kpop(action) {
  return action.targetElements[0]?.kpop;
}

Turbo.StreamActions.kpop_open = function () {
  const animate = !kpop(this).openValue;

  kpop(this)
    ?.dismiss({ animate, reason: "before-turbo-stream" })
    .then(() => {
      new StreamRenderer(this.targetElements[0], this).render();
      kpop(this)?.open(new StreamModal(this.target, this), { animate });
    });
};

Turbo.StreamActions.kpop_dismiss = function () {
  kpop(this)?.dismiss({ reason: "turbo_stream.kpop.dismiss" });
};

Turbo.StreamActions.kpop_redirect_to = function () {
  if (this.dataset.turboFrame === this.target) {
    if (DEBUG)
      console.debug(
        `kpop: redirecting ${this.target} to ${this.getAttribute("href")}`,
      );
    const a = document.createElement("A");
    a.setAttribute("data-turbo-action", "replace");
    this.targetElements[0].delegate.linkClickIntercepted(
      a,
      this.getAttribute("href"),
    );
  } else {
    if (DEBUG)
      console.debug(`kpop: redirecting to ${this.getAttribute("href")}`);
    Turbo.visit(this.getAttribute("href"), {
      action: this.dataset.turboAction,
    });
  }
};

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
katalyst-kpop-3.2.6 app/javascript/kpop/turbo_actions.js
katalyst-kpop-3.2.5 app/javascript/kpop/turbo_actions.js
katalyst-kpop-3.2.4 app/javascript/kpop/turbo_actions.js
katalyst-kpop-3.2.3 app/javascript/kpop/turbo_actions.js
katalyst-kpop-3.2.2 app/javascript/kpop/turbo_actions.js
katalyst-kpop-3.2.1 app/javascript/kpop/turbo_actions.js
katalyst-kpop-3.2.0 app/javascript/kpop/turbo_actions.js
katalyst-kpop-3.1.3 app/javascript/kpop/turbo_actions.js
katalyst-kpop-3.1.2 app/javascript/kpop/turbo_actions.js
katalyst-kpop-3.1.1 app/javascript/kpop/turbo_actions.js
katalyst-kpop-3.1.0 app/javascript/kpop/turbo_actions.js