From 93635069d64d75b81d78dfdb60f88a58fe0efbe4 Mon Sep 17 00:00:00 2001 From: lubber-de Date: Sat, 19 Aug 2023 22:51:04 +0200 Subject: [PATCH 1/2] fix(accordion): callbacks for closing exclusive accordions --- src/definitions/modules/accordion.js | 150 +++++++++++---------------- 1 file changed, 62 insertions(+), 88 deletions(-) diff --git a/src/definitions/modules/accordion.js b/src/definitions/modules/accordion.js index ce61a62270..af797acdbc 100644 --- a/src/definitions/modules/accordion.js +++ b/src/definitions/modules/accordion.js @@ -160,9 +160,13 @@ return; } + if (settings.onOpening.call($activeContent) === false || + settings.onChanging.call($activeContent) === false) { + module.debug('Opening or Changing Callback returned false cancelling open', $activeTitle); + + return; + } module.debug('Opening accordion content', $activeTitle); - settings.onOpening.call($activeContent); - settings.onChanging.call($activeContent); if (settings.exclusive) { module.closeOthers.call($activeTitle); } @@ -202,7 +206,7 @@ } $activeContent .slideDown(settings.duration, settings.easing, function () { - $activeContent + $(this) .removeClass(className.animating) .addClass(className.active) ; @@ -227,52 +231,60 @@ isClosing = isActive && isAnimating ; if ((isActive || isOpening) && !isClosing) { + if (settings.onClosing.call($activeContent) === false || + settings.onChanging.call($activeContent) === false) { + module.debug('Closing or Changing Callback returned false cancelling close', $activeTitle); + + return; + } module.debug('Closing accordion content', $activeContent); - settings.onClosing.call($activeContent); - settings.onChanging.call($activeContent); - $activeTitle - .removeClass(className.active) - ; - $activeContent - .stop(true, true) - .addClass(className.animating) - ; - if (settings.animateChildren) { - if ($.fn.transition !== undefined) { - $activeContent - .children() - .transition({ - animation: 'fade out', - queue: false, - useFailSafe: true, - debug: settings.debug, - verbose: settings.verbose, - silent: settings.silent, - duration: settings.duration, - skipInlineHidden: true, - }) - ; - } else { - $activeContent - .children() - .stop(true, true) - .animate({ - opacity: 0, - }, settings.duration, module.resetOpacity); - } + module.forceClose($activeTitle, $activeContent); + } + }, + + forceClose: function ($activeTitle, $activeContent) { + $activeTitle + .removeClass(className.active) + ; + $activeContent + .stop(true, true) + .addClass(className.animating) + ; + if (settings.animateChildren) { + if ($.fn.transition !== undefined) { + $activeContent + .children() + .transition({ + animation: 'fade out', + queue: false, + useFailSafe: true, + debug: settings.debug, + verbose: settings.verbose, + silent: settings.silent, + duration: settings.duration, + skipInlineHidden: true, + }) + ; + } else { + $activeContent + .children() + .stop(true, true) + .animate({ + opacity: 0, + }, settings.duration, module.resetOpacity); } - $activeContent - .slideUp(settings.duration, settings.easing, function () { - $activeContent - .removeClass(className.animating) - .removeClass(className.active) - ; - module.reset.display.call(this); - settings.onClose.call(this); - settings.onChange.call(this); - }) - ; } + $activeContent + .slideUp(settings.duration, settings.easing, function () { + $(this) + .removeClass(className.animating) + .removeClass(className.active) + ; + module.reset.display.call(this); + settings.onClose.call(this); + settings.onChange.call(this); + }) + ; }, closeOthers: function (index) { @@ -288,53 +300,15 @@ $nestedTitles, $openContents ; - if (settings.closeNested) { - $openTitles = $activeAccordion.find(activeSelector).not($parentTitles); - $openContents = $openTitles.next($content); - } else { - $openTitles = $activeAccordion.find(activeSelector).not($parentTitles); + $openTitles = $activeAccordion.find(activeSelector).not($parentTitles); + if (!settings.closeNested) { $nestedTitles = $activeAccordion.find(activeContent).find(activeSelector).not($parentTitles); $openTitles = $openTitles.not($nestedTitles); - $openContents = $openTitles.next($content); } + $openContents = $openTitles.next($content); if ($openTitles.length > 0) { module.debug('Exclusive enabled, closing other content', $openTitles); - $openTitles - .removeClass(className.active) - ; - $openContents - .removeClass(className.animating) - .stop(true, true) - ; - if (settings.animateChildren) { - if ($.fn.transition !== undefined) { - $openContents - .children() - .transition({ - animation: 'fade out', - useFailSafe: true, - debug: settings.debug, - verbose: settings.verbose, - silent: settings.silent, - duration: settings.duration, - skipInlineHidden: true, - }) - ; - } else { - $openContents - .children() - .stop(true, true) - .animate({ - opacity: 0, - }, settings.duration, module.resetOpacity); - } - } - $openContents - .slideUp(settings.duration, settings.easing, function () { - $(this).removeClass(className.active); - module.reset.display.call(this); - }) - ; + module.forceClose($openTitles, $openContents); } }, From e917cece38ca2798d21d564987533feddb0d0377 Mon Sep 17 00:00:00 2001 From: lubber-de Date: Sat, 19 Aug 2023 23:00:41 +0200 Subject: [PATCH 2/2] fix(accordion): linting fixes --- src/definitions/modules/accordion.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/definitions/modules/accordion.js b/src/definitions/modules/accordion.js index af797acdbc..c4e64cf7b9 100644 --- a/src/definitions/modules/accordion.js +++ b/src/definitions/modules/accordion.js @@ -160,8 +160,9 @@ return; } - if (settings.onOpening.call($activeContent) === false || - settings.onChanging.call($activeContent) === false) { + if (settings.onOpening.call($activeContent) === false + || settings.onChanging.call($activeContent) === false + ) { module.debug('Opening or Changing Callback returned false cancelling open', $activeTitle); return; @@ -231,8 +232,9 @@ isClosing = isActive && isAnimating ; if ((isActive || isOpening) && !isClosing) { - if (settings.onClosing.call($activeContent) === false || - settings.onChanging.call($activeContent) === false) { + if (settings.onClosing.call($activeContent) === false + || settings.onChanging.call($activeContent) === false + ) { module.debug('Closing or Changing Callback returned false cancelling close', $activeTitle); return;