refactored

This commit is contained in:
coderaiser 2013-04-08 09:18:00 -04:00
parent 31af952b37
commit e6754ed759
5 changed files with 55 additions and 43 deletions

View file

@ -3,7 +3,7 @@
"appcache" : false,
"minification" : {
"js" : false,
"css" : false,
"css" : true,
"html" : true,
"img" : true
},

View file

@ -129,7 +129,7 @@ var CloudCommander, Util, DOM = {}, CloudFunc;
*
* @pCurrentFile
*/
function unSetCurrentFile(pCurrentFile){
function unsetCurrentFile(pCurrentFile){
var lRet = DOM.isCurrentFile(pCurrentFile);
if(lRet)
@ -139,7 +139,7 @@ var CloudCommander, Util, DOM = {}, CloudFunc;
}
/**
* add class to current element
* add class to element
*
* @param pElement
* @param pClass
@ -158,6 +158,12 @@ var CloudCommander, Util, DOM = {}, CloudFunc;
return lRet;
};
/**
* check class of element
*
* @param pElement
* @param pClass
*/
DOM.isContainClass = function(pElement, pClass){
var lRet,
lClassList = pElement && pElement.classList;
@ -1145,7 +1151,7 @@ var CloudCommander, Util, DOM = {}, CloudFunc;
pCurrentFile = pCurrentFile.nextSibling;
if(lCurrentFileWas)
unSetCurrentFile(lCurrentFileWas);
unsetCurrentFile(lCurrentFileWas);
DOM.addClass(pCurrentFile, CURRENT_FILE);

View file

@ -149,17 +149,27 @@ var Util, DOM, jQuery;
};
if(!document.body.classList){
DOM.isContainClass = function(pElement, pClass){
var lRet,
lClassName = pElement && pElement.className;
if(lClassName)
lRet = lClassName.indexOf(pClass) > 0;
return lRet;
};
DOM.addClass = function(pElement, pClass){
var lSpaceChar = '',
lClassName = pElement.className,
lRet_b = true;
var lRet,
lClassName = pElement && pElement.className,
lSpaceChar = lClassName ? ' ' : '';
if(lClassName) lSpaceChar = ' ';
if( lClassName.indexOf(pClass) < 0 )
lRet = !DOM.isContainClass(pElement, pClass);
if( lRet )
pElement.className += lSpaceChar + pClass;
else
lRet_b = false;
return lRet;
};
DOM.removeClass = function(pElement, pClass){

View file

@ -1,63 +1,62 @@
/* module make possible connectoin thrue socket.io on a client */
var CloudCommander, Util, DOM, io;
(function(CloudCmd, Util, DOM, io){
(function(CloudCmd, Util, DOM){
'use strict';
var Messages = [],
socket,
JqueryTerminal;
Terminal,
function getJqueryTerminal(){
ERROR_MSG = 'could not connect to socket.io\n'+
'npm i socket.io';
function getTerminal(){
return CloudCmd.Terminal.JqueryTerminal;
}
DOM.jsload('/socket.io/lib/socket.io.js', {
onload : function(){
socket = io.connect(document.location.hostname);
onerror : Util.retExec(Util.log, ERROR_MSG),
onload : function(){
socket = io.connect(CloudCmd.HOST);
CloudCmd.Socket = socket;
socket.on('connect', function () {
JqueryTerminal = getJqueryTerminal();
Terminal = getTerminal();
if(JqueryTerminal){
if(Terminal){
outToTerminal({stdout: 'socket connected'});
JqueryTerminal.Term.resume();
Terminal.Term.resume();
}
});
socket.on('message', function (msg) {
var lMsg = JSON.parse(msg);
var lMsg = Util.parseJSON(msg);
outToTerminal(lMsg);
});
socket.on('disconnect', function () {
JqueryTerminal = getJqueryTerminal();
Terminal = getTerminal();
if(JqueryTerminal){
if(Terminal){
outToTerminal({stderr: 'socket disconected'});
JqueryTerminal.Term.pause();
Terminal.Term.pause();
}
});
},
onerror : function(){
Util.log('could not connect to socket.io\n'+
'npm i socket.io');
}
});
function outToTerminal(pMsg){
var lTerm,
lResult = true;
var lResult, lTerm;
JqueryTerminal = getJqueryTerminal();
if(JqueryTerminal)
lTerm = JqueryTerminal.Term;
Terminal = getTerminal();
if(Terminal)
lTerm = Terminal.Term;
if(lTerm){
var lStdout,
@ -75,7 +74,7 @@ var CloudCommander, Util, DOM, io;
if(lStderr){
/* if it's object - convert is to string' */
if( Util.isObject(lStderr) )
lStderr = JSON.Stringify(lStderr);
lStderr = Util.stringifyJSON(lStderr);
lTerm.error(lStderr);
}
@ -92,17 +91,13 @@ var CloudCommander, Util, DOM, io;
if(lStderr && lStderr.code !== 1)
lResult = lTerm.error(lStderr.toString());
}
else{
/* if term not accesable
* save msg to buffer
*/
else
/* if term not accesable save msg to buffer */
Messages.push(pMsg);
lResult = false;
}
Util.log(pMsg);
return lResult;
}
})(CloudCommander, Util, DOM, io);
})(CloudCommander, Util, DOM);

View file

@ -16,6 +16,7 @@
var main = global.cloudcmd.main,
fs = main.fs,
Util = main.util,
path = main.path;
exports.getSize = function(pDir, pCallBack) {
@ -49,7 +50,7 @@
for (var i = 0; i < n; i++) {
lDirPath = path.join(pDir, pFiles[i]);
getDirSize(lDirPath);
process.nextTick( Util.retExec(getDirSize, lDirPath) );
}
}