From e6754ed759064289295a258bf17e74ee65d89db4 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Mon, 8 Apr 2013 09:18:00 -0400 Subject: [PATCH] refactored --- json/config.json | 2 +- lib/client/dom.js | 12 +++++++--- lib/client/ie.js | 26 ++++++++++++++------- lib/client/socket.js | 55 ++++++++++++++++++++------------------------ lib/server/dir.js | 3 ++- 5 files changed, 55 insertions(+), 43 deletions(-) diff --git a/json/config.json b/json/config.json index adfe121a..3a8b6f66 100644 --- a/json/config.json +++ b/json/config.json @@ -3,7 +3,7 @@ "appcache" : false, "minification" : { "js" : false, - "css" : false, + "css" : true, "html" : true, "img" : true }, diff --git a/lib/client/dom.js b/lib/client/dom.js index c13386f0..e3e38955 100644 --- a/lib/client/dom.js +++ b/lib/client/dom.js @@ -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); diff --git a/lib/client/ie.js b/lib/client/ie.js index 974ae5e7..f9f446b8 100644 --- a/lib/client/ie.js +++ b/lib/client/ie.js @@ -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){ diff --git a/lib/client/socket.js b/lib/client/socket.js index d9544929..bb6dcf96 100644 --- a/lib/client/socket.js +++ b/lib/client/socket.js @@ -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); \ No newline at end of file +})(CloudCommander, Util, DOM); \ No newline at end of file diff --git a/lib/server/dir.js b/lib/server/dir.js index ff8043eb..8a8585a5 100644 --- a/lib/server/dir.js +++ b/lib/server/dir.js @@ -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) ); } }