From 856d9bb293fd4d81d1f39defd905bf2d138fee08 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Fri, 14 Dec 2012 10:55:19 -0500 Subject: [PATCH] refactored --- lib/client.js | 28 +++------------- lib/client/dom.js | 55 +++++++++++++++++--------------- lib/client/editor/_codemirror.js | 25 ++++----------- lib/client/keyBinding.js | 34 ++------------------ lib/client/menu.js | 2 +- lib/client/viewer.js | 11 ++----- lib/server/win.js | 22 ++++++++----- 7 files changed, 60 insertions(+), 117 deletions(-) diff --git a/lib/client.js b/lib/client.js index d2632079..5c2433a8 100644 --- a/lib/client.js +++ b/lib/client.js @@ -236,32 +236,14 @@ CloudClient._setCurrent = function(){ * вызоветься _loadDir */ return function(pFromEnter){ - var lCurrentFile = DOM.getCurrentFile(); - if(lCurrentFile){/* устанавливаем курсор на файл, на который нажали */ - DOM.setCurrentFile(this); - //if (DOM.isCurrentFile(this) && - // !Util.isBoolean(pFromEnter)){ - //var lParent = this; - - //setTimeout(function(){ - /* waiting a few seconds - * and if classes still equal - * make file name editable - * in other case - * double click event happend - */ - // if(DOM.getCurrentFile() === lParent) - // CloudClient._editFileName(lParent); - // },1000); - //} - } + var lCurrent = DOM.getCurrentFile(); /* если мы попали сюда с энтера */ if(pFromEnter===true){ - var lResult = Util.exec( Util.bind(this.ondblclick, this) ); + var lResult = Util.exec( Util.bind(lCurrent.ondblclick, lCurrent) ); /* enter pressed on file */ if(!lResult){ - var lA = DOM.getCurrentLink(this); - Util.exec( Util.bind(lA.ondblclick, this) ); + var lA = DOM.getCurrentLink(lCurrent); + Util.exec( Util.bind(lA.ondblclick, lCurrent) ); } }/* если мы попали сюда от клика мышки */ else @@ -603,7 +585,7 @@ CloudClient._changeLinks = function(pPanelID){ a[i].onclick = CloudClient._loadDir(link); } else { - lLi.onclick = CloudClient._setCurrent(); + lLi.onclick = CloudClient._setCurrent(); lLi.onmousedown = lSetCurrentFile_f; a[i].ondragstart = lOnDragStart_f; diff --git a/lib/client/dom.js b/lib/client/dom.js index 47545756..d673e5fd 100644 --- a/lib/client/dom.js +++ b/lib/client/dom.js @@ -759,6 +759,16 @@ var CloudCommander, Util, DOM, CloudFunc; return lCurrent; }; + + DOM.getCurrentSize = function(pCurrentFile){ + var lRet, + lCurrent = pCurrentFile || DOM.getCurrentFile(), + lSize = DOM.getByClass('size', lCurrent); + lRet = lSize[0].textContent; + + return lRet; + }; + /** * unified way to get current file content * @@ -811,35 +821,28 @@ var CloudCommander, Util, DOM, CloudFunc; * unified way to set current file */ DOM.setCurrentFile = function(pCurrentFile){ - var lRet_b = true; + var lRet = true, + lCurrentFileWas = DOM.getCurrentFile(); - if(!pCurrentFile){ - DOM.addCloudStatus({ - code : -1, - msg : 'Error pCurrentFile in' + - 'setCurrentFile' + - 'could not be none' - }); + if(!pCurrentFile) + lRet = false; + + if(lRet){ + if (pCurrentFile.className === 'path') + pCurrentFile = pCurrentFile.nextSibling; - lRet_b = false; + if (pCurrentFile.className === 'fm_header') + pCurrentFile = pCurrentFile.nextSibling; + + if(lCurrentFileWas) + UnSetCurrentFile(lCurrentFileWas); + + DOM.addClass(pCurrentFile, getCurrentFile()); + + /* scrolling to current file */ + DOM.scrollIntoViewIfNeeded(pCurrentFile); } - var lCurrentFileWas = DOM.getCurrentFile(); - - if (pCurrentFile.className === 'path') - pCurrentFile = pCurrentFile.nextSibling; - - if (pCurrentFile.className === 'fm_header') - pCurrentFile = pCurrentFile.nextSibling; - - if(lCurrentFileWas) - UnSetCurrentFile(lCurrentFileWas); - - DOM.addClass(pCurrentFile, getCurrentFile()); - - /* scrolling to current file */ - DOM.scrollIntoViewIfNeeded(pCurrentFile); - - return lRet_b; + return lRet; }; /** diff --git a/lib/client/editor/_codemirror.js b/lib/client/editor/_codemirror.js index 836465c0..b8c82fad 100644 --- a/lib/client/editor/_codemirror.js +++ b/lib/client/editor/_codemirror.js @@ -121,23 +121,11 @@ var CloudCommander, Util, DOM, CodeMirror; if(Loading) return; - /* getting link */ - var lCurrentFile = DOM.getCurrentFile(), - lPath = DOM.getCurrentPath(lCurrentFile); - - /* checking is this link is to directory */ - var lSize = DOM.getByClass('size', lCurrentFile); - if(lSize){ - lSize = lSize[0].textContent; - - /* when folder view - * is no need to edit - * data - */ - if (lSize === '') - ReadOnly = true; - - } + /* checking is this link is to directory + * when folder view is no need to edit data + */ + if ( DOM.getCurrentSize() === '' ) + ReadOnly = true; Loading = true; setTimeout(function(){ @@ -153,7 +141,7 @@ var CloudCommander, Util, DOM, CodeMirror; success : function(data){ /* if we got json - show it */ - if(typeof data === 'object') + if( Util.isObject(data) ) data = JSON.stringify(data, null, 4); var lHided = DOM.hidePanel(); @@ -184,7 +172,6 @@ var CloudCommander, Util, DOM, CodeMirror; DOM.showPanel(); } - /** * function calls all CodeMirror editor functions */ diff --git a/lib/client/keyBinding.js b/lib/client/keyBinding.js index 89f16980..9b83d422 100644 --- a/lib/client/keyBinding.js +++ b/lib/client/keyBinding.js @@ -260,38 +260,8 @@ var CloudCommander, Util, DOM; } /* если нажали Enter - открываем папку*/ - else if(lKeyCode === KEY.ENTER){ - /* если ненайдены выделенные файлы - выходим*/ - if(!lCurrentFile)return; - - /* из него достаём спан с именем файла*/ - lName = DOM.getByClass('name', lCurrentFile); - - /* если нету (что вряд ли) - выходим*/ - if(!lName)return false; - - /* достаём все ссылки*/ - var lATag = DOM.getByTag('a', lName[0]); - - /* если нету - выходим */ - if(!lATag)return false; - - /* вызываем ajaxload привязанный через changelinks - * пробуем нажать на ссылку, если не получиться - * (opera, ie), вызываем событие onclick, - */ - - if(lCurrentFile.onclick) - lCurrentFile.onclick(true); - else try{ - lATag[0].click(); - } - catch(error){ - console.log(error); - } - - event.preventDefault();//запрет на дальнейшее действие - } + else if(lKeyCode === KEY.ENTER) + Util.exec(lCurrentFile.onclick, true); /* если нажали +r * обновляем страницу, diff --git a/lib/client/menu.js b/lib/client/menu.js index c8656795..98c8b805 100644 --- a/lib/client/menu.js +++ b/lib/client/menu.js @@ -1,7 +1,7 @@ /* object contains jQuery-contextMenu * https://github.com/medialize/jQuery-contextMenu */ -var CloudCommander, Util, DOM, CloudFunc, $; +var CloudCommander, Util, DOM, $; (function(){ "use strict"; diff --git a/lib/client/viewer.js b/lib/client/viewer.js index d3f56e7f..6c0f44b0 100644 --- a/lib/client/viewer.js +++ b/lib/client/viewer.js @@ -138,17 +138,12 @@ var CloudCommander, Util, DOM, CloudFunc, $; if (lLink.indexOf(CloudFunc.NOJS) === CloudFunc.FS.length) lLink = Util.removeStr(lLink, CloudFunc.NOJS); - DOM.ajax({ + DOM.getCurrentFileContent({ url : lLink, - - error : function(jqXHR, textStatus, errorThrown){ + error : function(){ FancyBox.loading = false; - return DOM.Images.showError(jqXHR, textStatus, errorThrown); }, - - success :function(data, textStatus, jqXHR){ - Util.exec(pCallBack, data); - } + success : Util.retExec(pCallBack) }); }; diff --git a/lib/server/win.js b/lib/server/win.js index 9a7b58e3..3560b494 100644 --- a/lib/server/win.js +++ b/lib/server/win.js @@ -38,15 +38,15 @@ function retProcessOuput(pCallBack){ return function(pError, pStdout, pStderr){ + var lstrPattern = 'Том ', + lCharPosition = 10; + /** * get position of current name of volume * @param pNumber = number of volume */ var getPosition = function(pNumber){ - var lRet, - lstrPattern = 'Том '; - - lRet = pStdout.indexOf(lstrPattern + pNumber); + var lRet = pStdout.indexOf(lstrPattern + pNumber); return lRet; }; @@ -56,10 +56,7 @@ * @param pPosition - current char position */ var getVolumeName = function (pPosition){ - var lRet, - lCharPosition = 10; - - lRet = pStdout[pPosition + lCharPosition]; + var lRet = pStdout[pPosition + lCharPosition]; return lRet; }; @@ -72,6 +69,15 @@ var i = 0, lNum = getPosition(i); + /* if russian name not found + * try to search english name + */ + if(lNum < 0){ + lstrPattern = 'Volume ', + lCharPosition = 10 + 3; + lNum = getPosition(i); + } + do{ lVolumes[i] = getVolumeName(lNum); lNum = getPosition(++i);