2018-03-09 15:18:59 -05:00
|
|
|
import $ from 'jquery';
|
|
|
|
|
2017-06-07 04:11:44 -04:00
|
|
|
function expandSection($section) {
|
2017-06-22 10:32:04 -04:00
|
|
|
$section.find('.js-settings-toggle').text('Collapse');
|
2017-10-14 02:05:54 -04:00
|
|
|
$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-06-21 03:49:38 -04:00
|
|
|
}
|
2017-06-07 04:11:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function closeSection($section) {
|
|
|
|
$section.find('.js-settings-toggle').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')) {
|
|
|
|
$section.addClass('animating')
|
|
|
|
.one('animationend.animateSection', () => $section.removeClass('animating'));
|
|
|
|
}
|
2017-06-07 04:11:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function toggleSection($section) {
|
2017-10-14 02:05:54 -04:00
|
|
|
$section.removeClass('no-animate');
|
|
|
|
if ($section.hasClass('expanded')) {
|
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
|
|
|
|
|
|
|
if (!$section.hasClass('expanded')) {
|
|
|
|
$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
|
|
|
|
|
|
|
if (location.hash) {
|
2017-10-14 02:05:54 -04:00
|
|
|
const $target = $(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
|
|
|
}
|