From d87e932030dce40dfa3c23d5920a1c5fc3458616 Mon Sep 17 00:00:00 2001 From: Matt Pass Date: Tue, 30 Apr 2013 08:07:03 +0100 Subject: [PATCH] Live editing of CSS files Tries to find CSS files in the stickyTab shown window. If it does it appends a new stylesheet to it as you type. --- editor.php | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/editor.php b/editor.php index ec873f3..a473752 100644 --- a/editor.php +++ b/editor.php @@ -181,10 +181,23 @@ function createNewCMInstance(num) { } // Update HTML edited files live if (top.ICEcoder.stickyTab.location) { - var filename = top.ICEcoder.openFiles[top.ICEcoder.selectedTab-1]; + var filepath = top.ICEcoder.openFiles[top.ICEcoder.selectedTab-1]; + var filename = filepath.substr(filepath.lastIndexOf("/")+1); var fileExt = filename.substr(filename.lastIndexOf(".")+1); - if (["htm","html"].indexOf(fileExt) > -1) { + if (["htm","html","txt"].indexOf(fileExt) > -1) { top.ICEcoder.stickyTab.document.documentElement.innerHTML = window['cM'+num].getValue(); + } else if (["css"].indexOf(fileExt) > -1) { + if (top.ICEcoder.stickyTab.document.documentElement.innerHTML.indexOf(filename) > -1) { + var css = window['cM'+num].getValue(); + var style = document.createElement('style'); + style.type = 'text/css'; + if (style.styleSheet){ + style.styleSheet.cssText = css; + } else { + style.appendChild(document.createTextNode(css)); + } + top.ICEcoder.stickyTab.document.documentElement.appendChild(style); + } } }; }