diff --git a/lib/client/dom.js b/lib/client/dom.js index 638bafad..c0a94fc5 100644 --- a/lib/client/dom.js +++ b/lib/client/dom.js @@ -592,7 +592,11 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog; CURRENT_FILE = 'current-file', SELECTED_FILE = 'selected-file', SelectType = '*.*', - Title; + Title, + TabPanel = { + 'js-left' : null, + 'js-right' : null + }; /** * private function thet unset currentfile @@ -1837,6 +1841,32 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog; }); }; + this.changePanel = function() { + var id, files, + Info = CurrentInfo, + current = Info.element, + panel = Info.panel, + filesPassive = Info.filesPassive; + + id = panel.id; + TabPanel[id] = current; + + panel = Info.panelPassive; + id = panel.id; + + current = TabPanel[id]; + + if (current) + files = current.parentElement; + + if (!files || !files.parentElement) + current = filesPassive[0]; + + DOM.setCurrentFile(current); + + return this; + }; + this.CurrentInfo = CurrentInfo, this.updateCurrentInfo = function(currentFile) { diff --git a/lib/client/key.js b/lib/client/key.js index a808b05a..c9dc9fde 100644 --- a/lib/client/key.js +++ b/lib/client/key.js @@ -62,11 +62,7 @@ var CloudCmd, Util, DOM; function KeyProto() { var Key = this, - Binded, - TabPanel = { - 'js-left' : null, - 'js-right' : null - }; + Binded; this.isBind = function() {return Binded;}; @@ -160,11 +156,10 @@ var CloudCmd, Util, DOM; } function switchKey(event) { - var i, id, obj, files, name, isSelected, isDir, + var i, obj, name, isSelected, isDir, current = Info.element, panel = Info.panel, path = Info.path, - filesPassive = Info.filesPassive, prev = current.previousSibling, next = current.nextSibling, lKeyCode = event.keyCode, @@ -174,23 +169,8 @@ var CloudCmd, Util, DOM; switch (lKeyCode) { case Key.TAB: - id = panel.id; - TabPanel[id] = current; - - panel = Info.panelPassive; - id = panel.id; - - current = TabPanel[id]; - - if (current) - files = current.parentElement; - - if (!files || !files.parentElement) - current = filesPassive[0]; - - DOM.setCurrentFile(current); - - DOM.preventDefault(event); + DOM.changePanel() + .preventDefault(event); break; case Key.INSERT: diff --git a/lib/client/listeners.js b/lib/client/listeners.js index 5faeadb6..1be41e24 100644 --- a/lib/client/listeners.js +++ b/lib/client/listeners.js @@ -15,7 +15,7 @@ var Util, DOM, CloudCmd; 'mousedown' : Util.bind(ifExecNotUL, setCurrentFileByEvent), 'contextmenu' : Util.bind(ifExecNotUL, onContextMenu), 'dragstart' : Util.bind(ifExecNotUL, onDragStart), - 'click' : Util.bind(ifExecNotUL, onClick), + 'click' : onClick, 'dblclick' : Util.bind(ifExecNotUL, onDblClick), 'touchstart' : Util.bind(ifExecNotUL, onTouch) }; @@ -180,10 +180,16 @@ var Util, DOM, CloudCmd; } function onClick(event) { - var ctrl = event.ctrlKey; + var ctrl = event.ctrlKey, + panel = DOM.getPanel(), + files = DOM.getByDataName('js-files', panel), + ul = getULElement(event.target); if (!ctrl) DOM.preventDefault(event); + + if (ul !== files) + DOM.changePanel(); } function onDblClick(event) { @@ -263,6 +269,17 @@ var Util, DOM, CloudCmd; return element; } + function getULElement(element) { + var tag = element.tagName; + + if (tag !== 'UL') + do { + element = element.parentElement; + tag = element.tagName; + } while(tag !== 'UL'); + + return element; + } function setCurrentFileByEvent(event) { var element = getLIElement(event.target);