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