1 changed files with 28 additions and 63 deletions
@ -1,66 +1,31 @@ |
|||||||
//
|
(function (Drupal, once) { |
||||||
// (function (Drupal, once) {
|
Drupal.behaviors.removeTrailingZeros = { |
||||||
// Drupal.behaviors.removeTrailingZeros = {
|
attach: function (context) { |
||||||
// attach: function (context) {
|
function processField(id) { |
||||||
// function processField(id) {
|
var el = document.getElementById(id); |
||||||
// var el = document.getElementById(id);
|
if (!el) return; |
||||||
// 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). |
|
||||||
*/ |
|
||||||
|
|
||||||
Drupal.behaviors.olivesnewsYearSliderFix = { |
// If value isn't populated yet, wait and retry once
|
||||||
attach: function (context, settings) { |
if (el.value === "") { |
||||||
// Target the year slider (ID comes from your facet machine name)
|
setTimeout(function () { |
||||||
const sliderElements = context.querySelectorAll( |
processField(id); |
||||||
'#year.facet-slider, .facet-slider[id="year"]' |
}, 100); |
||||||
); |
return; |
||||||
|
} |
||||||
|
|
||||||
sliderElements.forEach(function (slider) { |
var str = el.value.toString().slice(0, -3); |
||||||
if (slider && slider.noUiSlider) { |
el.value = parseInt(str, 10); |
||||||
// Re-apply options with clean integer formatting
|
} |
||||||
slider.noUiSlider.updateOptions( |
|
||||||
{ |
once("from-slider", "#nouislider-input-from", context).forEach( |
||||||
format: { |
function () { |
||||||
to: function (value) { |
processField("nouislider-input-from"); |
||||||
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("to-slider", "#nouislider-input-to", context).forEach(function () { |
||||||
|
processField("nouislider-input-to"); |
||||||
}); |
}); |
||||||
}, |
}, |
||||||
}; |
}; |
||||||
|
})(Drupal, once); |
||||||
|
|||||||
Loading…
Reference in new issue