diff --git a/lib/ice-coder.js b/lib/ice-coder.js index 6209b6d..74229a1 100644 --- a/lib/ice-coder.js +++ b/lib/ice-coder.js @@ -1005,46 +1005,48 @@ var ICEcoder = { var cM, nestCheck, state, cx, startPos, fileName, events; cM = ICEcoder.getcMInstance(); - nestCheck = cM.getValue(); + if (cM) { + nestCheck = cM.getValue(); - // Set up array to store nest data - state = cM.getTokenAt(cM.getCursor()).state; - if ("undefined" != typeof state.curState) { - ICEcoder.htmlTagArray = []; - for (cx = state.curState.context; cx; cx = cx.prev) { - if ("undefined" != typeof cx.tagName) { - ICEcoder.htmlTagArray.unshift(cx.tagName); + // Set up array to store nest data + state = cM.getTokenAt(cM.getCursor()).state; + if ("undefined" != typeof state.curState) { + ICEcoder.htmlTagArray = []; + for (cx = state.curState.context; cx; cx = cx.prev) { + if ("undefined" != typeof cx.tagName) { + ICEcoder.htmlTagArray.unshift(cx.tagName); + } } } - } - ICEcoder.tagString = ICEcoder.htmlTagArray[ICEcoder.htmlTagArray.length-1]; - if (ICEcoder.caretLocType=="JavaScript") { - ICEcoder.tagString = "script"; - } + ICEcoder.tagString = ICEcoder.htmlTagArray[ICEcoder.htmlTagArray.length-1]; + if (ICEcoder.caretLocType=="JavaScript") { + ICEcoder.tagString = "script"; + } - // Now we've built up our nest depth array, if we're due to show it in the display - if (updateNestDisplay && !top.ICEcoder.dontUpdateNest) { - // Clear the display - ICEcoder.nestDisplayText.innerHTML = ""; - ICEcoder.nestDisplay.innerHTML = ""; - if ("undefined" != typeof ICEcoder.openFiles[ICEcoder.selectedTab-1]) { - fileName = ICEcoder.openFiles[ICEcoder.selectedTab-1]; - if (["js","coffee","rb","css","less"].indexOf(fileName.split(".")[1])<0 && - (nestCheck.indexOf("include(")==-1)&&(nestCheck.indexOf("include_once(")==-1)&& - (nestCheck.indexOf("-1||nestCheck.indexOf("-1)) { + // Now we've built up our nest depth array, if we're due to show it in the display + if (updateNestDisplay && !top.ICEcoder.dontUpdateNest) { + // Clear the display + ICEcoder.nestDisplayText.innerHTML = ""; + ICEcoder.nestDisplay.innerHTML = ""; + if ("undefined" != typeof ICEcoder.openFiles[ICEcoder.selectedTab-1]) { + fileName = ICEcoder.openFiles[ICEcoder.selectedTab-1]; + if (["js","coffee","rb","css","less"].indexOf(fileName.split(".")[1])<0 && + (nestCheck.indexOf("include(")==-1)&&(nestCheck.indexOf("include_once(")==-1)&& + (nestCheck.indexOf("-1||nestCheck.indexOf("-1)) { - ICEcoder.nestDisplayText.innerHTML = ICEcoder.htmlTagArray.length > 0 ? "Cursor Position" : ""; - // Then for all the array items, output as the nest display - for (var i=0;i'}; - ICEcoder.nestDisplay.innerHTML += ''+ICEcoder.htmlTagArray[i]+''; - ICEcoder.nestDisplay.innerHTML += i' - : '
'; - } - if ("undefined" != typeof state.curState && ICEcoder.htmlTagArray.length > 0) { - ICEcoder.nestDisplay.innerHTML += ''+(state.curState.tagName ? state.curState.tagName : 'content')+''; + ICEcoder.nestDisplayText.innerHTML = ICEcoder.htmlTagArray.length > 0 ? "Cursor Position" : ""; + // Then for all the array items, output as the nest display + for (var i=0;i'}; + ICEcoder.nestDisplay.innerHTML += ''+ICEcoder.htmlTagArray[i]+''; + ICEcoder.nestDisplay.innerHTML += i' + : '
'; + } + if ("undefined" != typeof state.curState && ICEcoder.htmlTagArray.length > 0) { + ICEcoder.nestDisplay.innerHTML += ''+(state.curState.tagName ? state.curState.tagName : 'content')+''; + } } } } @@ -1734,7 +1736,7 @@ var ICEcoder = { // Lastly, stop it from trying to also switch tab top.ICEcoder.canSwitchTabs=false; // and set the widths - top.ICEcoder.setTabWidths(); + top.ICEcoder.setTabWidths('posOnlyNewTab'); }, // Close all tabs @@ -1747,7 +1749,7 @@ var ICEcoder = { }, // Set the tabs width - setTabWidths: function() { + setTabWidths: function(posOnlyNewTab) { var availWidth, avgWidth, tabWidth, lastLeft, lastWidth; availWidth = parseInt(top.ICEcoder.content.style.width,10)-41-24-10; // - left margin - new tab - right margin @@ -1756,13 +1758,15 @@ var ICEcoder = { lastLeft = 41; lastWidth = 0; top.ICEcoder.tabLeftPos = []; - for (var i=0;i availWidth ? parseInt(avgWidth*i,10) - parseInt(avgWidth*(i-1),10) : 150; lastLeft = i==0 ? 41 : parseInt(top.document.getElementById('tab'+(i)).style.left,10); lastWidth = i==0 ? 0 : parseInt(top.document.getElementById('tab'+(i)).style.width,10)+18; - top.document.getElementById('tab'+(i+1)).style.left = (lastLeft+lastWidth) + "px"; - top.document.getElementById('tab'+(i+1)).style.width = tabWidth + "px"; + if (!posOnlyNewTab) { + top.document.getElementById('tab'+(i+1)).style.left = (lastLeft+lastWidth) + "px"; + top.document.getElementById('tab'+(i+1)).style.width = tabWidth + "px"; + } top.ICEcoder.tabLeftPos.push(lastLeft+lastWidth); } top.document.getElementById('newTab').style.left = (lastLeft+lastWidth+tabWidth+18) + "px";