Sha256: a5976d174eff185cc8515b3648fbbc671420901627f864d828f4c8e826d3ca10

Contents?: true

Size: 1.18 KB

Versions: 44

Compression:

Stored size: 1.18 KB

Contents

import { pushState, registerCallback } from "src/decidim/history"

const initializeListingOptionsMenu = (options) => {
  $(document).on("click", `${options.containerSelector} a`, (event) => {
    const $target = $(event.target);

    $target.parents(".menu").find("a:first").text($target.text());

    pushState($target.attr("href"));
  })

  registerCallback(options.callbackName, () => {
    const url = window.location.toString();
    const match = url.match(/${options.urlParameter}=([^&]*)/);
    const $targetMenu = $(`${options.containerSelector} .menu`);
    let value = $targetMenu.find(".menu a:first").data(options.dataAttribute);

    if (match) {
      value = match[1];
    }

    const linkText = $targetMenu.find(`.menu a[data-${options.dataAttribute}="${value}"]`).text();

    $targetMenu.find("a:first").text(linkText);
  });
};

$(() => {
  initializeListingOptionsMenu({
    containerSelector: ".order-by",
    callbackName: "orders",
    urlParameter: "order",
    dataAttribute: "order"
  });
  initializeListingOptionsMenu({
    containerSelector: ".results-per-page",
    callbackName: "results_per_page",
    urlParameter: "per_page",
    dataAttribute: "per-page-option"
  });
});

Version data entries

44 entries across 44 versions & 1 rubygems

Version Path
decidim-core-0.29.1 app/packs/src/decidim/results_listing.js
decidim-core-0.28.4 app/packs/src/decidim/results_listing.js
decidim-core-0.27.9 app/packs/src/decidim/results_listing.js
decidim-core-0.29.0 app/packs/src/decidim/results_listing.js
decidim-core-0.28.3 app/packs/src/decidim/results_listing.js
decidim-core-0.27.8 app/packs/src/decidim/results_listing.js
decidim-core-0.29.0.rc4 app/packs/src/decidim/results_listing.js
decidim-core-0.29.0.rc3 app/packs/src/decidim/results_listing.js
decidim-core-0.29.0.rc2 app/packs/src/decidim/results_listing.js
decidim-core-0.29.0.rc1 app/packs/src/decidim/results_listing.js
decidim-core-0.28.2 app/packs/src/decidim/results_listing.js
decidim-core-0.27.7 app/packs/src/decidim/results_listing.js
decidim-core-0.28.1 app/packs/src/decidim/results_listing.js
decidim-core-0.27.6 app/packs/src/decidim/results_listing.js
decidim-core-0.26.10 app/packs/src/decidim/results_listing.js
decidim-core-0.26.9 app/packs/src/decidim/results_listing.js
decidim-core-0.28.0 app/packs/src/decidim/results_listing.js
decidim-core-0.27.5 app/packs/src/decidim/results_listing.js
decidim-core-0.28.0.rc5 app/packs/src/decidim/results_listing.js
decidim-core-0.28.0.rc4 app/packs/src/decidim/results_listing.js