From ecb378a433608254fce437a4347d830041ad85cc Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Wed, 18 Mar 2015 12:57:02 +0100 Subject: Execute scripts in page --- js/main.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'js') 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; -- cgit v1.2.1