summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorPeter Wu <peter@lekensteyn.nl>2015-03-18 12:57:02 +0100
committerPeter Wu <peter@lekensteyn.nl>2015-03-18 12:57:02 +0100
commitecb378a433608254fce437a4347d830041ad85cc (patch)
tree1a72e7b929844bc93e9e021948b429b17becd1a6 /js
parenta7530e4ef857ebb7bbe92b1aa07157f8475ea55e (diff)
downloadsite-ecb378a433608254fce437a4347d830041ad85cc.tar.gz
Execute scripts in page
Diffstat (limited to 'js')
-rw-r--r--js/main.js18
1 files changed, 16 insertions, 2 deletions
diff --git a/js/main.js b/js/main.js
index c3191f6..34e0890 100644
--- a/js/main.js
+++ b/js/main.js
@@ -1,17 +1,31 @@
define(function() {
'use strict';
+ var all_pages = 'home studying curriculum campus career'.split(' ');
+
/* loads a page into view and execute scripts */
function loadContent(name, text) {
var contentElement = document.getElementById('content');
contentElement.innerHTML = text;
document.body.dataset.page = name;
+
+ // execute scripts in page
+ [].forEach.call(contentElement.getElementsByTagName('script'),
+ function(origScript) {
+ var script = document.createElement('script');
+ // copy attributes
+ [].forEach.call(origScript.attributes, function(a) {
+ script.setAttribute(a.name, a.value);
+ });
+ // copy contents
+ script.textContent = origScript.textContent;
+ origScript.parentNode.replaceChild(script, origScript);
+ });
}
/* tries to navigate to a page */
function selectPage(page) {
- var pages = 'home studying curriculum campus career'.split(' ');
- if (pages.indexOf(page) == -1) {
+ if (all_pages.indexOf(page) == -1) {
// TODO: 404
console.log("404 " + page);
return false;