From c0f565327ff534106c7187ca470cf9a3dd6cee9d Mon Sep 17 00:00:00 2001 From: rdrew Date: Mon, 25 May 2026 13:06:46 -0300 Subject: [PATCH] 00's fix --- js/nouislider-year-format_v2.js | 38 +++++++++++++++++++++++++++++++++ olivesnews.libraries.yml | 2 +- 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 js/nouislider-year-format_v2.js diff --git a/js/nouislider-year-format_v2.js b/js/nouislider-year-format_v2.js new file mode 100644 index 0000000..f8eaf75 --- /dev/null +++ b/js/nouislider-year-format_v2.js @@ -0,0 +1,38 @@ +(function (Drupal) { + "use strict"; + + Drupal.behaviors.nouisliderYearFormat = { + attach: function (context) { + // 1. Target the slider element + const sliderEl = document.getElementById("year"); + if (!sliderEl) return; + + // 2. Use a small function to attach the rounding logic + const applyRounding = () => { + if (sliderEl.noUiSlider && !sliderEl.dataset.yearFormatApplied) { + sliderEl.dataset.yearFormatApplied = "true"; + + sliderEl.noUiSlider.on("update", function (values, handle) { + const inputId = + handle === 0 ? "nouislider-input-from" : "nouislider-input-to"; + const input = document.getElementById(inputId); + if (input) { + // Round the string value ("1971.00" -> 1971) + input.value = Math.round(parseFloat(values[handle])); + } + }); + } + }; + + // 3. Try immediately, then periodically until the slider is ready + applyRounding(); + const retry = setInterval(() => { + applyRounding(); + if (sliderEl.dataset.yearFormatApplied) clearInterval(retry); + }, 100); + + // Stop trying after 3 seconds + setTimeout(() => clearInterval(retry), 3000); + }, + }; +})(Drupal); diff --git a/olivesnews.libraries.yml b/olivesnews.libraries.yml index a277b15..53593bb 100755 --- a/olivesnews.libraries.yml +++ b/olivesnews.libraries.yml @@ -69,7 +69,7 @@ global-styling: nouislider-year-format: js: - js/nouislider-year-format.js: {} + js/nouislider-year-format_v2.js: {} dependencies: - core/drupal