-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDOMHelpers.js
66 lines (53 loc) · 1.45 KB
/
DOMHelpers.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
62
63
64
65
66
function createToggle(params) {
var toggleWrapper = document.createElement('li'),
toggleInput = document.createElement('input'),
toggleLabel = document.createElement('label');
toggleWrapper.className = 'wikia-jw-settings__toggle';
toggleInput.className = 'wds-toggle__input';
toggleInput.id = params.id;
toggleInput.type = 'checkbox';
toggleInput.checked = params.checked;
toggleLabel.className = 'wds-toggle__label';
toggleLabel.setAttribute('for', params.id);
toggleLabel.appendChild(document.createTextNode(params.label));
toggleWrapper.appendChild(toggleInput);
toggleWrapper.appendChild(toggleLabel);
return toggleWrapper;
}
/**
* Available directions:
* - left
* - right
*
* @param {String} direction
* @returns {HTMLElement}
*/
function createArrowIcon(direction) {
var arrowIcon = createSVG(wikiaJWPlayerIcons.back);
if (direction === 'left') {
arrowIcon.classList.add('wikia-jw-settings__back-icon');
} else {
arrowIcon.classList.add('wikia-jw-settings__right-arrow-icon');
}
return arrowIcon;
}
function clearListElement(element) {
if (element) {
while (element.childElementCount > 1) {
element.removeChild(element.firstChild);
}
}
}
function createSVG(svgHtml) {
return domParser.parseFromString(svgHtml, 'image/svg+xml').documentElement;
}
function showElement(element) {
if (element) {
element.style.display = 'block';
}
}
function hideElement(element) {
if (element) {
element.style.display = 'none';
}
}