Sha256: f28167c0501d36854970a5756a924d15eb7a5ef8d79ae7a5eceafca8e63fe25e

Contents?: true

Size: 806 Bytes

Versions: 1

Compression:

Stored size: 806 Bytes

Contents

function initListing() {
  $ = document.querySelector.bind(document);

  function applySort(sortable) {
    var params = new URLSearchParams(location.search.slice(1));
    params.set("_servel_sort_method", sortable.dataset.sortMethod);
    params.set("_servel_sort_direction", sortable.dataset.sortDirection);

    if('sortActive' in sortable.dataset) {
      params.set("_servel_sort_direction", sortable.dataset.sortDirection == "asc" ? "desc" : "asc");
    }

    location.href = location.pathname + "?" + params.toString();
  }

  document.body.addEventListener("click", function(e) {
    if(!e.target) return;

    if(e.target.closest("th.sortable")) {
      e.preventDefault();
      applySort(e.target.closest("th.sortable"));
    }
  });
}

window.addEventListener("DOMContentLoaded", initListing);

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
servel-0.14.0 lib/servel/templates/js/listing.js