diff --git a/lib/client/dom.js b/lib/client/dom.js index dfe6f52e..2cf00543 100644 --- a/lib/client/dom.js +++ b/lib/client/dom.js @@ -45,17 +45,17 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog; * pPosition = {top: true}; */ this.showLoad = function(pPosition) { - var lLoadingImage = lImages.loading(), + var lCurrent, + lLoadingImage = lImages.loading(), lErrorImage = lImages.error(); DOM.hide(lErrorImage); - var lCurrent; if (pPosition && pPosition.top) lCurrent = DOM.getRefreshButton().parentElement; - else{ - var lFile = DOM.getCurrentFile(); - lCurrent = DOM.getByClass('name', lFile)[0]; + else { + lCurrent = DOM.getCurrentFile(); + lCurrent = DOM.getByClass('name', lCurrent)[0]; } /* show loading icon if it not showed */ @@ -1586,6 +1586,8 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog; this.scrollIntoViewIfNeeded(pCurrentFile); lRet = true; + + Cmd.updateCurrentInfo(); } return lRet; @@ -2147,6 +2149,34 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog; Util.exec(callback, ext); }); }; + this.CurrentInfo = {}, + this.updateCurrentInfo = function(pCurrent) { + var info = Cmd.CurrentInfo, + current = pCurrent || Cmd.getCurrentFile(), + panel = Cmd.getPanel(), + name = Cmd.getCurrentName(current); + + info.dir = Cmd.getCurrentDirName(); + info.dirPath = Cmd.getCurrentDirPath(); + info.element = current; + info.ext = Util.getExtension(name); + info.files = Cmd.getFiles(panel); + info.first = current.parentElement.firstChild; + info.getData = Cmd.getCurrentData; + info.last = current.parentElement.lastChild; + info.link = Cmd.getCurrentLink(current); + info.next = current.nextSibling; + info.mode = Cmd.getCurrentMode(current); + info.name = name; + info.path = Cmd.getCurrentPath(current); + info.panel = panel; + info.panelPassive = Cmd.getPanel({active:false}); + info.prev = current.previousSibling; + info.size = Cmd.getCurrentSize(current); + info.isDir = Cmd.isCurrentIsDir(); + info.isSelected = Cmd.isSelected(current); + }; + }, DOMTree = Util.extendProto(DOMTreeProto), @@ -2155,7 +2185,7 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog; Loader = Util.extendProto(LoaderProto), Images = Util.extendProto(ImagesProto), RESTful = Util.extendProto(RESTfulProto), - Storage = Util.extendProto(StorageProto); + Storage = Util.extendProto(StorageProto); DOMProto = DOMFunc.prototype = new CmdProto(); diff --git a/lib/client/edit.js b/lib/client/edit.js index 1950f948..9d9e96ce 100644 --- a/lib/client/edit.js +++ b/lib/client/edit.js @@ -9,6 +9,7 @@ var CloudCmd, Util, DOM, CloudFunc, ace, DiffProto, diff_match_patch; Loading = false, DIR = CloudCmd.LIBDIRCLIENT + 'edit/', LIBDIR = CloudCmd.LIBDIR, + Info = DOM.CurrentInfo, Value, Edit = this, Diff, @@ -42,9 +43,9 @@ var CloudCmd, Util, DOM, CloudFunc, ace, DiffProto, diff_match_patch; this.show = function(pValue) { var lMode, - lName = DOM.getCurrentName(), - isDir = DOM.isCurrentIsDir(), - lExt = Util.getExtension(lName); + lName = Info.name, + isDir = Info.isDir, + lExt = Info.ext; if (!Loading) { Images.showLoad(); @@ -77,7 +78,7 @@ var CloudCmd, Util, DOM, CloudFunc, ace, DiffProto, diff_match_patch; CloudCmd.View.show(Element, focus); Key.unsetBind(); } else { - DOM.getCurrentData({ + DOM.getData({ success : function(pData) { var lValue = ''; @@ -149,7 +150,7 @@ var CloudCmd, Util, DOM, CloudFunc, ace, DiffProto, diff_match_patch; } function save () { - var lPath = DOM.getCurrentPath(), + var lPath = Info.path, lValue = Ace.getValue(); CloudCmd.getConfig(function(config) { @@ -203,7 +204,7 @@ var CloudCmd, Util, DOM, CloudFunc, ace, DiffProto, diff_match_patch; patch = Diff.createPatch(Value, pNewValue); Util.exec(pCallBack, patch); }, function(callback) { - var path = DOM.getCurrentPath(); + var path = Info.path; DOM.getDataFromStorage(path, function(data) { if (data) @@ -250,7 +251,7 @@ var CloudCmd, Util, DOM, CloudFunc, ace, DiffProto, diff_match_patch; function onSave(text) { var ret, isError = Util.isContainStrAtBegin(text, 'error'), - path = DOM.getCurrentPath(), + path = Info.path, msg = '\nShould I save file anyway?'; if (!isError) { diff --git a/lib/client/key.js b/lib/client/key.js index 94280f2b..034b6a68 100644 --- a/lib/client/key.js +++ b/lib/client/key.js @@ -2,8 +2,9 @@ var CloudCmd, Util, DOM; (function(CloudCmd, Util, DOM) { 'use strict'; - var Chars = [], - KEY = { + var Info = DOM.CurrentInfo, + Chars = [], + KEY = { TAB : 9, ENTER : 13, ESC : 27, @@ -106,9 +107,9 @@ var CloudCmd, Util, DOM; skipCount = 0, skipN = 0, setted = false, - lCurrent = DOM.getCurrentFile(), - panel = DOM.getPanel(), - files = DOM.getFiles(panel), + lCurrent = Info.element, + panel = Info.panel, + files = Info.files, SMALL = 32, char = String.fromCharCode(pKeyCode), charSmall = String.fromCharCode(pKeyCode + SMALL); @@ -153,7 +154,8 @@ var CloudCmd, Util, DOM; } function switchKey(pEvent) { - var i, n, lCurrent = DOM.getCurrentFile(), + var i, n, + lCurrent = Info.element, lKeyCode = pEvent.keyCode, lShift = pEvent.shiftKey, lAlt = pEvent.altKey, @@ -163,15 +165,16 @@ var CloudCmd, Util, DOM; case Key.TAB: /* changing parent panel of curent-file */ var lFirstFileOnList, - lPanel = DOM.getPanel(), + lPanel = Info.panel; lId = lPanel.id; lTabPanel[lId] = lCurrent; - lPanel = DOM.getPanel({active:false}); + lPanel = Info.panelPassive; lId = lPanel.id; lCurrent = lTabPanel[lId]; + if (lCurrent && lCurrent.parentElement) DOM.setCurrentFile(lCurrent); else { @@ -185,17 +188,17 @@ var CloudCmd, Util, DOM; case Key.INSERT: DOM .toggleSelectedFile(lCurrent) - .setCurrentFile(lCurrent.nextSibling); + .setCurrentFile(Info.next); break; case Key.DELETE: if (lShift) { - var lUrl = DOM.getCurrentPath(lCurrent); + var path = Info.path; - if ( DOM.isCurrentIsDir(lCurrent) ) + if (Info.isDir) lUrl += '?dir'; - DOM.RESTful.delete(lUrl, function() { + DOM.RESTful.delete(path, function() { DOM.deleteCurrent(lCurrent); }); } @@ -259,12 +262,14 @@ var CloudCmd, Util, DOM; break; case Key.SPACE: - var lSelected = DOM.isSelected(lCurrent), - lDir = DOM.isCurrentIsDir(lCurrent), - lName = DOM.getCurrentName(lCurrent); + var lSelected, + isDir = Info.isDir, + lName = Info.name; - if (!lDir || lName === '..') - lSelected = true; + if (!isDir || lName === '..') + lSelected = true; + else + lSelected = Info.isSelected; Util.ifExec(lSelected, function() { DOM.toggleSelectedFile(lCurrent); @@ -283,8 +288,8 @@ var CloudCmd, Util, DOM; if (lShift) DOM.toggleSelectedFile(lCurrent); - DOM.setCurrentFile( lCurrent.previousSibling ); - DOM.preventDefault( pEvent ); + DOM.setCurrentFile(Info.prev); + DOM.preventDefault(pEvent); break; /* если нажали клавишу в низ - выделяем следующую строку */ @@ -292,22 +297,22 @@ var CloudCmd, Util, DOM; if (lShift) DOM.toggleSelectedFile(lCurrent); - DOM.setCurrentFile( lCurrent.nextSibling ); - DOM.preventDefault( pEvent ); + DOM.setCurrentFile(Info.next); + DOM.preventDefault(pEvent); break; /* если нажали клавишу Home * * переходим к самому верхнему * * элементу */ case Key.HOME: - DOM.setCurrentFile( lCurrent.parentElement.firstChild ); + DOM.setCurrentFile(Info.first); DOM.preventDefault(pEvent); break; /* если нажали клавишу End выделяем последний элемент */ case Key.END: - DOM.setCurrentFile( lCurrent.parentElement.lastElementChild ); - DOM.preventDefault( pEvent ); + DOM.setCurrentFile(Info.last); + DOM.preventDefault(pEvent); break; /* если нажали клавишу page down проматываем экран */ @@ -329,8 +334,7 @@ var CloudCmd, Util, DOM; case Key.PAGE_UP: DOM.scrollByPages(DOM.getPanel(), -1); - var lC = lCurrent, - tryCatch = function(pCurrentFile) { + var tryCatch = function(pCurrentFile) { Util.tryCatch(function() { return pCurrentFile .previousSibling @@ -341,19 +345,20 @@ var CloudCmd, Util, DOM; }; for (i = 0; i < 30; i++) { - if (!lC.previousSibling || tryCatch(lC) ) break; + if (!lCurrent.previousSibling || tryCatch(lCurrent) ) + break; - lC = lC.previousSibling; + lCurrent = lCurrent.previousSibling; } - DOM.setCurrentFile(lC); + DOM.setCurrentFile(lCurrent); DOM.preventDefault(pEvent); break; /* открываем папку*/ case Key.ENTER: - if (DOM.isCurrentIsDir()) - Util.exec( CloudCmd.loadDir() ); + if (Info.isDir) + Util.exec(CloudCmd.loadDir()); break; case Key.A: diff --git a/lib/client/menu.js b/lib/client/menu.js index 5a576739..a7ff1a18 100644 --- a/lib/client/menu.js +++ b/lib/client/menu.js @@ -10,6 +10,7 @@ var CloudCmd, Util, DOM, CloudFunc, $; function MenuProto(pPosition) { var Name = 'Menu', + Info = DOM.CurrentInfo, Loading = false, Key = CloudCmd.Key, Events = DOM.Events, @@ -35,7 +36,7 @@ var CloudCmd, Util, DOM, CloudFunc, $; Events.addKey( lListener ); DOM.setButtonKey('f9', function() { - var lCurrent = DOM.getCurrentFile(); + var lCurrent = Info.element; Events.dispatch('contextmenu', lCurrent); }); @@ -82,7 +83,7 @@ var CloudCmd, Util, DOM, CloudFunc, $; } else if (Util.isString(pObjectName)) { lObj = function(key, opt){ - DOM.getCurrentData(function(pParams) { + Info.getData(function(pParams) { CloudCmd.execFromModule(pObjectName, 'uploadFile', pParams); }); @@ -138,9 +139,9 @@ var CloudCmd, Util, DOM, CloudFunc, $; function downloadFromMenu(key, opt){ DOM.Images.showLoad(); - var lPath = DOM.getCurrentPath(), + var lPath = Info.path, lId = DOM.getIdBySrc(lPath), - lDir = DOM.isCurrentIsDir() ? '&&json' : ''; + lDir = Info.isDir ? '&&json' : ''; Util.log('downloading file ' + lPath +'...'); diff --git a/lib/client/view.js b/lib/client/view.js index 9166a623..d9e9e5bf 100644 --- a/lib/client/view.js +++ b/lib/client/view.js @@ -8,6 +8,7 @@ var CloudCmd, Util, DOM, CloudFunc, $; function ViewProto(CallBack) { var Name = 'View', Loading = false, + Info = DOM.CurrentInfo, Key = CloudCmd.Key, Images = DOM.Images, View = this, @@ -94,14 +95,15 @@ var CloudCmd, Util, DOM, CloudFunc, $; $.fancybox(lElement, config); } else { - lPath = CloudFunc.FS + DOM.getCurrentPath(); - if( Util.checkExtension(lPath, ['png','jpg', 'gif','ico']) ) { + lPath = CloudFunc.FS + Info.path; + + if(Util.checkExtension(lPath, ['png','jpg', 'gif','ico'])) { $.fancybox.open({ href : lPath }, Config); - } - else - DOM.getCurrentData(function(pParams){ + } else + Info.getData(function(pParams){ var data = document.createTextNode(pParams.data); - $.fancybox( Element.append(data), Config ); + + $.fancybox(Element.append(data), Config); }); } }