From ad327a864ecfd2b035a93d87bf97b13805ac83fb Mon Sep 17 00:00:00 2001 From: Kee Ga Jin Date: Fri, 20 Dec 2024 23:37:20 +0800 Subject: [PATCH] fix(js): dropdown omits non-p elements (#423) --- README.md | 2 +- assets/js/main.js | 22 ++++++++++++---------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 4c1e798b..00071479 100644 --- a/README.md +++ b/README.md @@ -68,7 +68,7 @@ For the homepage and separate [Stories](https://beta.advisory.sg/stories) page t # PostCSS Features Used -- Autoprefixer - Don't worry about writing browser prefixes of any kind, it's all done automatically with support for the latest 2 major versions of every browser. +- Autoprefixer - Don't worry about writing browser prefixes of any kind, it's all done automatically with support for the latest 2 major versions of every browser. # Copyright & License diff --git a/assets/js/main.js b/assets/js/main.js index f484f34f..bcab0478 100644 --- a/assets/js/main.js +++ b/assets/js/main.js @@ -605,28 +605,30 @@ function contentDropdown() { } $('div.single-content h2').each(function () { var $header = $(this); + var $container = $(''); var $nextElement = $header.next(); - var $pContainer = $(''); - var $pElements = []; + var $curElement = $nextElement; var $arrowIcon = $('\u25B8'); - while ($nextElement.is('p')) { - $pElements.push($nextElement); + while ( + $nextElement.length && + !$nextElement.is('h1') && + !$nextElement.is('h2') + ) { + $curElement = $nextElement; $nextElement = $nextElement.next(); + $container.append($curElement); } - $pElements.forEach(function ($pElement) { - $pContainer.append($pElement); - }); - if ($pContainer.length > 0) { + if ($container.length > 0) { // Add the dropdown-header class to the h2 element $header.addClass('dropdown-header'); $header.prepend($arrowIcon); // Hide the entire container and insert it after h2 - $pContainer.hide().insertAfter($header); + $container.hide().insertAfter($header); // Add a click event listener to the h2 element to toggle the container $header.on('click', function () { - $pContainer.slideToggle(); + $container.slideToggle(); if ($arrowIcon.text() === '\u25B8') { $arrowIcon.text('\u25B4'); } else {