2018-05-09 12:01:36 +05:30
|
|
|
import $ from 'jquery';
|
2018-12-13 13:39:08 +05:30
|
|
|
import { __ } from './locale';
|
2018-05-09 12:01:36 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
function expandSection($section) {
|
2018-12-13 13:39:08 +05:30
|
|
|
$section.find('.js-settings-toggle:not(.js-settings-toggle-trigger-only)').text(__('Collapse'));
|
|
|
|
$section
|
|
|
|
.find('.settings-content')
|
|
|
|
.off('scroll.expandSection')
|
|
|
|
.scrollTop(0);
|
2018-03-17 18:26:18 +05:30
|
|
|
$section.addClass('expanded');
|
|
|
|
if (!$section.hasClass('no-animate')) {
|
2018-12-13 13:39:08 +05:30
|
|
|
$section
|
|
|
|
.addClass('animating')
|
2018-03-17 18:26:18 +05:30
|
|
|
.one('animationend.animateSection', () => $section.removeClass('animating'));
|
2017-09-10 17:25:29 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function closeSection($section) {
|
2018-12-13 13:39:08 +05:30
|
|
|
$section.find('.js-settings-toggle:not(.js-settings-toggle-trigger-only)').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')) {
|
2018-12-13 13:39:08 +05:30
|
|
|
$section
|
|
|
|
.addClass('animating')
|
2018-03-17 18:26:18 +05:30
|
|
|
.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
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
if (window.location.hash) {
|
|
|
|
const $target = $(window.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
|
|
|
}
|