refactored

This commit is contained in:
coderaiser 2012-12-14 10:55:19 -05:00
parent 5eaf783c83
commit 856d9bb293
7 changed files with 60 additions and 117 deletions

View file

@ -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;

View file

@ -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;
};
/**

View file

@ -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 === '<dir>')
ReadOnly = true;
}
/* checking is this link is to directory
* when folder view is no need to edit data
*/
if ( DOM.getCurrentSize() === '<dir>' )
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
*/

View file

@ -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);
/* если нажали <ctr>+r
* обновляем страницу,

View file

@ -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";

View file

@ -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)
});
};

View file

@ -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);