diff options
author | Peter Wu <peter@lekensteyn.nl> | 2015-03-18 12:57:02 +0100 |
---|---|---|
committer | Peter Wu <peter@lekensteyn.nl> | 2015-03-18 12:57:02 +0100 |
commit | ecb378a433608254fce437a4347d830041ad85cc (patch) | |
tree | 1a72e7b929844bc93e9e021948b429b17becd1a6 /js | |
parent | a7530e4ef857ebb7bbe92b1aa07157f8475ea55e (diff) | |
download | site-ecb378a433608254fce437a4347d830041ad85cc.tar.gz |
Execute scripts in page
Diffstat (limited to 'js')
-rw-r--r-- | js/main.js | 18 |
1 files changed, 16 insertions, 2 deletions
@@ -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; |