From 9dbb86e09946039c3ad527af6d3523edcf4498bf Mon Sep 17 00:00:00 2001 From: Chris Lawton <chris.lawton@torchbox.com> Date: Mon, 7 Jan 2019 16:58:00 +0000 Subject: [PATCH] adds active class to select2 checkboxes after page has been filtered --- .../src/javascript/apply/submission-filters.js | 8 ++++++++ opentech/static_src/src/javascript/main.js | 9 --------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/opentech/static_src/src/javascript/apply/submission-filters.js b/opentech/static_src/src/javascript/apply/submission-filters.js index 0186b0c38..60c5f18c3 100644 --- a/opentech/static_src/src/javascript/apply/submission-filters.js +++ b/opentech/static_src/src/javascript/apply/submission-filters.js @@ -53,5 +53,13 @@ }); }); + $(function () { + // Add active class to select2 checkboxes after page has been filtered + const clearButtons = document.querySelectorAll('.select2-selection__clear'); + clearButtons.forEach(clearButton => { + clearButton.parentElement.parentElement.classList.add('is-active'); + }); + }); + })(jQuery); diff --git a/opentech/static_src/src/javascript/main.js b/opentech/static_src/src/javascript/main.js index 40b87e15c..8bc430ea6 100644 --- a/opentech/static_src/src/javascript/main.js +++ b/opentech/static_src/src/javascript/main.js @@ -126,15 +126,6 @@ message.classList.add('messages__text--hide'); }); - // Add active class to select2 checkboxes after page has been filtered - document.addEventListener('DOMContentLoaded', () => { - // If there are clear buttons in the dom, it means the filters have been applied - const clearButtons = document.querySelectorAll('.select2-selection__clear'); - clearButtons.forEach(clearButton => { - clearButton.parentElement.parentElement.classList.add('is-active'); - }); - }); - // reset mobile filters if they're open past the tablet breakpoint $(window).resize(function resize() { if ($(window).width() < 1024) { -- GitLab