From 8103c484611491befdaa5910d3f90182a760c22d Mon Sep 17 00:00:00 2001 From: "Willy \"Linty" Date: Mon, 27 Nov 2023 18:35:06 +0100 Subject: [PATCH] Fixes #2051 Move the widget as space becomes available I calculate the overflow and if it is too much we align the widget to the right of the filter and calculation takes place each time the window is resized --- themes/default/js/mcs.js | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/themes/default/js/mcs.js b/themes/default/js/mcs.js index 26deeb127..c0bab33b1 100644 --- a/themes/default/js/mcs.js +++ b/themes/default/js/mcs.js @@ -844,4 +844,32 @@ function updateFilters(filterName, mode) { function reloadPage(url){ window.location.href = url; -} \ No newline at end of file +} + +/** + * Replace the filter_form elements if they exceed the window + */ +function resize_filter_form(){ + $('.filter').each(function() { + const window_width = $(window).innerWidth(); + const left_distance = $(this).offset().left; + const filter_form = $(this).find($('.filter-form')); + const filter_form_width = filter_form.innerWidth(); + const too_left = (left_distance + $(this).innerWidth()) - filter_form_width; + filter_form.css('left', '0px'); + + if(left_distance + filter_form_width > window_width) { + console.log($(this)[0].outerText + ': dépasse de ' + (window_width - left_distance) + filter_form_width + 'px'); + + const check_left = too_left < 0 ? Math.abs(too_left - 5) : 0; + const replace_form_width = - filter_form_width + $(this).innerWidth() + check_left; + filter_form.css('left', replace_form_width+'px'); + } + }); +} +$(window).on('load', function() { + resize_filter_form(); +}); +$(window).on('resize', function() { + resize_filter_form(); +}); \ No newline at end of file