Browse Source

00's fix

master
rdrew 10 hours ago
parent
commit
c0f565327f
  1. 38
      js/nouislider-year-format_v2.js
  2. 2
      olivesnews.libraries.yml

38
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);

2
olivesnews.libraries.yml

@ -69,7 +69,7 @@ global-styling:
nouislider-year-format: nouislider-year-format:
js: js:
js/nouislider-year-format.js: {} js/nouislider-year-format_v2.js: {}
dependencies: dependencies:
- core/drupal - core/drupal

Loading…
Cancel
Save