Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
galaxyproject
GitHub Repository: galaxyproject/training-material
Path: blob/main/assets/js/main.js
1677 views
1
// make boxes collapsible
2
//LEGACY
3
$(".solution>h3,.details>h3,.tip>h3,.question>h3,.hands_on>h3,.comment>h3").click(function(event) {
4
$(">*:not(h3)", $(this).parent()).toggle(400);
5
$(">span.fold-unfold", this).toggleClass("fa-plus-square fa-minus-square");
6
});
7
8
//NEW
9
$("blockquote.solution>.box-title>button,blockquote.details>.box-title>button,blockquote.tip>.box-title>button,blockquote.question>.box-title>button,blockquote.hands_on>.box-title>button,blockquote.comment>.box-title>button").click(function(event) {
10
// If they click the icons, we need to make sure we have a reference to the button properly
11
var button;
12
if(event.target.nodeName === "BUTTON"){
13
button = $(event.target)
14
} else {
15
button = $(event.target).parents("button");
16
}
17
// Then we can collapse specifically things based on the button's ancestry
18
var parentBlockquote = button.parents("blockquote")[0];
19
20
// Collapse every child of the blockquote, that is NOT a box-title
21
$(">*:not(.box-title)", parentBlockquote).toggleClass("box-collapsed");
22
// And toggle our icon
23
$(">span.fold-unfold", button).toggleClass("fa-plus-square fa-minus-square");
24
25
// Naturally we also need to toggle the aria-expanded attribute to make sure we're accessible
26
$(this).attr("aria-expanded",
27
// if it's collapsed (i.e. showing plus icon indicating expanding)
28
$(">span.fold-unfold", this).hasClass("fa-plus-square") ?
29
// mark as collapsed
30
"false" : "true"
31
);
32
});
33
34
// collapse some box types by default
35
// LEGACY
36
$(".solution>h3,.details>h3,.tip>h3").each(function() {
37
$(">*:not(h3)", $(this.parent)).toggle("box-collapsed");
38
$(this).append("<span role='button' class='fold-unfold fa fa-plus-square'></span>");
39
});
40
41
42
// NEW
43
$("blockquote.solution,blockquote.details,blockquote.tip").each(function() {
44
$(">.box-title>button", this).click();
45
});
46
47
$("section#tutorial-content .hands_on,section#tutorial-content .hands-on").each((idx, el) => {
48
var box_id = $(".box-title", el).attr("id");
49
$(el).append(`
50
<p class="text-muted post-faq-box hide-when-printing" style="text-align:right;font-size:0.9rem;">
51
<a href="#${box_id}">Link to here</a> |
52
<i class="far fa-question-circle" aria-hidden="true"></i> <a href="./faqs/">FAQs</a> |
53
<a href="https://gitter.im/Galaxy-Training-Network/Lobby">Gitter Chat</a> |
54
<a href="https://help.galaxyproject.org">Help Forum</a>
55
</p>`
56
);
57
})
58
59
// CYOA Support
60
function cyoaChoice(text, cyoaId){
61
if(text !== undefined && text !== null){
62
var loc = new URL(document.location)
63
try {
64
localStorage.setItem(`${cyoaId}-${loc.pathname}`, text);
65
} catch(e) {
66
// Helaas pindakaas
67
}
68
69
var inputs = document.querySelectorAll(`#${cyoaId} input`),
70
options = [...inputs].map(x => x.value),
71
nonMatchingOptions = options.filter(x => x !== text);
72
73
nonMatchingOptions.forEach(value => {
74
document.querySelectorAll(`.${value}`).forEach(el => el.classList.add("gtn-cyoa-hidden"));
75
})
76
77
document.querySelectorAll(`.${text}`).forEach(el => el.classList.remove("gtn-cyoa-hidden"));
78
79
// Just in case we mark it as checked (e.g. if default/from URL)
80
var input_el = document.querySelector(`input[value="${text}"]`)
81
// Can be undefined
82
if(input_el) {
83
input_el.checked = true;
84
}
85
}
86
}
87
88
function cyoaDefault(defaultOption, cyoaId){
89
// Start with the URL parameter
90
var loc = new URL(document.location)
91
var urlOption = loc.searchParams.get(cyoaId);
92
if(urlOption){
93
cyoaChoice(urlOption, cyoaId);
94
return;
95
}
96
97
// Otherwise fall back to local storage (survives refreshes)
98
var lsOption;
99
try {
100
lsOption = localStorage.getItem(`${cyoaId}-${loc.pathname}`);
101
} catch(e) {
102
// Helaas pindakaas
103
}
104
if(lsOption !== null && lsOption !== undefined){
105
cyoaChoice(lsOption, cyoaId);
106
return;
107
}
108
109
// Otherwise if the browser is remembering for us, use that.
110
var currentlySelected = [...document.querySelectorAll("input[name='cyoa']")].filter(x => x.checked)[0];
111
if(currentlySelected){
112
cyoaChoice(currentlySelected, cyoaId);
113
return;
114
}
115
116
// And failing that, use the default.
117
cyoaChoice(defaultOption, cyoaId);
118
}
119
120
(function (window, document) {
121
function onDocumentReady(fn) {
122
if (document.attachEvent ? document.readyState === "complete" : document.readyState !== "loading") {
123
fn();
124
} else {
125
document.addEventListener('DOMContentLoaded', fn);
126
}
127
}
128
129
onDocumentReady(function () {
130
// If you pass `?with-answers` to an URL, it will automatically open
131
// the `<details>` blocks (i.e. the Q&A sections most of the time).
132
var withAnswers = (new URL(document.location)).searchParams.get("with-answers");
133
if (withAnswers !== null) {
134
// Same as above selector
135
$(".solution>.box-title button,.details>.box-title button").click();
136
}
137
138
var expandAll = (new URL(document.location)).searchParams.get("expand-all");
139
if (expandAll !== null) {
140
$(".solution>.box-title button,.details>.box-title button,.tip>.box-title button").click();
141
142
}
143
// collapse all boxes on the faq overview pages
144
if (window.location.href.indexOf("faqs") > -1) {
145
$(".hands_on>.box-title,.question>.box-title,.comment>.box-title").click();
146
}
147
148
var handsOnOnly = (new URL(document.location)).searchParams.get("only-hands-on");
149
if(handsOnOnly !== null) {
150
$(".tutorial .container .col-sm-10>:not(.hands_on)").hide()
151
}
152
});
153
154
})(window, document);
155
156
157
function fixDiffPresentation(codeBlock){
158
codeBlock.childNodes.forEach(x => {
159
if(x.nodeName == '#text'){
160
x.textContent = x.textContent.split('\n').map(q => { return q.startsWith(" ") ? q.slice(1) : q }).join('\n')
161
} else {
162
if(!(x.nodeName.toLowerCase() === 'span' && x.classList[0] === 'notranslate')){
163
var fixed = $(x).text().split('\n').map(q => { return q.slice(1) }).join('\n');
164
$(x).text(fixed);
165
}
166
}
167
})
168
}
169
170
// For admin training
171
document.querySelectorAll("article.topic-admin section#tutorial-content div.language-diff pre code").forEach(codeBlock => fixDiffPresentation(codeBlock))
172
document.querySelectorAll("article.topic-data-science section#tutorial-content div.language-diff pre code").forEach(codeBlock => fixDiffPresentation(codeBlock))
173
174
// Redirects
175
//if(window.location.hostname === "galaxyproject.github.io") {
176
// // Redirect
177
// var redirect = "https://training.galaxyproject.org" + window.location.pathname + window.location.search;
178
// $('div.container.main-content').prepend("<div class='alert alert-warning'><strong>Note: </strong>This content has a new home at <a href=\"" + redirect + "\">" + redirect + "</a>, which you will be redirected to in 5 seconds.</div>");
179
180
// window.setTimeout(function(){
181
// window.location.href = redirect;
182
// }, 5000)
183
//}
184
185
// Copy paste buttons
186
document.querySelectorAll('div.highlight').forEach((snippet) => {
187
// Google translate has additional #text nodes mixed in with
188
// the pre for some reason.
189
var gtn_snippet_pres = [...snippet.childNodes].filter(x => x.tagName == "PRE")
190
if(gtn_snippet_pres && gtn_snippet_pres.length > 0){
191
gtn_snippet_pres[0].insertAdjacentHTML('beforebegin','<button class="btn btn-light" data-clipboard-snippet tabindex="0"><i class="fa fa-copy"></i>&nbsp;Copy</button>');
192
}
193
});
194
195
var clipboardSnippets=new ClipboardJS('[data-clipboard-snippet]',{
196
target:function(trigger){return trigger.nextElementSibling;
197
}});
198
199
// Cited blockquotes
200
document.querySelectorAll("blockquote[cite],blockquote[author]").forEach(bq => {
201
let bq_cite = bq.getAttribute("cite");
202
let bq_url = bq_cite ? `<cite class="text-muted"><a href="${bq_cite}"><i>Source</i></a></cite>` : "";
203
let bq_author = bq.getAttribute("author") ? "— " + bq.getAttribute("author") + " " : "";
204
bq.insertAdjacentHTML("beforeend", `<footer>${bq_author}${bq_url}</footer>`)
205
})
206
207