diff options
[OKG] Added a practicum template for the future, and added needed javascript files
1 files changed, 40 insertions, 0 deletions
| -rw-r--r-- | Year 2/Computer Graphics Fundamentals/okg-prac-helper.js | 40 |
diff --git a/Year 2/Computer Graphics Fundamentals/okg-prac-helper.js b/Year 2/Computer Graphics Fundamentals/okg-prac-helper.js new file mode 100644 index 0000000..58c12a2 --- /dev/null +++ b/Year 2/Computer Graphics Fundamentals/okg-prac-helper.js @@ -0,0 +1,40 @@ +/* Create + * <nav id="scrCont"><select id="scrSel"></select></nav> + */ + +const scrCont = document.createElement('nav'); +scrCont.id = 'scrCont'; +document.body.insertBefore(scrCont, document.body.firstChild); + +const scrSel = document.createElement('select'); +scrSel.id = 'scrSel'; +scrCont.appendChild(scrSel); + +/* Add options to scrSel, from scripts array */ + +for (var i = 0; i < scripts.length; i++) { + var temp = document.createElement('option'); + temp.value = i; + temp.text = scripts[i][0]; + scrSel.appendChild(temp); +} + + +/* Logic for changing rendered object */ + +function renderScr (index) { + var temp = document.createElement('script'); + temp.src = scripts[index][1]; + temp.id = scripts[index][1]; + document.body.appendChild(temp); +} + +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]); + renderScr(scrSel.value); + oldIndex = scrSel.value; +} |
