Commit 7e8f3a58 authored by Mike Greiling's avatar Mike Greiling

remove needlessly complicated, duplicate css class for expanded settings panels

parent 93139aa8
function expandSectionParent($section, $content) {
$section.addClass('expanded');
$content.off('animationend.expandSectionParent');
}
function expandSection($section) { function expandSection($section) {
$section.find('.js-settings-toggle').text('Collapse'); $section.find('.js-settings-toggle').text('Collapse');
$section.find('.settings-content').off('scroll.expandSection').scrollTop(0);
const $content = $section.find('.settings-content'); $section.addClass('expanded');
$content.addClass('expanded').off('scroll.expandSection').scrollTop(0); if (!$section.hasClass('no-animate')) {
$section.addClass('animating')
if ($content.hasClass('no-animate')) { .one('animationend.animateSection', () => $section.removeClass('animating'));
expandSectionParent($section, $content);
} else {
$content.on('animationend.expandSectionParent', () => expandSectionParent($section, $content));
} }
} }
function closeSection($section) { function closeSection($section) {
$section.find('.js-settings-toggle').text('Expand'); $section.find('.js-settings-toggle').text('Expand');
$section.find('.settings-content').on('scroll.expandSection', () => expandSection($section));
const $content = $section.find('.settings-content');
$content.removeClass('expanded').on('scroll.expandSection', () => expandSection($section));
$section.removeClass('expanded'); $section.removeClass('expanded');
if (!$section.hasClass('no-animate')) {
$section.addClass('animating')
.one('animationend.animateSection', () => $section.removeClass('animating'));
}
} }
function toggleSection($section) { function toggleSection($section) {
const $content = $section.find('.settings-content'); $section.removeClass('no-animate');
$content.removeClass('no-animate'); if ($section.hasClass('expanded')) {
if ($content.hasClass('expanded')) {
closeSection($section); closeSection($section);
} else { } else {
expandSection($section); expandSection($section);
...@@ -39,10 +31,19 @@ export default function initSettingsPanels() { ...@@ -39,10 +31,19 @@ export default function initSettingsPanels() {
$('.settings').each((i, elm) => { $('.settings').each((i, elm) => {
const $section = $(elm); const $section = $(elm);
$section.on('click.toggleSection', '.js-settings-toggle', () => toggleSection($section)); $section.on('click.toggleSection', '.js-settings-toggle', () => toggleSection($section));
$section.find('.settings-content:not(.expanded)').on('scroll.expandSection', () => expandSection($section));
if (!$section.hasClass('expanded')) {
$section.find('.settings-content').on('scroll.expandSection', () => {
$section.removeClass('no-animate');
expandSection($section);
});
}
}); });
if (location.hash) { if (location.hash) {
expandSection($(location.hash)); const $target = $(location.hash);
if ($target.length && $target.hasClass('.settings')) {
expandSection($target);
}
} }
} }
...@@ -23,15 +23,14 @@ ...@@ -23,15 +23,14 @@
} }
.settings { .settings {
overflow: hidden;
border-bottom: 1px solid $gray-darker; border-bottom: 1px solid $gray-darker;
&:first-of-type { &:first-of-type {
margin-top: 10px; margin-top: 10px;
} }
&.expanded { &.animating {
overflow: visible; overflow: hidden;
} }
} }
...@@ -57,13 +56,13 @@ ...@@ -57,13 +56,13 @@
padding-right: 110px; padding-right: 110px;
animation: collapseMaxHeight 300ms ease-out; animation: collapseMaxHeight 300ms ease-out;
&.expanded { .settings.expanded & {
max-height: none; max-height: none;
overflow-y: visible; overflow-y: visible;
animation: expandMaxHeight 300ms ease-in; animation: expandMaxHeight 300ms ease-in;
} }
&.no-animate { .settings.no-animate & {
animation: none; animation: none;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment