From 4e77f783b855f542829862ec2b526908e39cac49 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Tue, 13 Nov 2012 10:33:50 -0500 Subject: [PATCH] minor changes --- client.js | 2 +- lib/client/dom.js | 53 ++++++++++++++++-------------------------- lib/client/terminal.js | 8 +++---- lib/util.js | 13 ++++++++++- package.json | 2 +- 5 files changed, 37 insertions(+), 41 deletions(-) diff --git a/client.js b/client.js index 77f3c359..a67b14fe 100644 --- a/client.js +++ b/client.js @@ -494,7 +494,7 @@ function baseInit(pCallBack){ '}' }); - Util.exec(pCallBack || initModules); + Util.exec(pCallBack); cloudcmd.KeyBinding(); } diff --git a/lib/client/dom.js b/lib/client/dom.js index b58b79ca..a7b35376 100644 --- a/lib/client/dom.js +++ b/lib/client/dom.js @@ -1,4 +1,4 @@ -var CloudCommander, $, Util, DOM; +var CloudCommander, $, Util, DOM, CloudFunc; (function(){ "use strict"; @@ -20,7 +20,7 @@ var CloudCommander, $, Util, DOM; * функции для отображения * картинок */ - Images_o = { + Images_o = { /* Функция создаёт картинку загрузки*/ loading : function(){ var lE = DOM.getById('loading-image'); @@ -104,48 +104,38 @@ var CloudCommander, $, Util, DOM; XMLHTTP.send(null); var lSuccess_f = pParams.success; - if(typeof lSuccess_f !== 'function') - console.log('error in DOM.ajax onSuccess:', pParams); + if( !Util.isFunction(lSuccess_f) ) + console.log('error in DOM.ajax onSuccess:', pParams); XMLHTTP.onreadystatechange = function(pEvent){ if (XMLHTTP.readyState === 4 /* Complete */){ - var lJqXHR = pEvent.target; - var lContentType = XMLHTTP.getResponseHeader('content-type'); + var lJqXHR = pEvent.target, + lType = XMLHTTP.getResponseHeader('content-type'); if (XMLHTTP.status === 200 /* OK */){ var lData = lJqXHR.response; /* If it's json - parse it as json */ - if(lContentType && - lContentType.indexOf('application/json') === 0){ - try{ - lData = JSON.parse(lJqXHR.response); - } - catch(pError) { - /* if could not parse */ - console.log('Error: could not parse' + - 'json from server from url: ' + - pParams.url); - - lData = lJqXHR.response; - } - } + if(lType && Util.isContainStr(lType, 'application/json') ){ + var lResult = Util.tryCatch(function(){ + lData = JSON.parse(lJqXHR.response); + }); + + if( Util.log(lResult) ) + lData = lJqXHR.response; + } lSuccess_f(lData, lJqXHR.statusText, lJqXHR); } else/* file not found or connection lost */{ - var lError_f = pParams.error; - /* if html given or something like it * getBack just status of result */ - if(lContentType && - lContentType.indexOf('text/plain') !== 0){ + if(lType && + lType.indexOf('text/plain') !== 0){ lJqXHR.responseText = lJqXHR.statusText; } - - if(typeof lError_f === 'function') - lError_f(lJqXHR); + Util.exec(pParams.error, lJqXHR); } } }; @@ -184,7 +174,8 @@ var CloudCommander, $, Util, DOM; DOM.anyload(lParam); - }else Util.exec(pFunc); + }else + Util.exec(pFunc); } }; @@ -382,11 +373,7 @@ var CloudCommander, $, Util, DOM; DOM.jqueryLoad = function(pCallBack){ /* загружаем jquery: */ DOM.jsload('//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js',{ - onload: function(){ - $ = window.jQuery; - if(typeof pCallBack === 'function') - pCallBack(); - }, + onload: Util.retExec(pCallBack), onerror: function(){ DOM.jsload('lib/client/jquery.js'); diff --git a/lib/client/terminal.js b/lib/client/terminal.js index d91bcf43..571c3eb5 100644 --- a/lib/client/terminal.js +++ b/lib/client/terminal.js @@ -48,7 +48,7 @@ var CloudCommander, Util, DOM, $; $(window).unbind('resize'); - Util.exec(pCallBack); + Util.exec(pCallBack.callback || pCallBack); }); } @@ -105,13 +105,11 @@ var CloudCommander, Util, DOM, $; */ cloudcmd.Terminal.Keys = function(){ /* loading js and css*/ - DOM.jqueryLoad(function(){ - Util.loadOnLoad([ + DOM.jqueryLoad( Util.retLoadOnLoad([ JqueryTerminal.show, load, DOM.socketLoad - ]); - }); + ]) ); /* добавляем обработчик клавишь */ DOM.addKeyListener(function(){ diff --git a/lib/util.js b/lib/util.js index 368a3bfb..610f59a9 100644 --- a/lib/util.js +++ b/lib/util.js @@ -65,7 +65,7 @@ var Util, exports; */ Util.loadOnLoad = function(pFunc_a, pData){ if( Util.isArray(pFunc_a) && pFunc_a.length) { - var lFunc_a = pFunc_a.slice, + var lFunc_a = pFunc_a.slice(), lFunc = lFunc_a.pop(), lCallBack = function(pData){ return Util.loadOnLoad(lFunc_a, pData); @@ -150,6 +150,17 @@ var Util, exports; }; }; + /** + * return load functions thrue callbacks one-by-one + * @param pFunc_a {Array} - array of functions + * @param pData - not necessarily + */ + Util.retLoadOnLoad = function(pFunc_a, pData){ + return function(){ + Util.loadOnLoad(pFunc_a, pData); + }; + }; + /** * set value to property of object, if object exist * @param pArgs {object, property, value} diff --git a/package.json b/package.json index 74e76409..9c9c110b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cloudcmd", - "version": "0.1.7", + "version": "0.1.7-20", "author": "coderaiser (https://github.com/coderaiser)", "description": "Two-panels file manager, totally writed on js.", "homepage": "https://github.com/coderaiser/cloudcmd",