Error catching when no tabs are open

Look to openFiles.length on if statements within openPreviewWindow,
closeAllTabs and alphaTabs functions so we only do these processes if we
have 1 or more tabs open
This commit is contained in:
Matt Pass
2013-05-24 09:10:37 +01:00
parent d2504dac64
commit b05954eccd

View File

@@ -1653,16 +1653,18 @@ var ICEcoder = {
// Open/show the preview window
openPreviewWindow: function() {
var cM, filepath, filename, fileExt;
if (top.ICEcoder.openFiles.length>0) {
var cM, filepath, filename, fileExt;
filepath = top.ICEcoder.openFiles[top.ICEcoder.selectedTab-1];
filename = filepath.substr(filepath.lastIndexOf("/")+1);
fileExt = filename.substr(filename.lastIndexOf(".")+1);
cM = ICEcoder.getcMInstance();
filepath = top.ICEcoder.openFiles[top.ICEcoder.selectedTab-1];
filename = filepath.substr(filepath.lastIndexOf("/")+1);
fileExt = filename.substr(filename.lastIndexOf(".")+1);
cM = ICEcoder.getcMInstance();
top.ICEcoder.previewWindow = window.open(filepath,"previewWindow");
if (["md"].indexOf(fileExt) > -1) {
top.ICEcoder.previewWindow.onload = function() {top.ICEcoder.previewWindow.document.documentElement.innerHTML = mmd(cM.getValue())};
top.ICEcoder.previewWindow = window.open(filepath,"previewWindow");
if (["md"].indexOf(fileExt) > -1) {
top.ICEcoder.previewWindow.onload = function() {top.ICEcoder.previewWindow.document.documentElement.innerHTML = mmd(cM.getValue())};
}
}
},
@@ -1911,7 +1913,7 @@ var ICEcoder = {
// Close all tabs
closeAllTabs: function() {
if (ICEcoder.ask("Close all tabs?")) {
if (top.ICEcoder.cMInstances.length>0 && ICEcoder.ask("Close all tabs?")) {
for (var i=top.ICEcoder.cMInstances.length; i>0; i--) {
top.ICEcoder.closeTab(i, i>1? true:false);
}
@@ -2054,32 +2056,34 @@ var ICEcoder = {
// Alphabetize tabs
alphaTabs: function() {
var currentArray, currentArrayFull, alphaArray, nextValue, nextPos;
currentArray = [];
currentArrayFull = [];
alphaArray = [];
for (var i=0;i<top.ICEcoder.openFiles.length;i++) {
currentArray.push(top.ICEcoder.openFiles[i].slice(top.ICEcoder.openFiles[i].lastIndexOf('/')+1));
currentArrayFull.push(top.ICEcoder.openFiles[i]);
top.document.getElementById('tab'+(i+1)).className = "tab tabSlide";
}
while (currentArray.length>0) {
nextValue = currentArray[0];
nextValueFull = currentArrayFull[0];
nextPos = 0;
for (var i=0;i<currentArray.length;i++) {
if (currentArray[i] < nextValue) {
nextValue = currentArray[i];
nextValueFull = top.ICEcoder.openFiles[top.ICEcoder.openFiles.indexOf(currentArrayFull[i])];
nextPos = i;
}
if (top.ICEcoder.cMInstances.length>0) {
var currentArray, currentArrayFull, alphaArray, nextValue, nextPos;
currentArray = [];
currentArrayFull = [];
alphaArray = [];
for (var i=0;i<top.ICEcoder.openFiles.length;i++) {
currentArray.push(top.ICEcoder.openFiles[i].slice(top.ICEcoder.openFiles[i].lastIndexOf('/')+1));
currentArrayFull.push(top.ICEcoder.openFiles[i]);
top.document.getElementById('tab'+(i+1)).className = "tab tabSlide";
}
alphaArray.push((top.ICEcoder.openFiles.indexOf(nextValueFull)+1));
currentArray.splice(nextPos,1);
currentArrayFull.splice(nextPos,1);
while (currentArray.length>0) {
nextValue = currentArray[0];
nextValueFull = currentArrayFull[0];
nextPos = 0;
for (var i=0;i<currentArray.length;i++) {
if (currentArray[i] < nextValue) {
nextValue = currentArray[i];
nextValueFull = top.ICEcoder.openFiles[top.ICEcoder.openFiles.indexOf(currentArrayFull[i])];
nextPos = i;
}
}
alphaArray.push((top.ICEcoder.openFiles.indexOf(nextValueFull)+1));
currentArray.splice(nextPos,1);
currentArrayFull.splice(nextPos,1);
}
top.ICEcoder.sortTabs(alphaArray);
}
top.ICEcoder.sortTabs(alphaArray);
},
// ==============