Only update current doc & CSS append once

Now only updates the innerHTML value of the stickyTab doc if the browser
location is the same as the doc we're editing (HTML & MD files). Also
now adding an ID to the style and if it exists, remove that child DOM
elem before adding another so we only ever have 1 child for this, ie, it
gets updated by removing & adding.
This commit is contained in:
Matt Pass
2013-05-02 17:18:15 +01:00
parent d43a758a37
commit 0d01b4a2ea

View File

@@ -180,29 +180,36 @@ function createNewCMInstance(num) {
clearTimeout(window['cM'+num+'waiting']);
window['cM'+num+'waiting'] = setTimeout(top.ICEcoder.updateHints, 100);
}
var filepath = top.ICEcoder.openFiles[top.ICEcoder.selectedTab-1];
var filename = filepath.substr(filepath.lastIndexOf("/")+1);
var fileExt = filename.substr(filename.lastIndexOf(".")+1);
// Update HTML edited files live
if (top.ICEcoder.stickyTab.location) {
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","txt"].indexOf(fileExt) > -1) {
top.ICEcoder.stickyTab.document.documentElement.innerHTML = window['cM'+num].getValue();
if (top.ICEcoder.stickyTab.location.pathname==filepath) {
top.ICEcoder.stickyTab.document.documentElement.innerHTML =
["htm","html","txt"].indexOf(fileExt) > -1
? window['cM'+num].getValue()
: ["md"].indexOf(fileExt) > -1
? mmd(window['cM'+num].getValue())
: false;
} 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';
style.id = "ICEcoder"+filepath.replace(/\//g,"_");
if (style.styleSheet){
style.styleSheet.cssText = css;
} else {
style.appendChild(document.createTextNode(css));
}
if (top.ICEcoder.stickyTab.document.getElementById(style.id)) {
top.ICEcoder.stickyTab.document.documentElement.removeChild(top.ICEcoder.stickyTab.document.getElementById(style.id));
}
top.ICEcoder.stickyTab.document.documentElement.appendChild(style);
}
} else if (["md"].indexOf(fileExt) > -1) {
top.ICEcoder.stickyTab.document.documentElement.innerHTML = mmd(window['cM'+num].getValue());
}
};
}
}
);