Summary Files Commits Branches @commit @diff @stats
diff options
context:
space:
mode:
1 files changed, 27 insertions, 3 deletions
-rw-r--r--Year 2/Computer Graphics Fundamentals/okg-prac-helper.js30
diff --git a/Year 2/Computer Graphics Fundamentals/okg-prac-helper.js b/Year 2/Computer Graphics Fundamentals/okg-prac-helper.js
index 58c12a2..fdc2619 100644
--- a/Year 2/Computer Graphics Fundamentals/okg-prac-helper.js
+++ b/Year 2/Computer Graphics Fundamentals/okg-prac-helper.js
@@ -10,6 +10,11 @@ const scrSel = document.createElement('select');
scrSel.id = 'scrSel';
scrCont.appendChild(scrSel);
+const reloadBtn = document.createElement('button');
+reloadBtn.id = 'reloadBtn';
+reloadBtn.innerHTML = 'Reload';
+scrCont.appendChild(reloadBtn);
+
/* Add options to scrSel, from scripts array */
for (var i = 0; i < scripts.length; i++) {
@@ -30,11 +35,30 @@ function renderScr (index) {
}
var oldIndex = scrSel.value;
-renderScr(scrSel.value);
scrSel.onchange = function() {
- document.body.removeChild(document.getElementById(scripts[oldIndex][1]));
- document.body.removeChild(document.getElementsByTagName('canvas')[0]);
+ try {
+ document.body.removeChild(document.getElementById(scripts[oldIndex][1]));
+ document.body.removeChild(document.getElementsByTagName('canvas')[0]);
+ } catch(e) {}
+
renderScr(scrSel.value);
oldIndex = scrSel.value;
+ localStorage.setItem('render', scrSel.value);
+}
+
+if (localStorage.getItem('render') !== 0 && localStorage.getItem('render')) {
+ scrSel.value = localStorage.getItem('render');
+ scrSel.onchange();
+} else {
+ renderScr(scrSel.value);
+}
+
+reloadBtn.onclick = function() {
+ try {
+ document.body.removeChild(document.getElementById(scripts[oldIndex][1]));
+ document.body.removeChild(document.getElementsByTagName('canvas')[0]);
+ } catch(e) {}
+
+ renderScr(oldIndex);
}