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
|
|
|
|
2017-06-07 04:11:44 -04:00
|
|
|
function expandSection($section) {
|
2018-10-15 09:36:19 -04:00
|
|
|
$section.find('.js-settings-toggle:not(.js-settings-toggle-trigger-only)').text(__('Collapse'));
|
2018-10-10 03:13:34 -04: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
|
|
|
}
|
|
|
|
|
|
|
|
function closeSection($section) {
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
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
|
|
|
}
|