diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-11 00:09:24 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-11 00:09:24 +0300 |
commit | 02c3b2af448be6a5004e8d833cbcbf8e5f185210 (patch) | |
tree | 27359dc5c21a8901c9eb95a0101cb97087b1f4ac /app/assets/javascripts/settings_panels.js | |
parent | 577bb49691b11bc8ebae3a4966153ed39af60d87 (diff) |
Add latest changes from gitlab-org/gitlab@master
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); |