From ad87f4ff6b3d6c163c57e2005bbf6b3b1d05e06e Mon Sep 17 00:00:00 2001 From: coderaiser Date: Fri, 9 Nov 2012 07:43:48 -0500 Subject: [PATCH] minor changes --- client.js | 76 +++++++++++++++++++--------------------- lib/client/keyBinding.js | 60 +++++++++++++++---------------- lib/client/menu.js | 16 +++------ lib/server/main.js | 5 +-- lib/util.js | 50 ++++++++++++++++++++++---- server.js | 10 +++--- 6 files changed, 119 insertions(+), 98 deletions(-) diff --git a/client.js b/client.js index f2efb96a..e8977a9f 100644 --- a/client.js +++ b/client.js @@ -242,7 +242,11 @@ CloudClient._loadDir = function(pLink,pNeedRefresh){ * onclick */ - pEvent.returnValue = false; + Util.setValue({ + object : pEvent, + property: 'returnValue', + value : false + }); return lRet; }; @@ -585,11 +589,7 @@ CloudClient._changeLinks = function(pPanelID){ /* устанавливаем обработчики на строку на одинарное и * * двойное нажатие на левую кнопку мышки */ else{ - var lLi; - - try{ - lLi = a[i].parentElement.parentElement; - }catch(error){console.log(error);} + var lLi = a[i].parentElement.parentElement; /* if we in path changing onclick events */ if (lLi.className === 'path') { @@ -597,9 +597,7 @@ CloudClient._changeLinks = function(pPanelID){ } else { lLi.onclick = CloudClient._setCurrent(); - lLi.onmousedown = lSetCurrentFile_f; - a[i].ondragstart = lOnDragStart_f; /* if right button clicked menu will @@ -611,10 +609,11 @@ CloudClient._changeLinks = function(pPanelID){ if(a[i].target !== '_blank'){ lLi.ondblclick = CloudClient._loadDir(link); - if(lLi.addEventListener) + var lListener = lLi.addEventListener; + if(lListener) lLi.addEventListener('touchend', CloudClient._loadDir(link), - false); + false); } lLi.id = (a[i].title ? a[i].title : a[i].textContent) + @@ -654,20 +653,21 @@ CloudClient._ajaxLoad = function(path, pNeedRefresh){ /* опредиляем в какой мы панели: * правой или левой */ - var lPanel = DOM.getPanel().id; + var lPanel = DOM.getPanel().id, + lError; if(pNeedRefresh === undefined && lPanel){ var lJSON = CloudClient.Cache.get(lPath); + if (lJSON !== null){ - /* переводим из текста в JSON */ if(window && !window.JSON){ - try{ + lError = Util.tryCatchLog(function(){ lJSON = eval('('+lJSON+')'); - }catch(err){ - console.log(err); - } - }else lJSON = JSON.parse(lJSON); + }); + + }else + lJSON = JSON.parse(lJSON); CloudClient._createFileTable(lPanel, lJSON); CloudClient._changeLinks(lPanel); @@ -677,7 +677,7 @@ CloudClient._ajaxLoad = function(path, pNeedRefresh){ } /* ######################## */ - try{ + Util.tryCatchLog(function(){ DOM.ajax({ url: path, error: DOM.Images.showError, @@ -708,7 +708,7 @@ CloudClient._ajaxLoad = function(path, pNeedRefresh){ CloudClient.Cache.set(lPath,lJSON_s); } }); - }catch(err){console.log(err);} + }); }; /** @@ -771,18 +771,18 @@ CloudClient._getJSONfromFileTable = function(){ for(; i +s pressed'); - console.log('+r reload key-handerl - set'); - console.log('+s clear cache key-handler - set'); - console.log('press +q to remove them'); - - event.preventDefault();//запрет на дальнейшее действие + else if(event.keyCode === KEY.S && event.altKey){ + /* обрабатываем нажатия на клавиши*/ + keyBinded = true; + + console.log('+s pressed'); + console.log('+r reload key-handerl - set'); + console.log('+s clear cache key-handler - set'); + console.log('press +q to remove them'); + + event.preventDefault();//запрет на дальнейшее действие } return false; diff --git a/lib/client/menu.js b/lib/client/menu.js index c3e1964a..e285c92e 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, $; +var CloudCommander, Util, DOM, CloudFunc, $; (function(){ "use strict"; @@ -203,8 +203,7 @@ var CloudCommander, Util, DOM, $; var lFunc = document.oncontextmenu; document.oncontextmenu = function(){ - if(typeof lFunc === 'function') - lFunc(); + Util.exec(lFunc); return Menu.ENABLED; }; @@ -224,18 +223,13 @@ var CloudCommander, Util, DOM, $; }); /* добавляем обработчик клавишь */ - if (document.addEventListener) + if (document.addEventListener) document.addEventListener('keydown', key_event.bind(this),false); else{ - lFunc; - if(typeof document.onkeydown === 'function') - lFunc = document.onkeydown; - + lFunc = document.onkeydown; document.onkeydown = function(){ - if(lFunc) - lFunc(); - + Util.exec(lFunc); key_event(); }; diff --git a/lib/server/main.js b/lib/server/main.js index b1af8bc8..b8490c20 100644 --- a/lib/server/main.js +++ b/lib/server/main.js @@ -21,9 +21,10 @@ /* Native Modules*/ exports.child_process = require('child_process'), exports.fs = require('fs'), + exports.http = require('http'), exports.https = require('https'), - exports.path = require('path'), - exports.querystring = require('querystring'), + exports.path = require('path'), + exports.querystring = require('querystring'), /* Needed Modules */ exports.util = Util = require(LIBDIR + 'util'), diff --git a/lib/util.js b/lib/util.js index 4ab304a5..ea1c1559 100644 --- a/lib/util.js +++ b/lib/util.js @@ -46,6 +46,18 @@ var Util, exports; pStr1.indexOf(pStr2) >= 0; }; + /** + * function log pArg if it's not empty + * @param pArg + */ + Util.log = function(pArg){ + var lRet = pArg; + if(pArg) + console.log(pArg); + + return lRet; + }; + /** * function remove substring from string * @param pStr @@ -115,14 +127,25 @@ var Util, exports; }; }; - Util.ExecOnExec = function(pCallBacks){ - if(Util.isArray(pCallBacks)){ - for(var i = 0, n = pCallBacks.length; i < n; i++){ - var lFunc = pCallBacks.pop(); - - Util.execOnExec( Util.retExec(lFunc, pCallBacks) ); + /** + * set value to property of object, if object exist + * @param pArgs {object, property, value} + */ + Util.setValue = function(pArgs){ + var lRet = false; + + if( Util.isObject(pArgs) ){ + var lObj = pArgs.object, + lProp = pArgs.property, + lVal = pArgs.lVal; + + if(lObj){ + lObj[lProp] = lVal; + lRet = true; } } + + return lRet; }; /** @@ -131,7 +154,7 @@ var Util, exports; * * @param pCallBack */ - Util.tryCatch = function(pCallBack){ + Util.tryCatch = function(pCallBack){ var lRet; try{ lRet = pCallBack(); @@ -143,6 +166,19 @@ var Util, exports; return lRet; }; + /** + * function execute param function in + * try...catch block and log result + * + * @param pCallBack + */ + Util.tryCatchLog = function(pCallBack){ + var lRet; + + lRet = Util.tryCatch(pCallBack); + + return Util.log(lRet); + }; /** * function do save exec */ diff --git a/server.js b/server.js index 3b70e30c..75803644 100644 --- a/server.js +++ b/server.js @@ -171,9 +171,8 @@ CloudServer.start = function (pConfig, pIndexProcessing, pAppCachProcessing) { /* server mode or testing mode */ if (lConfig.server) { - var http = require('http'); - - try { + var http = main.http, + lError = Util.tryCatchLog(function(){ this.Server = http.createServer(this._controller); this.Server.listen(this.Port, this.IP); @@ -186,10 +185,9 @@ CloudServer.start = function (pConfig, pIndexProcessing, pAppCachProcessing) { console.log('Cloud Commander server running at http://' + this.IP + ':' + this.Port); - }catch(pError){ + }); + if(lError) console.log('Cloud Commander server could not started'); - console.log(pError); - } }else console.log('Cloud Commander testing mode'); };