2017-03-26 21:33:47 -04:00
|
|
|
// Toggle button. Show/hide content inside parent container.
|
|
|
|
// Button does not change visibility. If button has icon - it changes chevron style.
|
|
|
|
//
|
|
|
|
// %div.js-toggle-container
|
|
|
|
// %button.js-toggle-button
|
|
|
|
// %div.js-toggle-content
|
|
|
|
//
|
|
|
|
|
|
|
|
$(() => {
|
|
|
|
function toggleContainer(container, toggleState) {
|
|
|
|
const $container = $(container);
|
|
|
|
|
|
|
|
$container
|
|
|
|
.find('.js-toggle-button .fa')
|
|
|
|
.toggleClass('fa-chevron-up', toggleState)
|
|
|
|
.toggleClass('fa-chevron-down', toggleState !== undefined ? !toggleState : undefined);
|
|
|
|
|
|
|
|
$container
|
|
|
|
.find('.js-toggle-content')
|
|
|
|
.toggle(toggleState);
|
|
|
|
}
|
|
|
|
|
|
|
|
$('body').on('click', '.js-toggle-button', function toggleButton(e) {
|
2017-04-16 05:42:08 -04:00
|
|
|
e.target.classList.toggle('open');
|
2017-03-26 21:33:47 -04:00
|
|
|
toggleContainer($(this).closest('.js-toggle-container'));
|
|
|
|
|
|
|
|
const targetTag = e.currentTarget.tagName.toLowerCase();
|
|
|
|
if (targetTag === 'a' || targetTag === 'button') {
|
|
|
|
e.preventDefault();
|
2016-07-31 21:17:19 -04:00
|
|
|
}
|
|
|
|
});
|
2017-03-26 21:33:47 -04:00
|
|
|
|
|
|
|
// If we're accessing a permalink, ensure it is not inside a
|
|
|
|
// closed js-toggle-container!
|
|
|
|
const hash = window.gl.utils.getLocationHash();
|
|
|
|
const anchor = hash && document.getElementById(hash);
|
|
|
|
const container = anchor && $(anchor).closest('.js-toggle-container');
|
|
|
|
|
|
|
|
if (container) {
|
|
|
|
toggleContainer(container, true);
|
|
|
|
anchor.scrollIntoView();
|
|
|
|
}
|
|
|
|
});
|