Skip to content
This repository was archived by the owner on Nov 22, 2019. It is now read-only.

Commit 657cf4d

Browse files
committed
Visibility filters do not work properly
In issue phpDocumentor/phpDocumentor#573 @ferjul17 mentioned that the visibility filters do not function properly. During research we discovered that the logic was faulty and that bootstrap sets the 'active' class after this event is called. With this commit we fix this behaviour and it works as expected.
1 parent 809a102 commit 657cf4d

File tree

1 file changed

+31
-12
lines changed

1 file changed

+31
-12
lines changed

js/template.js

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,37 @@ function initializeContents()
4646
.find('i').click(function(){ $(this).parent().click(); });
4747

4848
// set the events for the visibility buttons and enable by default.
49-
$('.visibility button.public').click(function(){
50-
$('.element.public,.side-nav li.public').toggle($(this).hasClass('active'));
51-
}).click();
52-
$('.visibility button.protected').click(function(){
53-
$('.element.protected,.side-nav li.protected').toggle($(this).hasClass('active'));
54-
}).click();
55-
$('.visibility button.private').click(function(){
56-
$('.element.private,.side-nav li.private').toggle($(this).hasClass('active'));
57-
}).click();
58-
$('.visibility button.inherited').click(function(){
59-
$('.element.inherited,.side-nav li.inherited').toggle($(this).hasClass('active'));
60-
}).click();
49+
function toggleVisibility(event)
50+
{
51+
// because the active class is toggled _after_ this event we toggle it for the duration of this event. This
52+
// will make the next piece of code generic
53+
if (event) {
54+
$(this).toggleClass('active');
55+
}
56+
57+
$('.element.public,.side-nav li.public').toggle($('.visibility button.public').hasClass('active'));
58+
$('.element.protected,.side-nav li.protected').toggle($('.visibility button.protected').hasClass('active'));
59+
$('.element.private,.side-nav li.private').toggle($('.visibility button.private').hasClass('active'));
60+
$('.element.public.inherited,.side-nav li.public.inherited').toggle(
61+
$('.visibility button.public').hasClass('active') && $('.visibility button.inherited').hasClass('active')
62+
);
63+
$('.element.protected.inherited,.side-nav li.protected.inherited').toggle(
64+
$('.visibility button.protected').hasClass('active') && $('.visibility button.inherited').hasClass('active')
65+
);
66+
$('.element.private.inherited,.side-nav li.private.inherited').toggle(
67+
$('.visibility button.private').hasClass('active') && $('.visibility button.inherited').hasClass('active')
68+
);
69+
70+
// and untoggle the active class again so that bootstrap's default handling keeps working
71+
if (event) {
72+
$(this).toggleClass('active');
73+
}
74+
}
75+
$('.visibility button.public').on("click", toggleVisibility);
76+
$('.visibility button.protected').on("click", toggleVisibility);
77+
$('.visibility button.private').on("click", toggleVisibility);
78+
$('.visibility button.inherited').on("click", toggleVisibility);
79+
toggleVisibility();
6180

6281
$('.type-filter button.critical').click(function() {
6382
packageContentDivs = $('.package-contents');

0 commit comments

Comments
 (0)