Skip to content

Commit 8170b3b

Browse files
committed
Fix for #210: selected sidebar group is collapsable
1 parent 86ab9ec commit 8170b3b

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

scripts/createWebBook.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,10 @@ def returnChapterByCommonName( commonName ):
329329
# Create a chapter group LI
330330
groupLi = Tag(soup, None, "li")
331331
groupLi['class']="group"
332-
groupLi.append( group['groupName'])
332+
groupTitle = Tag(soup, None, 'div')
333+
groupTitle['class'] = 'groupTitle'
334+
groupTitle.string = group['groupName']
335+
groupLi.append(groupTitle)
333336
navbar.append(groupLi)
334337

335338
# Run through the chapters of the group

static/javascript/navbar.js

+20-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,27 @@
11
$(document).ready(function() {
22

3+
// Handle selecting & unselecting chapter groups in the sidebar
4+
var $selectedGroup = $('.group.selected');
35
$(".group").click(function() {
4-
$('.group.selected').removeClass('selected');
6+
// Pull out the element that to which the click event is bound (li.group)
7+
var newSelected = event.currentTarget;
58

6-
$(this).addClass('selected');
7-
})
9+
if ($selectedGroup.length && ($selectedGroup.get(0) === newSelected)) {
10+
// Clicked on already selected group, but only unselect the current group
11+
// if the click happened over the title div. This helps prevents
12+
// accidentally closing the group, e.g. if click happened in-between
13+
// chapter links.
14+
if ($(event.target).hasClass('groupTitle')) {
15+
$selectedGroup.removeClass('selected');
16+
$selectedGroup = $(); // Empty selection
17+
}
18+
} else {
19+
// Clicked on a new group
20+
$selectedGroup.removeClass('selected');
21+
$selectedGroup = $(newSelected);
22+
$selectedGroup.addClass('selected');
23+
}
24+
});
825

926

1027
// Cache selectors

static/style/_navbar.scss

+4
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ nav {
3434
overflow: hidden;
3535
max-height:42px;
3636
transition: all 0.3s;
37+
38+
.groupTitle {
39+
cursor: pointer;
40+
}
3741

3842
&.selected {
3943
background-color: rgba(255,255,255,1);

0 commit comments

Comments
 (0)