From b05954eccd6581ba9cf91d110731f4a1e63a8705 Mon Sep 17 00:00:00 2001 From: Matt Pass Date: Fri, 24 May 2013 09:10:37 +0100 Subject: [PATCH] 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 --- lib/ice-coder.js | 70 +++++++++++++++++++++++++----------------------- 1 file changed, 37 insertions(+), 33 deletions(-) diff --git a/lib/ice-coder.js b/lib/ice-coder.js index 5d6457e..184d24e 100644 --- a/lib/ice-coder.js +++ b/lib/ice-coder.js @@ -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;i0) { - nextValue = currentArray[0]; - nextValueFull = currentArrayFull[0]; - nextPos = 0; - for (var i=0;i0) { + var currentArray, currentArrayFull, alphaArray, nextValue, nextPos; + + currentArray = []; + currentArrayFull = []; + alphaArray = []; + for (var i=0;i0) { + nextValue = currentArray[0]; + nextValueFull = currentArrayFull[0]; + nextPos = 0; + for (var i=0;i