Fixed code iframes
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
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)