Sha256: 7e0a8b460653816b26af04f97efae2e48346d5f3280902a640927c947bf3e854

Contents?: true

Size: 740 Bytes

Versions: 9

Compression:

Stored size: 740 Bytes

Contents

import { Controller } from "@hotwired/stimulus";
import { Turbo } from "@hotwired/turbo";

export default class TurboCollectionController extends Controller {
  static values = {
    url: String,
    sort: String,
  };

  urlValueChanged(url) {
    Turbo.navigator.history.replace(this.#url(url));
  }

  sortValueChanged(sort) {
    document.querySelectorAll(this.#sortSelector).forEach((input) => {
      if (input) input.value = sort;
    });
  }

  get #sortSelector() {
    return "input[name='sort']";
  }

  #url(relativeUrl) {
    const frame = this.element.closest("turbo-frame");

    if (frame) {
      return new URL(relativeUrl, frame.baseURI);
    } else {
      return new URL(relativeUrl, window.location.href);
    }
  }
}

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
katalyst-tables-2.2.8 app/assets/javascripts/controllers/tables/turbo_collection_controller.js
katalyst-tables-2.2.7 app/assets/javascripts/controllers/tables/turbo_collection_controller.js
katalyst-tables-2.2.6 app/assets/javascripts/controllers/tables/turbo_collection_controller.js
katalyst-tables-2.2.5 app/assets/javascripts/controllers/tables/turbo_collection_controller.js
katalyst-tables-2.2.4 app/assets/javascripts/controllers/tables/turbo_collection_controller.js
katalyst-tables-2.2.3 app/assets/javascripts/controllers/tables/turbo_collection_controller.js
katalyst-tables-2.2.2 app/assets/javascripts/controllers/tables/turbo_collection_controller.js
katalyst-tables-2.2.1 app/assets/javascripts/controllers/tables/turbo_collection_controller.js
katalyst-tables-2.2.0 app/assets/javascripts/controllers/tables/turbo_collection_controller.js