From b767b005ea1c423b0a5d9fef1b46cf6f3911d45e Mon Sep 17 00:00:00 2001 From: coderaiser Date: Wed, 5 Jun 2013 07:23:02 -0400 Subject: [PATCH] minor changes --- json/config.json | 2 +- lib/client.js | 2 - lib/client/edit/_codemirror.js | 337 +++++++++++++++++---------------- lib/client/key.js | 10 +- 4 files changed, 178 insertions(+), 173 deletions(-) diff --git a/json/config.json b/json/config.json index ca98c321..de652952 100644 --- a/json/config.json +++ b/json/config.json @@ -4,7 +4,7 @@ "minification" : { "js" : false, "css" : false, - "html" : true, + "html" : false, "img" : true }, "cache" : true, diff --git a/lib/client.js b/lib/client.js index d53d8a1c..ce7f490f 100644 --- a/lib/client.js +++ b/lib/client.js @@ -16,7 +16,6 @@ var Util, DOM, CloudFunc, CloudCmd; LIBDIRCLIENT : '/lib/client/', JSONDIR : '/json/', HTMLDIR : '/html/', - /* height of Cloud Commander seting up in */ HEIGHT : 0, MIN_ONE_PANEL_WIDTH : 1155, OLD_BROWSER : false, @@ -519,7 +518,6 @@ var Util, DOM, CloudFunc, CloudCmd; var lJSON = Cache.get(lCleanPath); if (lJSON){ - /* переводим из текста в JSON */ lJSON = Util.parseJSON(lJSON); createFileTable(lPanel, lJSON); } diff --git a/lib/client/edit/_codemirror.js b/lib/client/edit/_codemirror.js index d433c441..ecc3c91f 100644 --- a/lib/client/edit/_codemirror.js +++ b/lib/client/edit/_codemirror.js @@ -3,180 +3,47 @@ var CloudCmd, Util, DOM, CodeMirror; (function(CloudCmd, Util, DOM){ 'use strict'; - var Key = CloudCmd.Key, - Edit = {}, - FM, - Element, - Loaded = false, - Loading = false, - ReadOnly = false, - - CallBacks = [ - hide, - init, - show, - load - ]; + CloudCmd.Edit = new EditProto(CloudCmd, Util, DOM); - function setCSS(){ - var lPosition = DOM.getPanel().id, - lRet = DOM.cssSet({ - id : 'editor-css', - inner : '.CodeMirror{' + - 'font-family' + ': \'Droid Sans Mono\';' + - 'font-size' + ': 15px;' + - '}' + - '.CodeMirror-scroll{' + - 'height' + ':' + CloudCmd.HEIGHT + 'px' + - '}' + - '#editor{' + - 'float' + ':' + lPosition + - '}' - }); + function EditProto(CloudCmd, Util, DOM){ + var Key = CloudCmd.Key, + Edit = this, + FM, + Element, + Loaded = false, + Loading = false, + ReadOnly = false, + + CallBacks = [ + hide, + init, + _show, + load + ]; - return lRet; - } - - /** - * function initialize CodeMirror - * @param {value, callback} - */ - function init(pParams){ - if(!FM) - FM = DOM.getFM(); - - var lCSS = setCSS(), - lCurrent = DOM.getCurrentFile(), - lPath = DOM.getCurrentPath( lCurrent ); - - Element = DOM.anyload({ - name : 'div', - id : 'editor', - className : 'panel', - parent : FM - }); - - var lEditor = Edit.CodeMirror = new CodeMirror(Element, { - mode : 'javascript', - value : pParams && pParams.data && pParams.data.data, - theme : 'night', - lineNumbers : true, - lineWrapping: false, - autofocus : true, - extraKeys: { - /* Exit */ - 'Esc': function(){ - Util.exec(pParams); - DOM.remove(lCSS, document.head); - }, - - /* Save */ - 'Ctrl-S': function(){ - var lValue = lEditor.getValue(); - - DOM.setCurrentSize( lValue.length, lCurrent ); - DOM.RESTfull.save( lPath, lValue ); - } - }, - readOnly : ReadOnly - }); - } - - /** - * function loads CodeMirror js and css files - */ - function load(pCallBack){ - Util.time('codemirror load'); - var lDir = CloudCmd.LIBDIRCLIENT + 'edit/codemirror/', - lFiles = - [ - [ - lDir + 'codemirror.css', - lDir + 'theme/night.css', - lDir + 'mode/javascript.js', - ], - - lDir + 'codemirror.js' - ]; - - DOM.anyLoadOnLoad(lFiles, function(){ - Util.timeEnd('codemirror load'); - Loaded = true; - Util.exec(pCallBack); - }); - } - - /** - * function shows CodeMirror editor - */ - function show(pCallBack){ - - /* if CodeMirror function show already - * called do not call it again - * if f4 key pressed couple times + /** + * function calls all CodeMirror editor functions */ - if(!Loading){ - /* checking is this link is to directory - * when folder view is no need to edit data */ - ReadOnly = DOM.isCurrentIsDir(); - - Loading = true; - - setTimeout(lFalseLoading, 400); - - DOM.getCurrentData({ - error : lFalseLoading, - success : function(data){ - if( DOM.hidePanel() ){ - Util.exec(pCallBack, data); - Key.unsetBind(); - } - - DOM.Images.hideLoad(); - lFalseLoading(); - } - }); - } + this.show = show; + /** + * function hides CodeMirror editor + */ + this.hide = hide; - function lFalseLoading(){ Loading = false; } - } - - /** - * function hides CodeMirror editor - */ - function hide() { - Key.setBind(); + /** + * function bind keys + */ + this.init = function(){ + CloudCmd.Edit = Edit; + }; - if(Element && FM) - FM.removeChild(Element); - - DOM.showPanel(); - } - - /** - * function calls all CodeMirror editor functions - */ - Edit.show = function(){ - DOM.Images.showLoad(); - Util.loadOnLoad( CallBacks ); - }; - - /** - * function hides CodeMirror editor - */ - Edit.hide = hide; - - /** - * function bind keys - */ - CloudCmd.Edit.init = function(){ - Edit.show(); + show(); CallBacks.pop(); /* добавляем обработчик клавишь */ DOM.Events.addKey(lListener); DOM.setButtonKey('f4', Edit.show); - + function lListener(pEvent){ var lIsBind = Key.isBind(); @@ -189,7 +56,145 @@ var CloudCmd, Util, DOM, CodeMirror; } } - CloudCmd.Edit = Edit; - }; + function setCSS(){ + var lPosition = DOM.getPanel().id, + lRet = DOM.cssSet({ + id : 'edit-css', + inner : '.CodeMirror{' + + 'font-family' + ': \'Droid Sans Mono\';' + + 'font-size' + ': 15px;' + + '}' + + '.CodeMirror-scroll{' + + 'height' + ':' + CloudCmd.HEIGHT + 'px' + + '}' + + '#edit{' + + 'float' + ':' + lPosition + + '}' + }); + + return lRet; + } + + /** + * function initialize CodeMirror + * @param {value, callback} + */ + function init(pParams){ + if(!FM) + FM = DOM.getFM(); + + var lCSS = setCSS(), + lCurrent = DOM.getCurrentFile(), + lPath = DOM.getCurrentPath( lCurrent ); + + Element = DOM.anyload({ + name : 'div', + id : 'edit', + className : 'panel', + parent : FM + }); + + var lEdit = Edit.CodeMirror = new CodeMirror(Element, { + mode : 'javascript', + value : pParams && pParams.data && pParams.data.data, + theme : 'night', + lineNumbers : true, + lineWrapping: false, + autofocus : true, + extraKeys: { + /* Exit */ + 'Esc': function(){ + Util.exec(pParams); + DOM.remove(lCSS, document.head); + }, + + /* Save */ + 'Ctrl-S': function(){ + var lValue = lEdit.getValue(); + + DOM.setCurrentSize( lValue.length, lCurrent ); + DOM.RESTfull.save( lPath, lValue ); + } + }, + readOnly : ReadOnly + }); + } + + /** + * function loads CodeMirror js and css files + */ + function load(pCallBack){ + Util.time('codemirror load'); + var lDir = CloudCmd.LIBDIRCLIENT + 'edit/codemirror/', + lFiles = + [ + [ + lDir + 'codemirror.css', + lDir + 'theme/night.css', + lDir + 'mode/javascript.js', + ], + + lDir + 'codemirror.js' + ]; + + DOM.anyLoadOnLoad(lFiles, function(){ + Util.timeEnd('codemirror load'); + Loaded = true; + Util.exec(pCallBack); + }); + } + + /** + * function shows CodeMirror editor + */ + function _show(pCallBack){ + + /* if CodeMirror function show already + * called do not call it again + * if f4 key pressed couple times + */ + if(!Loading){ + /* checking is this link is to directory + * when folder view is no need to edit data */ + ReadOnly = DOM.isCurrentIsDir(); + + Loading = true; + + setTimeout(lFalseLoading, 400); + + DOM.getCurrentData({ + error : lFalseLoading, + success : function(data){ + if( DOM.hidePanel() ){ + Util.exec(pCallBack, data); + Key.unsetBind(); + } + + DOM.Images.hideLoad(); + lFalseLoading(); + } + }); + } + + function lFalseLoading(){ Loading = false; } + } + + function show() { + DOM.Images.showLoad(); + Util.loadOnLoad( CallBacks ); + } + + /** + * function hides CodeMirror editor + */ + function hide() { + Key.setBind(); + + if(Element && FM) + FM.removeChild(Element); + + DOM.showPanel(); + } + } })(CloudCmd, Util, DOM); diff --git a/lib/client/key.js b/lib/client/key.js index bb09a819..4262bd7f 100644 --- a/lib/client/key.js +++ b/lib/client/key.js @@ -44,9 +44,9 @@ var CloudCmd, Util, DOM; }; KeyProto.prototype = KEY; - CloudCmd.Key = new KeyProto(); + CloudCmd.Key = new KeyProto(CloudCmd, Util, DOM); - function KeyProto(){ + function KeyProto(CloudCmd, Util, DOM){ var Key = this, Binded, lTabPanel = { @@ -284,11 +284,13 @@ var CloudCmd, Util, DOM; break; - /* обновляем страницу, + /* + * обновляем страницу, * загружаем содержимое каталога * при этом данные берём всегда с * сервера, а не из кэша - * (обновляем кэш)*/ + * (обновляем кэш) + */ case Key.R: if(lCtrl){ Util.log('+r pressed\n' +