Commit bf060e393aab9345aad05a660168970f7ba50bce

Lea Verou 2012-07-11T02:09:22

Fixed code iframes

diff --git a/code.js b/code.js
index e281351..dc78a8a 100644
--- a/code.js
+++ b/code.js
@@ -2,11 +2,14 @@ $$('iframe').forEach(function(iframe) {
 	(iframe.onload = function() {	
 		var doc = iframe.contentDocument,
 		    pre = $('pre', doc),
-		    language = /.css$/.test(iframe.src)? 'css' : 'javascript';
-		
+		    language = /.css$/.test(iframe.src)? 'css' : 'javascript',
+		    depth = (iframe.getAttribute('src').match(/\//g) || []).length,
+		    pathPrefix = Array(depth + 1).join('../');
+
 		if(!pre) {
 			return;
 		}
+		
 		iframe.onload = null;
 
 		pre.className = 'prism language-' + language;
@@ -20,7 +23,7 @@ $$('iframe').forEach(function(iframe) {
 		
 		$u.element.create('link', {
 			properties: {
-				href: 'style.css',
+				href: pathPrefix + 'style.css',
 				rel: 'stylesheet'
 			},
 			inside: $('head', doc)
@@ -28,7 +31,7 @@ $$('iframe').forEach(function(iframe) {
 		
 		$u.element.create('link', {
 			properties: {
-				href: 'prism.css',
+				href: pathPrefix + 'prism.css',
 				rel: 'stylesheet'
 			},
 			inside: $('head', doc)