diff options
Diffstat (limited to 'app/assets/javascripts/settings_panels.js')
-rw-r--r-- | app/assets/javascripts/settings_panels.js | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/app/assets/javascripts/settings_panels.js b/app/assets/javascripts/settings_panels.js index 1f1f6e42576..2c6da5669ef 100644 --- a/app/assets/javascripts/settings_panels.js +++ b/app/assets/javascripts/settings_panels.js @@ -1,7 +1,22 @@ import $ from 'jquery'; import { __ } from './locale'; -export function expandSection($section) { +/** + * Returns true if the given section is expanded or not + * + * For legacy consistency, it supports both jQuery and DOM elements + * + * @param {jQuery | Element} section + */ +export function isExpanded(sectionArg) { + const section = sectionArg instanceof $ ? sectionArg[0] : sectionArg; + + return section.classList.contains('expanded'); +} + +export function expandSection(sectionArg) { + const $section = $(sectionArg); + $section.find('.js-settings-toggle:not(.js-settings-toggle-trigger-only)').text(__('Collapse')); // eslint-disable-next-line @gitlab/no-global-event-off $section.find('.settings-content').off('scroll.expandSection').scrollTop(0); @@ -13,7 +28,9 @@ export function expandSection($section) { } } -export function closeSection($section) { +export function closeSection(sectionArg) { + const $section = $(sectionArg); + $section.find('.js-settings-toggle:not(.js-settings-toggle-trigger-only)').text(__('Expand')); $section.find('.settings-content').on('scroll.expandSection', () => expandSection($section)); $section.removeClass('expanded'); @@ -26,7 +43,7 @@ export function closeSection($section) { export function toggleSection($section) { $section.removeClass('no-animate'); - if ($section.hasClass('expanded')) { + if (isExpanded($section)) { closeSection($section); } else { expandSection($section); @@ -38,7 +55,7 @@ export default function initSettingsPanels() { const $section = $(elm); $section.on('click.toggleSection', '.js-settings-toggle', () => toggleSection($section)); - if (!$section.hasClass('expanded')) { + if (!isExpanded($section)) { $section.find('.settings-content').on('scroll.expandSection', () => { $section.removeClass('no-animate'); expandSection($section); |