forked from pytorch/pytorch.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhub-filter.js
52 lines (44 loc) · 1.12 KB
/
hub-filter.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
$(".hub-filter[data-tag]").on("click", function(e) {
e.preventDefault();
var tag = $(this).data("tag");
if (tag) {
showCardsByTag(tag, ".research-hub-card-wrapper", "tags");
} else {
$(".hub-filter").show();
}
updateMenuSelection(tag, ".research-menu .hub-filter", "data-tag");
});
$(".right-hub-filter[data-right-tag]").on("click", function(e) {
e.preventDefault();
var rightTag = $(this).data("right-tag");
if (rightTag) {
showCardsByTag(rightTag, ".hub-card-wrapper", "right-tags");
} else {
$(".hub-filter").show();
}
updateMenuSelection(
rightTag,
".development-menu .right-hub-filter",
"data-right-tag"
);
});
function showCardsByTag(tag, wrapper, dataTags) {
if (tag === "all") {
$(wrapper).show();
return;
}
$(wrapper).each(function(i, el) {
var targets = $(el)
.data(dataTags)
.split(",");
if (targets.indexOf(tag) > -1) {
$(el).show();
} else {
$(el).hide();
}
});
}
function updateMenuSelection(tag, menu, dataTags) {
$(menu).removeClass("selected");
$(menu + "[" + dataTags + "=" + tag + "]").addClass("selected");
}