From 9e84fc950ffa542ec8702e15c08f9b2d1226e82f Mon Sep 17 00:00:00 2001 From: rdrew Date: Mon, 20 Apr 2026 13:31:47 -0300 Subject: [PATCH] slider test --- js/custom.js | 91 ++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 63 insertions(+), 28 deletions(-) diff --git a/js/custom.js b/js/custom.js index 73c7130..efdc276 100644 --- a/js/custom.js +++ b/js/custom.js @@ -1,31 +1,66 @@ -(function (Drupal, once) { - Drupal.behaviors.removeTrailingZeros = { - attach: function (context) { - function processField(id) { - var el = document.getElementById(id); - if (!el) return; +// +// (function (Drupal, once) { +// Drupal.behaviors.removeTrailingZeros = { +// attach: function (context) { +// function processField(id) { +// var el = document.getElementById(id); +// if (!el) return; +// +// // If value isn't populated yet, wait and retry once +// if (el.value === "") { +// setTimeout(function () { +// processField(id); +// }, 100); +// return; +// } +// +// var str = el.value.toString().slice(0, -3); +// el.value = parseInt(str, 10); +// } +// +// once("from-slider", "#nouislider-input-from", context).forEach( +// function () { +// processField("nouislider-input-from"); +// } +// ); +// +// once("to-slider", "#nouislider-input-to", context).forEach(function () { +// processField("nouislider-input-to"); +// }); +// }, +// }; +// })(Drupal, once); +/** + * @file + * Fix noUiSlider formatting for year facets (remove .00). + */ - // If value isn't populated yet, wait and retry once - if (el.value === "") { - setTimeout(function () { - processField(id); - }, 100); - return; - } +Drupal.behaviors.olivesnewsYearSliderFix = { + attach: function (context, settings) { + // Target the year slider (ID comes from your facet machine name) + const sliderElements = context.querySelectorAll( + '#year.facet-slider, .facet-slider[id="year"]' + ); - var str = el.value.toString().slice(0, -3); - el.value = parseInt(str, 10); + sliderElements.forEach(function (slider) { + if (slider && slider.noUiSlider) { + // Re-apply options with clean integer formatting + slider.noUiSlider.updateOptions( + { + format: { + to: function (value) { + return Math.round(value).toString(); // e.g., 1787 instead of 1787.00 + }, + from: function (value) { + return Number(value); + }, + }, + // Optional: also force tooltips to use the same clean format + tooltips: [true, true], // or a custom formatter if needed + }, + true + ); // true = fire 'update' event so it refreshes immediately } - - once("from-slider", "#nouislider-input-from", context).forEach( - function () { - processField("nouislider-input-from"); - } - ); - - once("to-slider", "#nouislider-input-to", context).forEach(function () { - processField("nouislider-input-to"); - }); - }, - }; -})(Drupal, once); + }); + }, +};