Skip to content

Instantly share code, notes, and snippets.

@ahaywood
Created June 5, 2015 21:38
Show Gist options
  • Save ahaywood/cc2cdbb9412aab3402dd to your computer and use it in GitHub Desktop.
Save ahaywood/cc2cdbb9412aab3402dd to your computer and use it in GitHub Desktop.
PHP: WP - Expanding and collapsing archives
/* handle archives expanding / collapsing within the footer */
function initFooterArchives() {
hideArchiveMonths(); // Hide all the archive months to begin with
// Set up archive year click
$('.js-footer__archives__year').find('a').click(function(e) {
e.preventDefault();
var $parent = $(this).parent();
// If it's expanded, collapse it
if ($parent.hasClass('expanded')) {
hideArchiveMonths(); // Hide any months that are currently showing
}
// Otherwise, expand it
else {
hideArchiveMonths(); // Hide any months that are currently showing
/* cycle through each item to see if it has a month class and if it's visible */
var startingPoint = $parent;
if ( startingPoint.next().is(":visible") ) {
while (startingPoint.next().hasClass('js-footer__archives__month')) {
startingPoint.next().fadeOut();
startingPoint = startingPoint.next();
}
} else {
while (startingPoint.next().hasClass('js-footer__archives__month')) {
startingPoint.next().fadeIn();
startingPoint = startingPoint.next();
}
}
$parent.addClass('expanded');
}
});
// initialize it by "clicking" on the first year
$('.js-footer__archives__year').first().find('a').trigger('click');
}
/* hide all the archive month items in the footer
set all years to closed */
function hideArchiveMonths() {
$('.js-footer__archives__year').removeClass('expanded');
$('.js-footer__archives__month').hide();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment