From eb1be4ffa1cb8543eae5d66b16bc54ed20cf4736 Mon Sep 17 00:00:00 2001 From: rdrew Date: Thu, 21 May 2026 13:15:12 -0300 Subject: [PATCH] trailing zeros --- .php-cs-fixer.dist.php | 28 ++++++++++++++++++++++++++++ js/nouislider-year-format.js | 34 ++++++++++++++++++++++++++++++++++ vre2024.libraries.yml | 8 +++++++- vre2024.theme | 1 + 4 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 .php-cs-fixer.dist.php create mode 100644 js/nouislider-year-format.js diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php new file mode 100644 index 0000000..4324ce9 --- /dev/null +++ b/.php-cs-fixer.dist.php @@ -0,0 +1,28 @@ +setRiskyAllowed(false) + ->setRules([ + '@auto' => true + ]) + // 💡 by default, Fixer looks for `*.php` files excluding `./vendor/` - here, you can groom this config + ->setFinder( + (new Finder()) + // 💡 root folder to check + ->in(__DIR__) + // 💡 additional files, eg bin entry file + // ->append([__DIR__.'/bin-entry-file']) + // 💡 folders to exclude, if any + // ->exclude([/* ... */]) + // 💡 path patterns to exclude, if any + // ->notPath([/* ... */]) + // 💡 extra configs + // ->ignoreDotFiles(false) // true by default in v3, false in v4 or future mode + // ->ignoreVCS(true) // true by default + ) +; diff --git a/js/nouislider-year-format.js b/js/nouislider-year-format.js new file mode 100644 index 0000000..624504f --- /dev/null +++ b/js/nouislider-year-format.js @@ -0,0 +1,34 @@ +(function (Drupal) { + "use strict"; + + Drupal.behaviors.nouisliderYearFormat = { + // Weight needs to be higher than the module's behavior so we run after it. + // Drupal behaviors don't have explicit weight in this API, but attaching + // after DOM ready is fine since once() ensures the module ran first. + attach: function (context, settings) { + const sliderEl = context.querySelector("#year.noUi-target"); + + if (!sliderEl || !sliderEl.noUiSlider) return; + if (sliderEl.dataset.yearFormatApplied) return; + sliderEl.dataset.yearFormatApplied = "true"; + + const inputFrom = document.getElementById("nouislider-input-from"); + const inputTo = document.getElementById("nouislider-input-to"); + + // The module's update listener gives inputs the raw float (e.g. 1971.00) + // because no top-level format is set on the slider. We add our own + // update listener that overwrites the input value with a rounded integer. + // 'update' fires on drag but does NOT trigger navigation — only 'set' does. + sliderEl.noUiSlider.on("update", function (values, handle) { + const rounded = Math.round(parseFloat(values[handle])); + if (handle === 0 && inputFrom) inputFrom.value = rounded; + if (handle === 1 && inputTo) inputTo.value = rounded; + }); + + // Fix the current displayed values in the inputs immediately + const current = sliderEl.noUiSlider.get(); + if (inputFrom) inputFrom.value = Math.round(parseFloat(current[0])); + if (inputTo) inputTo.value = Math.round(parseFloat(current[1])); + }, + }; +})(Drupal); diff --git a/vre2024.libraries.yml b/vre2024.libraries.yml index 13532d8..8318fce 100755 --- a/vre2024.libraries.yml +++ b/vre2024.libraries.yml @@ -53,7 +53,7 @@ fontawesome5: version: 5.15.4 css: component: - css/fontawesome5.css: {weight: -10} + css/fontawesome5.css: { weight: -10 } # Bootstrap Icons bootstrap-icons: @@ -68,3 +68,9 @@ maintenance: css: theme: css/maintenance.css: {} + +nouislider-year-format: + js: + js/nouislider-year-format.js: {} + dependencies: + - core/drupal diff --git a/vre2024.theme b/vre2024.theme index c663c64..70db28a 100755 --- a/vre2024.theme +++ b/vre2024.theme @@ -9,6 +9,7 @@ function vre2024_preprocess_page(array &$variables) { $variables['site_slogan'] = $config->get('slogan'); $variables['base_path'] = base_path(); $variables['scrolltotop_on'] = 1; + $variables['#attached']['library'][] = 'vre2024/nouislider-year-format'; } /** * Add current page to breadcrumb.