From 9fbf1e7504615ab3ebe1bb38de596cb15b63247a Mon Sep 17 00:00:00 2001 From: Matt Pass Date: Thu, 26 Sep 2013 18:28:39 +0100 Subject: [PATCH] Dragging with key, drop file, paste URL functions draggingWithKey is new param, to indicate which key we have down while dragging, false if no key pasteURL is new function to paste a URL into the editor. If CTRL/Cmd is down, add the protocol and // as a prefix draggingWithKeyTest - another new function, this will work out a key that may be down whilst dragging, For now we set to CTRL (for CTRL/Cmd) or false but could take other keys in future dropFile is a final new function, when dropping a file, it will do something. If we're in the editor area, paste the URL, if we're in the files area, we'll move a file (a future update here). Finally, we set mouseDown to false as we may have crossed from one area to another and the event wouldn't trigger and flag not set otherwise Also setting top.ICEcoder.area on mouse move, very useful so we can work with that info (in the case of dropFile above) --- lib/ice-coder.js | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/lib/ice-coder.js b/lib/ice-coder.js index 111cb0c..9df4a10 100644 --- a/lib/ice-coder.js +++ b/lib/ice-coder.js @@ -28,6 +28,7 @@ var ICEcoder = { mouseDown: false, // If the mouse is down draggingFilesW: false, // If we're dragging the file manager width draggingTab: false, // If we're dragging a tab + draggingWithKey: false, // The key that's down while dragging, false if no key tabLeftPos: [], // Array of left positions of tabs inside content area tabBGcurrent: '#141414', // BG of current tab tabBGselected: '#49d', // BG of selected tab @@ -527,6 +528,17 @@ var ICEcoder = { } }, + // Paste a URL, locally or absolutely if CTRL/Cmd key down + pasteURL: function(url) { + var cM; + + cM = ICEcoder.getcMInstance(); + if(top.ICEcoder.draggingWithKey == "CTRL") { + url = window.location.protocol + "//" + window.location.hostname + url; + } + cM.replaceSelection(url); + }, + // ============== // FILES // ============== @@ -1056,6 +1068,31 @@ var ICEcoder = { } }, + // Detect CTRL/Cmd key whilst dragging files + draggingWithKeyTest: function(evt) { + var key; + + key = evt.keyCode ? evt.keyCode : evt.which ? evt.which : evt.charCode; + + // Mac command key handling (224 = Moz, 91/93 = Webkit Left/Right Apple) + if (key==224 || key==91 || key==93) { + top.ICEcoder.cmdKey = true; + } + + top.ICEcoder.draggingWithKey = evt.ctrlKey||top.ICEcoder.cmdKey ? "CTRL" : false; + }, + + // On dropping a file, do something + dropFile: function(elem) { + if (top.ICEcoder.area=='editor') { + top.ICEcoder.pasteURL(elem.childNodes[0].childNodes[1].id.replace(/\|/g,"/")); + }; + if (top.ICEcoder.area=='files') { + alert('Will drag files/folders soon!'); + }; + top.ICEcoder.mouseDown=false; + }, + // ============== // FIND & REPLACE // ============== @@ -1370,7 +1407,8 @@ var ICEcoder = { top.ICEcoder.mouseX = e.pageX ? e.pageX : e.clientX + document.body.scrollLeft; top.ICEcoder.mouseY = e.pageY ? e.pageY : e.clientY + document.body.scrollTop; - + + top.ICEcoder.area = area; if (area!="top") { top.ICEcoder.mouseY += 25 + 45; }