Server Queue, CSS Color Preview, scrolling bug fix & some minor updates

New server queue system added which deals with and processes server calls in turn
(This should stop any potential connectity conncurrency issues)
Saving now takes a temp snapshot of the content to be saved when due in the server queue
Having a server queue is more professional and means you can queue up actions while other actions are happening
refresh() is now called in a couple of places so scroll position is applied
(This avoids the bug when switching between tabs)
Server messages now accept a message as part of the variable
(This means you now show messages via the plugins setInterval system)
CSS color preview boxes appear when text cursor moves within the color value
CSS color preview system also ties in with Code Assist and is part of the toggle
You also now refocus when clicking Code Assist
This commit is contained in:
Matt Pass
2012-03-25 16:52:14 +01:00
parent 4bbd84f594
commit 029f5edd1a

View File

@@ -24,6 +24,7 @@ var ICEcoder = {
codeAssist: true, // Assist user with their coding
mouseDown: false, // If the mouse is down or not
draggingFilesW: false, // If we're dragging the file manager width or not
serverQueueItems: [], // Array of URLs to call in order
// Don't consider these tags as part of nesting as they're singles, JS or PHP code blocks
tagNestExceptions: ["!DOCTYPE","meta","link","img","br","hr","input","script","?"],
@@ -322,9 +323,10 @@ var ICEcoder = {
}
cM.setOption('theme','icecoder visible');
// Focus on our selected instance
// Focus on & refresh our selected instance
cM = ICEcoder.getcMInstance();
cM.focus();
cM.refresh();
// Highlight the selected tab
ICEcoder.redoTabHighlight(ICEcoder.selectedTab);
@@ -655,7 +657,7 @@ var ICEcoder = {
if (newFolder) {
newFolder = shortURL + "/" + newFolder;
filesFrame.contentWindow.frames['fileControl'].location.href="lib/file-control.php?action=newFolder&file="+newFolder.replace(/\//g,"|");
top.ICEcoder.serverQueue("add","lib/file-control.php?action=newFolder&file="+newFolder.replace(/\//g,"|"));
top.ICEcoder.serverMessage('<b>Creating Folder</b><br>'+newFolder);
}
},
@@ -695,7 +697,7 @@ var ICEcoder = {
if (shortURL!="/[NEW]") {
// replace forward slashes with pipes so it get be placed in a querystring
top.ICEcoder.thisFileFolderLink = top.ICEcoder.thisFileFolderLink.replace(/\//g,"|");
ICEcoder.filesFrame.contentWindow.frames['fileControl'].location.href = "lib/file-control.php?action=load&file="+top.ICEcoder.thisFileFolderLink;
top.ICEcoder.serverQueue("add","lib/file-control.php?action=load&file="+top.ICEcoder.thisFileFolderLink);
top.ICEcoder.serverMessage('<b>Opening File</b><br>'+top.ICEcoder.shortURL);
} else {
top.ICEcoder.createNewTab();
@@ -709,7 +711,7 @@ var ICEcoder = {
var saveType;
if (saveAs) {saveType = "saveAs"} else {saveType = "save"};
filesFrame.contentWindow.frames['fileControl'].location.href="lib/file-control.php?action=save&file="+ICEcoder.openFiles[ICEcoder.selectedTab-1].replace(/\//g,"|")+"&saveType="+saveType;
top.ICEcoder.serverQueue("add","lib/file-control.php?action=save&file="+ICEcoder.openFiles[ICEcoder.selectedTab-1].replace(/\//g,"|")+"&saveType="+saveType);
top.ICEcoder.serverMessage('<b>Saving</b><br>'+ICEcoder.openFiles[ICEcoder.selectedTab-1]);
},
@@ -732,7 +734,7 @@ var ICEcoder = {
top.document.getElementById('tab'+(i+1)).innerHTML = top.ICEcoder.openFiles[i] + " " + closeTabLink;
}
}
ICEcoder.filesFrame.contentWindow.frames['fileControl'].location.href = "lib/file-control.php?action=rename&file="+renamedFile+"&oldFileName="+top.ICEcoder.rightClickedFile.replace(/\|/g,"/");
top.ICEcoder.serverQueue("add","lib/file-control.php?action=rename&file="+renamedFile+"&oldFileName="+top.ICEcoder.rightClickedFile.replace(/\|/g,"/"));
top.ICEcoder.serverMessage('<b>Renaming to</b><br>'+renamedFile);
}
},
@@ -750,7 +752,7 @@ var ICEcoder = {
selectedFilesList += top.ICEcoder.selectedFiles[i];
if (i<top.ICEcoder.selectedFiles.length-1) {selectedFilesList+=";"}
}
ICEcoder.filesFrame.contentWindow.frames['fileControl'].location.href = "lib/file-control.php?action=delete&file="+selectedFilesList;
top.ICEcoder.serverQueue("add","lib/file-control.php?action=delete&file="+selectedFilesList);
top.ICEcoder.serverMessage('<b>Deleting File</b><br>'+top.ICEcoder.selectedFiles.toString().replace(/\|/g,"/").replace(/,/g,"\n"));
};
},
@@ -919,14 +921,13 @@ var ICEcoder = {
// Start running plugin intervals according to given specifics
startPluginIntervals: function(plugURL,plugTarget,plugTimer) {
// For this window instances
if (plugTarget=="_parent"||plugTarget=="_top"||plugTarget=="_self"||plugTarget=="") {
setInterval('window.location=\''+plugURL+'\'',plugTimer*1000*60);
// for pluginActions iframe instances
} else if (plugTarget=="pluginActions") {
setInterval('document.getElementById(\'pluginActions\').src=\''+plugURL+'\'',plugTimer*1000*60);
} else if (plugTarget.indexOf("fileControl")==0) {
setInterval(function() {top.ICEcoder.serverQueue("add",plugURL);top.ICEcoder.serverMessage(plugTarget.split(":")[1]);},plugTimer*1000*60);
// for _blank or named target window instances
} else {
@@ -986,6 +987,7 @@ var ICEcoder = {
top.ICEcoder.dragCursorTest();
},
// Test if we need to show a drag cursor or not
dragCursorTest: function() {
var winH;
@@ -1093,7 +1095,14 @@ var ICEcoder = {
// Turning on/off the Code Assist
codeAssistToggle: function() {
var cM;
cM = ICEcoder.getcMInstance();
top.ICEcoder.codeAssist ? top.ICEcoder.codeAssist = false : top.ICEcoder.codeAssist = true;
top.ICEcoder.cssColorPreview();
cM.focus();
},
// Show or hide a server message
@@ -1107,5 +1116,76 @@ var ICEcoder = {
} else {
serverMessage.style.opacity = 0;
}
},
// Queue items up for processing in turn
serverQueue: function(action,item) {
var cM,nextSaveID,txtArea,topSaveID,element;
cM = ICEcoder.getcMInstance();
// Firstly, work out how many saves we have to carry out
nextSaveID=0;
for (i=0;i<ICEcoder.serverQueueItems.length;i++) {
if (ICEcoder.serverQueueItems[i].indexOf('action=save')>0) {
nextSaveID++;
}
}
nextSaveID++;
// Add to end of array or remove from beginning on demand, plus add or remove if necessary
if (action=="add") {
ICEcoder.serverQueueItems.push(item);
if (item.indexOf('action=save')>0) {
txtArea = document.createElement('textarea');
txtArea.setAttribute('id', 'saveTemp'+nextSaveID);
document.body.appendChild(txtArea);
document.getElementById('saveTemp'+nextSaveID).value = cM.getValue();
}
}
if (action=="del") {
if (ICEcoder.serverQueueItems[0].indexOf('action=save')>0) {
topSaveID = nextSaveID-1;
for (i=1;i<topSaveID;i++) {
document.getElementById('saveTemp'+i).value = document.getElementById('saveTemp'+(i+1)).value;
}
element = document.getElementById('saveTemp'+topSaveID);
element.parentNode.removeChild(element);
}
ICEcoder.serverQueueItems.splice(0,1);
}
// If we've just removed from the array and there's another action queued up, or we're triggering for the first time
// then do the next requested process, stored at array pos 0
if (action=="del" && ICEcoder.serverQueueItems.length>=1 || ICEcoder.serverQueueItems.length==1) {
setTimeout(function() {top.ICEcoder.filesFrame.contentWindow.frames['fileControl'].location.href=ICEcoder.serverQueueItems[0]},1);
}
},
// Show a CSS color block next to our text cursor
cssColorPreview: function() {
var cM,string,startPosAdj,endPosAdj,nextSpace,oldBlock,newBlock;
cM = ICEcoder.getcMInstance();
string = cM.getLine(cM.getCursor().line);
startPosAdj = string.slice(0,cM.getCursor().ch).length - string.slice(0,cM.getCursor().ch).lastIndexOf(' ') - 1;
nextSpace = string.slice(cM.getCursor().ch,string.length).indexOf(' ');
nextSpace > -1 ? endPosAdj = nextSpace : endPosAdj = string.length - cM.getCursor().ch;
string = string.slice(cM.getCursor().ch-startPosAdj,cM.getCursor().ch+endPosAdj);
string = string.replace(/[^a-z0-9#(),.]/gi,'');
oldBlock = top.document.getElementById('content').contentWindow.document.getElementById('cssColor');
if (oldBlock) {oldBlock.parentNode.removeChild(oldBlock)};
if (top.ICEcoder.codeAssist) {
newBlock = top.document.createElement("div");
newBlock.id="cssColor";
newBlock.style.position = "absolute";
newBlock.style.display = "block";
newBlock.style.width = newBlock.style.height = "20px";
newBlock.style.backgroundColor = string;
top.document.getElementById('header').appendChild(newBlock);
cM.addWidget(cM.getCursor(), top.document.getElementById('cssColor'), true);
}
}
};