Skip to content
This repository has been archived by the owner on Sep 15, 2020. It is now read-only.

Commit

Permalink
downloads.js: minor tweaks.
Browse files Browse the repository at this point in the history
  • Loading branch information
XhmikosR committed Jun 9, 2019
1 parent df599c4 commit 79eff70
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions source/assets/js/downloads.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@
$(function() {
'use strict';

var $el = $('.toggleLink');
var $toggleLink = $('.toggleLink');
var $totalToggleLinkCount = $('.toggleLink').length;

if ($el.length === 0) {
if ($totalToggleLinkCount === 0) {
return;
}

var collapsedToggleLinkCount = $('.toggleLink.collapsed').length;
var totalToggleLinkCount = $el.length;
var $collapsedToggleLinkCount = $('.toggleLink.collapsed').length;

function checkButtonState() {
if (collapsedToggleLinkCount === 0) {
function setButtonState() {
if ($collapsedToggleLinkCount === 0) {
// All elements are expanded
$('.closeAll').prop('disabled', false);
$('.expandAll').prop('disabled', true);
} else if (collapsedToggleLinkCount === totalToggleLinkCount) {
} else if ($collapsedToggleLinkCount === $totalToggleLinkCount) {
// All elements are collapsed
$('.closeAll').prop('disabled', true);
$('.expandAll').prop('disabled', false);
Expand All @@ -27,27 +27,27 @@ $(function() {
}
}

$el.on('click', function() {
$toggleLink.on('click', function() {
// If the .toggleLink element has the `.collapsed` class,
// decrease or increase the collapsedToggleLinkCount
// decrease or increase the $collapsedToggleLinkCount
if ($(this).hasClass('collapsed')) {
collapsedToggleLinkCount--;
$collapsedToggleLinkCount--;
} else {
collapsedToggleLinkCount++;
$collapsedToggleLinkCount++;
}

checkButtonState();
setButtonState();
});

$('.closeAll').click(function() {
$('.panel-collapse.in').collapse('hide'); // hide any `panel`s
collapsedToggleLinkCount = totalToggleLinkCount; // reset the global count
checkButtonState();
$collapsedToggleLinkCount = $totalToggleLinkCount; // reset the global count
setButtonState();
});

$('.expandAll').click(function() {
$('.panel-collapse:not(".in")').collapse('show'); // show any `panel`s
collapsedToggleLinkCount = 0; // reset the global count
checkButtonState();
$collapsedToggleLinkCount = 0; // reset the global count
setButtonState();
});
});

0 comments on commit 79eff70

Please sign in to comment.