Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
galaxyproject
GitHub Repository: galaxyproject/training-material
Path: blob/main/assets/js/main.js
2613 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:not(.nobox)").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
document.querySelectorAll(`.${value} h1,.${value} h2,.${value}`).forEach(el => el.setAttribute("data-toc-skip",""));
76
77
})
78
79
document.querySelectorAll(`.${text}`).forEach(el => el.classList.remove("gtn-cyoa-hidden"));
80
document.querySelectorAll(`.${text} h1,.${text} h2,.${text}`).forEach(el => {
81
if (el.getAttributeNode("data-toc-skip")) {
82
el.removeAttributeNode(el.getAttributeNode("data-toc-skip"));
83
}
84
});
85
86
var $myNav = $("#toc");
87
$myNav.empty();
88
Toc.init({
89
$nav: $("#toc")
90
});
91
92
// Just in case we mark it as checked (e.g. if default/from URL)
93
var input_el = document.querySelector(`input[value="${text}"]`)
94
// Can be undefined
95
if(input_el) {
96
input_el.checked = true;
97
}
98
}
99
}
100
101
function cyoaDefault(defaultOption, cyoaId){
102
// Start with the URL parameter
103
var loc = new URL(document.location)
104
var urlOption = loc.searchParams.get(cyoaId);
105
if(urlOption){
106
cyoaChoice(urlOption, cyoaId);
107
return;
108
}
109
110
// Otherwise fall back to local storage (survives refreshes)
111
var lsOption;
112
try {
113
lsOption = localStorage.getItem(`${cyoaId}-${loc.pathname}`);
114
} catch(e) {
115
// Helaas pindakaas
116
}
117
if(lsOption !== null && lsOption !== undefined){
118
cyoaChoice(lsOption, cyoaId);
119
return;
120
}
121
122
// Otherwise if the browser is remembering for us, use that.
123
var currentlySelected = [...document.querySelectorAll("input[name='cyoa']")].filter(x => x.checked)[0];
124
if(currentlySelected){
125
cyoaChoice(currentlySelected, cyoaId);
126
return;
127
}
128
129
// And failing that, use the default.
130
cyoaChoice(defaultOption, cyoaId);
131
}
132
133
(function (window, document) {
134
function onDocumentReady(fn) {
135
if (document.attachEvent ? document.readyState === "complete" : document.readyState !== "loading") {
136
fn();
137
} else {
138
document.addEventListener('DOMContentLoaded', fn);
139
}
140
}
141
142
onDocumentReady(function () {
143
// If you pass `?with-answers` to an URL, it will automatically open
144
// the `<details>` blocks (i.e. the Q&A sections most of the time).
145
var withAnswers = (new URL(document.location)).searchParams.get("with-answers");
146
if (withAnswers !== null) {
147
// Same as above selector
148
$(".solution>.box-title button,.details>.box-title button").click();
149
}
150
151
var expandAll = (new URL(document.location)).searchParams.get("expand-all");
152
if (expandAll !== null) {
153
$(".solution>.box-title button,.details>.box-title button,.tip>.box-title button").click();
154
155
}
156
// collapse all boxes on the faq overview pages
157
if (window.location.href.indexOf("faqs") > -1) {
158
$(".hands_on>.box-title,.question>.box-title,.comment>.box-title").click();
159
}
160
161
var handsOnOnly = (new URL(document.location)).searchParams.get("only-hands-on");
162
if(handsOnOnly !== null) {
163
$(".tutorial .container .col-sm-10>:not(.hands_on)").hide()
164
}
165
});
166
167
})(window, document);
168
169
170
// Redirects
171
//if(window.location.hostname === "galaxyproject.github.io") {
172
// // Redirect
173
// var redirect = "https://training.galaxyproject.org" + window.location.pathname + window.location.search;
174
// $('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>");
175
176
// window.setTimeout(function(){
177
// window.location.href = redirect;
178
// }, 5000)
179
//}
180
181
// Copy paste buttons
182
document.querySelectorAll('div.highlight').forEach((snippet) => {
183
// Google translate has additional #text nodes mixed in with
184
// the pre for some reason.
185
var gtn_snippet_pres = [...snippet.childNodes].filter(x => x.tagName == "PRE")
186
if(gtn_snippet_pres && gtn_snippet_pres.length > 0){
187
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>');
188
}
189
});
190
191
var clipboardSnippets=new ClipboardJS('[data-clipboard-snippet]',{
192
target:function(trigger){return trigger.nextElementSibling;
193
}});
194
195
// Cited blockquotes
196
document.querySelectorAll("blockquote[cite],blockquote[author]").forEach(bq => {
197
let bq_cite = bq.getAttribute("cite");
198
let bq_url = bq_cite ? `<cite class="text-muted"><a href="${bq_cite}"><i>Source</i></a></cite>` : "";
199
let bq_author = bq.getAttribute("author") ? "— " + bq.getAttribute("author") + " " : "";
200
bq.insertAdjacentHTML("beforeend", `<footer>${bq_author}${bq_url}</footer>`)
201
})
202
203
204
205