-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgmlscripts38.js
More file actions
117 lines (105 loc) · 3.83 KB
/
gmlscripts38.js
File metadata and controls
117 lines (105 loc) · 3.83 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
// ONLOAD HANDLER
function start() {
setupAccordion();
}
// CLIPBOARD HANDLER
// https://stackoverflow.com/a/30810322
// This code has been modified to copy text from
// a DOM element and to hide textarea scrollbars.
// It also removes \xA0 (nbsp) characters generated
// by the innerText DOM accessor. These occur when
// it collapses lines consisting of only whitespace
// to a single space and are also generated between
// successive linebreaks. Non-critical whitespace
// in the original code is not preserved but it's
// better than inserting weird characters into it.
function copyToClipboard(id) {
var textArea = document.createElement("textarea");
textArea.style.position = "fixed";
textArea.style.top = 0;
textArea.style.left = 0;
textArea.style.width = "2em";
textArea.style.height = "2em";
textArea.style.padding = 0;
textArea.style.border = "none";
textArea.style.outline = "none";
textArea.style.boxShadow = "none";
textArea.style.overflow = "hidden";
textArea.style.background = "transparent";
textArea.value = document.getElementById(id).innerText.replace(/\u00a0/g, "");
document.body.appendChild(textArea);
textArea.focus();
textArea.select();
var successful = false;
try {
successful = document.execCommand("copy");
} catch (err) {
console.log("Copy is not supported in this browser.");
}
document.body.removeChild(textArea);
return successful;
}
function copyUpdate(e, success) {
if (success) {
e.innerText = "COPIED";
clearTimeout(timeoutID);
timeoutID = setTimeout(function () {
e.innerText = "COPY";
}, 6000);
}
return false;
}
let timeoutID = undefined;
// ACCORDION MENU HANDLER
function setupAccordion() {
// Select accordion elements
var accordion_head = document.querySelectorAll(".accordion > li > a"),
accordion_body = document.querySelectorAll(".accordion > li > ul");
for (var i = 0; i < accordion_head.length; i++) {
// Set height of initial active element
if (accordion_head[i].classList.contains("active")) {
accordion_head[i].nextElementSibling.style.maxHeight = accordion_head[i].nextElementSibling.scrollHeight + "px";
}
// Set event listeners
accordion_head[i].addEventListener("click", function (event) {
// Disable header links
event.preventDefault();
// Show and hide the tabs on click
if (this.getAttribute("class") != "active") {
accordion_active = this.parentNode.getAttribute("id");
for (var j = 0; j < accordion_body.length; j++) {
accordion_body[j].style.maxHeight = null;
}
this.nextElementSibling.style.maxHeight = this.nextElementSibling.scrollHeight + "px";
for (var j = 0; j < accordion_head.length; j++) {
accordion_head[j].classList.remove("active");
}
this.classList.add("active");
} else {
for (var j = 0; j < accordion_head.length; j++) {
accordion_head[j].classList.remove("active");
}
this.nextElementSibling.style.maxHeight = null;
}
});
}
}
// MATHJAX DISPLAY HANDLER
function showMathJax() {
var mathjax = document.querySelectorAll(".mathjax");
for (var i = 0; i < mathjax.length; i++) {
mathjax[i].style.maxHeight = mathjax[i].scrollHeight + "px";
mathjax[i].style.opacity = 1.0;
}
}
// CODE EXPANDER
function expandCode(e) {
var vscroll = e.parentNode;
if (vscroll.classList.contains("expand")) {
vscroll.classList.remove("expand");
e.textContent = "Expand";
} else {
vscroll.classList.add("expand");
e.textContent = "Collapse";
}
}