forked from kubernetes/website
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathglossary.js
More file actions
181 lines (157 loc) · 5.2 KB
/
glossary.js
File metadata and controls
181 lines (157 loc) · 5.2 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
// TODO (long-term): Would be easier to manage all this state with React
$( document ).ready(function() {
var expandText = "[+]";
var closeText = "[-]";
var selectAllKey = "all";
var deselectAllKey = "none";
var defaultActiveTag = "fundamental";
var activeTags = {};
var paramSize = function(paramHash) {
return Object.keys(paramHash).length;
}
// "Lib" for acquiring parameters from the URL
var urlParamLib = function() {
function initParams() {
var sPageURL = decodeURIComponent(window.location.search.substring(1)),
sURLVariables = sPageURL.split('&'),
sParameterName,
i;
var paramHash = {};
for (i = 0; i < sURLVariables.length; i++) {
sParameterName = sURLVariables[i].split('=');
if (sParameterName[0] != "")
paramHash[sParameterName[0]] = sParameterName[1];
}
if (paramSize(paramHash) == 0) {
paramHash[defaultActiveTag] = true;
}
return paramHash;
}
function updateParams(paramHash) {
var urlWithoutQuery = window.location.href.split('?')[0];
var urlHash = window.location.hash;
window.history.pushState(null,null, urlWithoutQuery + "?" + $.param(paramHash) + window.location.hash);
}
return {
initParams: initParams,
updateParams: updateParams,
};
}();
var initClickFunctions = function() {
var deactivateTagTerms = function(elt) {
var targetTag = elt.data("target");
var targetClass = "." + targetTag;
var tagName = targetTag.split('tag-')[1];
elt.removeClass("active-tag");
$(targetClass).each(function(){
var showCount = $(this).data("show-count");
var newShowCount = showCount - 1;
$(this).data("show-count", newShowCount);
if (newShowCount < 1) {
$(this).addClass("hide");
}
});
delete activeTags[tagName];
};
var activateTagTerms = function(elt) {
var targetTag = elt.data("target");
var targetClass = "." + targetTag;
var tagName = targetTag.split('tag-')[1];
elt.addClass("active-tag");
$(targetClass).each(function(){
var showCount = $(this).data("show-count");
var newShowCount = showCount + 1;
$(this).data("show-count", newShowCount);
if (newShowCount > 0) {
$(this).removeClass("hide");
}
});
activeTags[tagName] = true;
if (activeTags[deselectAllKey]) {
delete activeTags[deselectAllKey];
}
};
// Shows/hides glossary terms when their relevant tags are clicked
$(".canonical-tag").each(function(){
var placeholder = $("#placeholder");
var targetTag = $(this).data("target");
$(this).mouseenter(function(){
var tagDescription = $("#" + targetTag + "-description").html();
placeholder.html(tagDescription);
placeholder.removeClass('invisible');
}).mouseleave(function(){
placeholder.addClass('invisible');
});
$(this).click(function(){
var shouldHide = $(this).hasClass("active-tag");
if (shouldHide) {
deactivateTagTerms($(this));
} else {
activateTagTerms($(this));
}
urlParamLib.updateParams(activeTags);
});
});
// Adds functionality to "select all tags" link
$("#select-all-tags").click(function(){
$(".canonical-tag").each(function(){
var shouldActivate = !$(this).hasClass("active-tag");
if (shouldActivate) {
activateTagTerms($(this));
}
});
queryParams = {}
queryParams[selectAllKey] = true;
urlParamLib.updateParams(queryParams);
});
// Adds functionality to "deselect all tags" link
$("#deselect-all-tags").click(function(){
$(".canonical-tag").each(function(){
var shouldHide = $(this).hasClass("active-tag");
if (shouldHide) {
deactivateTagTerms($(this));
}
});
queryParams = {}
queryParams[deselectAllKey] = true;
urlParamLib.updateParams(queryParams);
});
// Expands/hides glossary term definitions when [+] button is clicked
$(".click-controller").each(function(){
$(this).click(function() {
var targetId = $(this).data("target");
var shouldExpand = $(this).html() == expandText;
if (shouldExpand) {
$("#" + targetId).removeClass('hide');
$(this).html(closeText);
} else {
$("#" + targetId).addClass('hide');
$(this).html(expandText);
}
});
});
// Shows permalink when term name is hovered over
$(".term-name").each(function() {
var permalink = $($(this).parent().find(".permalink")[0]);
$(this).mouseenter(function(){
permalink.removeClass("hide");
}).mouseleave(function(){
permalink.addClass("hide");
});;
});
};
function initActiveTags() {
if (activeTags[selectAllKey]) {
$("#select-all-tags").click();
} else if (activeTags[deselectAllKey]) {
$("#deselect-all-tags").click();
} else {
for (var tagId in activeTags) {
$("#tag-" + tagId).find("a")[0].click();
}
}
}
initClickFunctions();
activeTags = urlParamLib.initParams();
initActiveTags();
});