Skip to content

Commit

Permalink
Refactor 'closed' class assignment.
Browse files Browse the repository at this point in the history
  • Loading branch information
cjcenizal committed May 2, 2017
1 parent 708700b commit 0edadb9
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/ui/public/collapsible_sidebar/collapsible_sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,28 @@ uiModules
return $siblings.hasClass(className) && className;
}, false);

$collapser.on('click', function () {
$elem.toggleClass('closed');
// If there is are only two elements we can assume the other one will take 100% of the width.
const hasSingleSibling = $siblings.length === 1 && siblingsClass;

$collapser.on('click', function () {
if (isCollapsed) {
isCollapsed = false;
$elem.removeClass('closed');
$icon.addClass('fa-chevron-circle-left');
$icon.removeClass('fa-chevron-circle-right');
} else {
isCollapsed = true;
$elem.addClass('closed');
$icon.removeClass('fa-chevron-circle-left');
$icon.addClass('fa-chevron-circle-right');
}

// if there is are only two elements we can assume the other one will take 100% of the width
if ($siblings.length === 1 && siblingsClass) {
if (hasSingleSibling) {
$siblings.toggleClass(siblingsClass + ' col-md-12');
}
})
});

.appendTo($elem);
$collapser.appendTo($elem);
}
};
});

0 comments on commit 0edadb9

Please sign in to comment.