debian-mirror-gitlab/app/assets/javascripts/settings_panels.js

50 lines
1.5 KiB
JavaScript
Raw Normal View History

2017-09-10 17:25:29 +05:30
function expandSection($section) {
$section.find('.js-settings-toggle').text('Collapse');
2018-03-17 18:26:18 +05:30
$section.find('.settings-content').off('scroll.expandSection').scrollTop(0);
$section.addClass('expanded');
if (!$section.hasClass('no-animate')) {
$section.addClass('animating')
.one('animationend.animateSection', () => $section.removeClass('animating'));
2017-09-10 17:25:29 +05:30
}
}
function closeSection($section) {
$section.find('.js-settings-toggle').text('Expand');
2018-03-17 18:26:18 +05:30
$section.find('.settings-content').on('scroll.expandSection', () => expandSection($section));
2017-09-10 17:25:29 +05:30
$section.removeClass('expanded');
2018-03-17 18:26:18 +05:30
if (!$section.hasClass('no-animate')) {
$section.addClass('animating')
.one('animationend.animateSection', () => $section.removeClass('animating'));
}
2017-09-10 17:25:29 +05:30
}
function toggleSection($section) {
2018-03-17 18:26:18 +05:30
$section.removeClass('no-animate');
if ($section.hasClass('expanded')) {
2017-09-10 17:25:29 +05:30
closeSection($section);
} else {
expandSection($section);
}
}
export default function initSettingsPanels() {
$('.settings').each((i, elm) => {
const $section = $(elm);
$section.on('click.toggleSection', '.js-settings-toggle', () => toggleSection($section));
2018-03-17 18:26:18 +05:30
if (!$section.hasClass('expanded')) {
$section.find('.settings-content').on('scroll.expandSection', () => {
$section.removeClass('no-animate');
expandSection($section);
});
}
2017-09-10 17:25:29 +05:30
});
2018-03-17 18:26:18 +05:30
if (location.hash) {
const $target = $(location.hash);
2018-03-27 19:54:05 +05:30
if ($target.length && $target.hasClass('settings')) {
2018-03-17 18:26:18 +05:30
expandSection($target);
}
}
2017-09-10 17:25:29 +05:30
}