2018-03-09 15:18:59 -05:00
|
|
|
import $ from 'jquery';
|
2018-10-15 09:36:19 -04:00
|
|
|
import { __ } from './locale';
|
2018-03-09 15:18:59 -05:00
|
|
|
|
2021-02-10 16:09:24 -05:00
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
|
2018-10-15 09:36:19 -04:00
|
|
|
$section.find('.js-settings-toggle:not(.js-settings-toggle-trigger-only)').text(__('Collapse'));
|
2020-12-08 16:10:06 -05:00
|
|
|
// eslint-disable-next-line @gitlab/no-global-event-off
|
2020-12-23 07:10:26 -05:00
|
|
|
$section.find('.settings-content').off('scroll.expandSection').scrollTop(0);
|
2017-10-14 02:05:54 -04:00
|
|
|
$section.addClass('expanded');
|
|
|
|
if (!$section.hasClass('no-animate')) {
|
2018-10-10 03:13:34 -04:00
|
|
|
$section
|
|
|
|
.addClass('animating')
|
2017-10-14 02:05:54 -04:00
|
|
|
.one('animationend.animateSection', () => $section.removeClass('animating'));
|
2017-06-21 03:49:38 -04:00
|
|
|
}
|
2017-06-07 04:11:44 -04:00
|
|
|
}
|
|
|
|
|
2021-02-10 16:09:24 -05:00
|
|
|
export function closeSection(sectionArg) {
|
|
|
|
const $section = $(sectionArg);
|
|
|
|
|
2018-10-15 09:36:19 -04:00
|
|
|
$section.find('.js-settings-toggle:not(.js-settings-toggle-trigger-only)').text(__('Expand'));
|
2017-10-14 02:05:54 -04:00
|
|
|
$section.find('.settings-content').on('scroll.expandSection', () => expandSection($section));
|
2017-06-21 03:49:38 -04:00
|
|
|
$section.removeClass('expanded');
|
2017-10-14 02:05:54 -04:00
|
|
|
if (!$section.hasClass('no-animate')) {
|
2018-10-10 03:13:34 -04:00
|
|
|
$section
|
|
|
|
.addClass('animating')
|
2017-10-14 02:05:54 -04:00
|
|
|
.one('animationend.animateSection', () => $section.removeClass('animating'));
|
|
|
|
}
|
2017-06-07 04:11:44 -04:00
|
|
|
}
|
|
|
|
|
2021-01-07 04:10:22 -05:00
|
|
|
export function toggleSection($section) {
|
2017-10-14 02:05:54 -04:00
|
|
|
$section.removeClass('no-animate');
|
2021-02-10 16:09:24 -05:00
|
|
|
if (isExpanded($section)) {
|
2017-06-07 04:11:44 -04:00
|
|
|
closeSection($section);
|
|
|
|
} else {
|
|
|
|
expandSection($section);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default function initSettingsPanels() {
|
|
|
|
$('.settings').each((i, elm) => {
|
|
|
|
const $section = $(elm);
|
2017-06-21 03:49:38 -04:00
|
|
|
$section.on('click.toggleSection', '.js-settings-toggle', () => toggleSection($section));
|
2017-10-14 02:05:54 -04:00
|
|
|
|
2021-02-10 16:09:24 -05:00
|
|
|
if (!isExpanded($section)) {
|
2017-10-14 02:05:54 -04:00
|
|
|
$section.find('.settings-content').on('scroll.expandSection', () => {
|
|
|
|
$section.removeClass('no-animate');
|
|
|
|
expandSection($section);
|
|
|
|
});
|
|
|
|
}
|
2017-06-07 04:11:44 -04:00
|
|
|
});
|
2017-09-07 05:26:51 -04:00
|
|
|
|
2018-06-15 11:58:27 -04:00
|
|
|
if (window.location.hash) {
|
|
|
|
const $target = $(window.location.hash);
|
2018-02-12 20:30:03 -05:00
|
|
|
if ($target.length && $target.hasClass('settings')) {
|
2017-10-14 02:05:54 -04:00
|
|
|
expandSection($target);
|
|
|
|
}
|
2017-09-07 05:26:51 -04:00
|
|
|
}
|
2017-06-07 04:11:44 -04:00
|
|
|
}
|