From 09fde0c3e5f63d6716d9b5bff50bddebc1f64dca Mon Sep 17 00:00:00 2001 From: Matt Pass Date: Wed, 16 Mar 2016 13:27:48 +0000 Subject: [PATCH] Only get statusObj if we have status 200 A non 200 event means there may not be a statusObj, which in turn causes an error which causes a JS jam --- lib/ice-coder.js | 76 +++++++++++++++++++++++--------------------- lib/ice-coder.min.js | 8 ++--- 2 files changed, 43 insertions(+), 41 deletions(-) diff --git a/lib/ice-coder.js b/lib/ice-coder.js index 6a8609c..f293ab8 100644 --- a/lib/ice-coder.js +++ b/lib/ice-coder.js @@ -1638,27 +1638,28 @@ var ICEcoder = { xhr = top.ICEcoder.xhrObj(); xhr.onreadystatechange=function() { if (xhr.readyState==4) { - // Parse the response as a JSON object - statusObj = JSON.parse(xhr.responseText); - - // Set the action end time and time taken in JSON object - statusObj.action.timeEnd = new Date().getTime(); - statusObj.action.timeTaken = statusObj.action.timeEnd - statusObj.action.timeStart; - - // User wanted raw (or both) output of the response? - if (["raw","both"].indexOf(top.ICEcoder.fileDirResOutput) >= 0) { - console.log(xhr.responseText); - } - // User wanted object (or both) output of the response? - if (["object","both"].indexOf(top.ICEcoder.fileDirResOutput) >= 0) { - console.log(statusObj); - } - - // Also store the statusObj - top.ICEcoder.lastFileDirCheckStatusObj = statusObj; - - // OK reponse? If error, show that, otherwise do whatever we're required to do next + // OK reponse? if (xhr.status==200) { + // Parse the response as a JSON object + statusObj = JSON.parse(xhr.responseText); + + // Set the action end time and time taken in JSON object + statusObj.action.timeEnd = new Date().getTime(); + statusObj.action.timeTaken = statusObj.action.timeEnd - statusObj.action.timeStart; + + // User wanted raw (or both) output of the response? + if (["raw","both"].indexOf(top.ICEcoder.fileDirResOutput) >= 0) { + console.log(xhr.responseText); + } + // User wanted object (or both) output of the response? + if (["object","both"].indexOf(top.ICEcoder.fileDirResOutput) >= 0) { + console.log(statusObj); + } + + // Also store the statusObj + top.ICEcoder.lastFileDirCheckStatusObj = statusObj; + + // If error, show that, otherwise do whatever we're required to do next if (statusObj.status.error) { top.ICEcoder.message(statusObj.status.errorMsg); console.log("ICEcoder error info for your request..."); @@ -2546,24 +2547,25 @@ var ICEcoder = { xhr = top.ICEcoder.xhrObj(); xhr.onreadystatechange=function() { if (xhr.readyState==4) { - // Parse the response as a JSON object - statusObj = JSON.parse(xhr.responseText); - - // Set the action end time and time taken in JSON object - statusObj.action.timeEnd = new Date().getTime(); - statusObj.action.timeTaken = statusObj.action.timeEnd - statusObj.action.timeStart; - - // User wanted raw (or both) output of the response? - if (["raw","both"].indexOf(top.ICEcoder.fileDirResOutput) >= 0) { - console.log(xhr.responseText); - } - // User wanted object (or both) output of the response? - if (["object","both"].indexOf(top.ICEcoder.fileDirResOutput) >= 0) { - console.log(statusObj); - } - - // OK reponse? If error, show that, otherwise do whatever we're required to do next + // OK reponse? if (xhr.status==200) { + // Parse the response as a JSON object + statusObj = JSON.parse(xhr.responseText); + + // Set the action end time and time taken in JSON object + statusObj.action.timeEnd = new Date().getTime(); + statusObj.action.timeTaken = statusObj.action.timeEnd - statusObj.action.timeStart; + + // User wanted raw (or both) output of the response? + if (["raw","both"].indexOf(top.ICEcoder.fileDirResOutput) >= 0) { + console.log(xhr.responseText); + } + // User wanted object (or both) output of the response? + if (["object","both"].indexOf(top.ICEcoder.fileDirResOutput) >= 0) { + console.log(statusObj); + } + + // If error, show that, otherwise do whatever we're required to do next if (statusObj.status.error) { top.ICEcoder.message(statusObj.status.errorMsg); console.log("ICEcoder error info for your request..."); diff --git a/lib/ice-coder.min.js b/lib/ice-coder.min.js index 863b8ce..1ddef04 100644 --- a/lib/ice-coder.min.js +++ b/lib/ice-coder.min.js @@ -66,8 +66,8 @@ deleteFiles:function(a){var b;a=a?a:top.ICEcoder.selectedFiles;b=a.toString().re else top.ICEcoder.message(top.t["Nothing to paste..."])},duplicateFiles:function(a){var b;top.ICEcoder.copiedFiles&&(b=top.ICEcoder.copiedFiles);top.ICEcoder.copyFiles(a,"dontShowPaste","dontHide");a=a[0].substr(0,a[0].lastIndexOf("|"));top.ICEcoder.pasteFiles(a);"undefined"!=typeof b&&(top.ICEcoder.copiedFiles=b)},uploadFilesSelect:function(a){top.get("uploadDir").value=a;top.get("fileInput").click()},uploadFilesSubmit:function(a){""!=top.get("fileInput").value&&(top.ICEcoder.showHide("show",top.get("loadingMask")), top.get("uploadFilesForm").submit(),event.preventDefault())},showHideFileNav:function(a,b){var c=["optionsFile","optionsEdit","optionsSource","optionsHelp"];if("hide"==a)fileNavInt=setTimeout(function(){for(var a=0;ac&&(b-=b+a-c),top.get("fileMenu").style.top=b+"px");return!1},showFileMenu:function(){top.get("fileMenu").style.display="inline-block";setTimeout(function(){top.get("fileMenu").style.opacity="1"},4)},hideFileMenu:function(){top.get("fileMenu").style.display="none";top.get("fileMenu").style.opacity="0"},updateFileManagerList:function(a,b,c,d,e,f,g){var k,h,l,p,n,m,q;if("add"==a&&!top.get("filesFrame").contentWindow.document.getElementById(b.replace(top.iceRoot, @@ -108,8 +108,8 @@ top.ICEcoder.csrf);top.ICEcoder["plugTimer"+a]=-1<["_parent","_top","_self",""]. !top.ICEcoder.codeAssist;top.get("codeAssistDisplay").style.backgroundPosition=top.ICEcoder.codeAssist?"0 0":"-16px 0";top.ICEcoder.cssColorPreview();top.ICEcoder.focus(-1'+top.t["Cancelled tasks"]+"");setTimeout(function(){top.ICEcoder.serverMessage()},2E3)},setPreviousFiles:function(){var a;a=top.ICEcoder.openFiles.join(",").replace(/\//g,"|").replace(/(\|\[NEW\])|(,\|\[NEW\])/g,"").replace(/(^,)|(,$)/g,"");""==a&&(a="CLEAR");top.ICEcoder.serverQueue("add", "lib/settings.php?saveFiles="+a+"&csrf="+top.ICEcoder.csrf);top.ICEcoder.updateLast10List(a)},updateLast10List:function(a){var b,c,d;a=a.split(",");for(var e=0;e"+a[e].replace(/\|/g,"/")+"\n",c=top.ICEcoder.content.contentWindow.document.getElementById("last10Files"),-1==