-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
utils.js
61 lines (55 loc) · 1.86 KB
/
utils.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
53
54
55
56
57
58
59
60
61
/**
* @file Primerpedia Utility Functions
*/
// This file only provides static global functions,
// which are called from primerpedia.js; so we tell eslint
// to ignore the "no unused variables" check for this entire file:
/* eslint-disable no-unused-vars */
/**
* Remove any Child Nodes from an Element
* @param {HTMLElement} node - any DOM Node
*/
function clearNode(node) {
var clone = node.cloneNode(false);
node.parentNode.replaceChild(clone, node);
return clone;
}
/**
* Changes Visibility of an HTMLElement
* @param {HTMLElement} element - any DOM Node
* @param {boolean} visibility - show or hide DOM Node
*/
function toggleVisibility(element, visibility) {
if(element instanceof HTMLElement) {
if(!visibility) {
element.style.setProperty("display", "none");
} else {
element.style.removeProperty("display");
}
}
}
/**
* Get query string from URL parameter
*
* @see [origin on stackoverflow]{@link https://stackoverflow.com/a/2091331/266309}
* @param {string} parameter - Name of the query parameter to retrieve
* @returns {string|null} - Decoded query parameter or null
*/
function getQueryVariable(parameter) {
// Get query string, excluding the first character, "?"
var query = window.location.search.substring(1);
// Split each parameter=value pair using "&" as separator
var vars = query.split("&");
// Loop over all the parameter=value pairs, and split them into their parameter/value components
for(var i = 0; i < vars.length; i++) {
var pair = vars[i].split("=");
// If one of the parameter names is the one we're looking for, return its value
if(decodeURIComponent(pair[0]) == parameter) {
return decodeURIComponent(pair[1]);
}
}
return null;
}
function prefixUrl(language) {
return "https://" + language + ".";
}