2016-11-15 09:08:06 -05:00
|
|
|
/* eslint-disable wrap-iife, func-names, space-before-function-paren, prefer-arrow-callback, vars-on-top, no-var, max-len */
|
2016-07-31 21:17:19 -04:00
|
|
|
(function(w) {
|
2016-07-24 16:45:11 -04:00
|
|
|
$(function() {
|
2017-01-25 00:12:06 -05:00
|
|
|
var toggleContainer = function(container, /* optional */toggleState) {
|
|
|
|
var $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);
|
|
|
|
};
|
|
|
|
|
2016-07-26 23:32:10 -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
|
2017-03-14 01:02:30 -04:00
|
|
|
// %button.js-toggle-button
|
2016-07-26 23:32:10 -04:00
|
|
|
// %div.js-toggle-content
|
|
|
|
//
|
2017-03-14 12:47:05 -04:00
|
|
|
$('body').on('click', '.js-toggle-button', function(e) {
|
2017-01-25 00:12:06 -05:00
|
|
|
toggleContainer($(this).closest('.js-toggle-container'));
|
2017-03-14 12:47:05 -04:00
|
|
|
|
2017-03-21 17:57:12 -04:00
|
|
|
const targetTag = e.currentTarget.tagName.toLowerCase();
|
2017-03-14 12:47:05 -04:00
|
|
|
if (targetTag === 'a' || targetTag === 'button') {
|
|
|
|
e.preventDefault();
|
|
|
|
}
|
2016-07-24 16:45:11 -04:00
|
|
|
});
|
|
|
|
|
2016-07-31 21:17:19 -04:00
|
|
|
// If we're accessing a permalink, ensure it is not inside a
|
|
|
|
// closed js-toggle-container!
|
|
|
|
var hash = w.gl.utils.getLocationHash();
|
|
|
|
var anchor = hash && document.getElementById(hash);
|
|
|
|
var container = anchor && $(anchor).closest('.js-toggle-container');
|
|
|
|
|
2017-01-25 00:12:06 -05:00
|
|
|
if (container) {
|
|
|
|
toggleContainer(container, true);
|
2016-07-31 21:17:19 -04:00
|
|
|
anchor.scrollIntoView();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
})(window);
|