From 01e3bb61eab7f297b835a6c33e687b61c021ee5c Mon Sep 17 00:00:00 2001 From: MatthieuLP Date: Mon, 24 Jul 2023 11:47:15 +0200 Subject: [PATCH] related to #1945 & #1931 Clearer code --- themes/default/js/mcs.js | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/themes/default/js/mcs.js b/themes/default/js/mcs.js index 2b55c9326..59e192d72 100644 --- a/themes/default/js/mcs.js +++ b/themes/default/js/mcs.js @@ -9,14 +9,22 @@ $(document).ready(function () { $(document).on('click', function (e) { $(".filter-form").each(function () { - if ($(this).parent().hasClass("show-filter-dropdown") && - $(this).parent().has(e.target).length === 0 && - !$(this).parent().is(e.target) && - !$("#addLinkedAlbum").is(e.target) && - $("#addLinkedAlbum").has(e.target).length === 0) { - $(this).parent().trigger('click'); - if ($(".filter").has(e.target).length !== 0) { - $(e.target).trigger('click'); + if ($(this).parent().hasClass("show-filter-dropdown")) { + // Filter is open + + if ($(this).parent().has(e.target).length === 0 && !$(this).parent().is(e.target)) { + // We don't click on a filter or filter's form + // $(this).parent().trigger('click'); + + if ($("#addLinkedAlbum").has(e.target).length === 0 && !$("#addLinkedAlbum").is(e.target)) { + console.log("We don't click in filter manager"); + $(this).parent().trigger('click'); + } + + //if target if a filter, open it + if ($(".filter").has(e.target).length !== 0) { + $(e.target).trigger('click'); + } } } });