From 999962f5eeebd4759d2d6153e9ec931ac6cb0749 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Fri, 28 Sep 2012 09:23:14 -0400 Subject: [PATCH] minor changes --- lib/client/editor.js | 103 +++++++++++++++++++-------------------- lib/client/keyBinding.js | 4 +- 2 files changed, 51 insertions(+), 56 deletions(-) diff --git a/lib/client/editor.js b/lib/client/editor.js index f875c324..7fc38ed8 100644 --- a/lib/client/editor.js +++ b/lib/client/editor.js @@ -7,10 +7,13 @@ var CloudCommander, CloudFunc, CodeMirror; var cloudcmd = CloudCommander, Util = CloudCommander.Util, KeyBinding = CloudCommander.KeyBinding, - CodeMirrorEditor = {}, - CodeMirrorLoaded = false, + CodeMirrorEditor = {}, FM, - CodeMirrorElement; + CodeMirrorElement, + CodeMirrorLoaded = false, + /* indicator says CodeMirror still loads */ + Loading = false, + ReadOnly = false; cloudcmd.Editor = { get : (function(){ @@ -19,7 +22,8 @@ var CloudCommander, CloudFunc, CodeMirror; }; - var createEditorDiv = function(pIsReadOnly){ + /* private functions */ + function initCodeMirror(pValue){ if(!FM) FM = Util.getById('fm'); @@ -29,16 +33,28 @@ var CloudCommander, CloudFunc, CodeMirror; className : 'panel', parent : FM }); - }; + + CodeMirrorEditor.CodeMirror = new CodeMirror(CodeMirrorElement,{ + mode : 'javascript', + value : pValue, + theme : 'night', + lineNumbers : true, + //переносим длинные строки + lineWrapping: false, + autofocus : true, + extraKeys: { + //Сохранение + "Esc": CodeMirrorEditor.hide + }, + readOnly : ReadOnly + }); + } cloudcmd.Editor.dir = 'lib/client/editor/'; CodeMirrorEditor.dir = cloudcmd.Editor.dir + 'codemirror/'; - /* indicator says CodeMirror still loads */ - CodeMirrorEditor.loading = false; - /* function loads CodeMirror js and css files */ - CodeMirrorEditor.load = (function(pCurrentFile, pIsReadOnly){ + CodeMirrorEditor.load = (function(){ /* function loads css files of CodeMirror */ var loadAll = function() { Util.cssLoad([ @@ -67,7 +83,7 @@ var CloudCommander, CloudFunc, CodeMirror; Util.jsload(CodeMirrorEditor.dir + 'mode/javascript.js', function(){ CodeMirrorLoaded = true; - CodeMirrorEditor.show(pIsReadOnly); + CodeMirrorEditor.show(); }); }; @@ -76,44 +92,17 @@ var CloudCommander, CloudFunc, CodeMirror; }); /* function shows CodeMirror editor */ - CodeMirrorEditor.show = (function(pIsReadOnly){ + CodeMirrorEditor.show = (function(){ /* if CodeMirrorEditor is not loaded - loading him */ if(!CodeMirrorLoaded) - return this.load(pIsReadOnly); + return this.load(); /* if CodeMirror function show already * called do not call it again * if f4 key pressed couple times */ - if(this.loading) + if(Loading) return; - - /* when folder view - * is no need to edit - * data - */ - var lReadOnly = pIsReadOnly || false; - - var lThis = this; - - var initCodeMirror_f = function(pValue){ - createEditorDiv(); - CodeMirrorEditor.CodeMirror = new CodeMirror(CodeMirrorElement,{ - mode : 'javascript', - value : pValue, - theme : 'night', - lineNumbers : true, - //переносим длинные строки - lineWrapping: false, - autofocus : true, - extraKeys: { - //Сохранение - "Esc": lThis.hide - }, - readOnly : lReadOnly - }); - }; - /* getting link */ var lCurrentFile = Util.getCurrentFile(), @@ -132,34 +121,38 @@ var CloudCommander, CloudFunc, CodeMirror; * not html data */ if (lSize === ''){ - if (lA.indexOf(CloudFunc.NOJS) === - CloudFunc.FS.length) { - lA = lA.replace(CloudFunc.NOJS, ''); - lReadOnly = true; + var lIndexOfNOJS = lA.indexOf(CloudFunc.NOJS); + if (lIndexOfNOJS === CloudFunc.FS.length){ + lA = lA.replace(CloudFunc.NOJS, ''); + /* when folder view + * is no need to edit + * data + */ + ReadOnly = true; } } } - this.loading = true; + Loading = true; setTimeout(function(){ - lThis.loading = false;}, + Loading = false; + }, 400); /* reading data from current file */ Util.ajax({ url:lA, - error: (function(jqXHR, textStatus, errorThrown){ - lThis.loading = false; - + error: function(jqXHR, textStatus, errorThrown){ + Loading = false; return Util.Images.showError(jqXHR); - }), + }, success:function(data, textStatus, jqXHR){ /* if we got json - show it */ if(typeof data === 'object') data = JSON.stringify(data, null, 4); - initCodeMirror_f(data); + initCodeMirror(data); /* removing keyBinding if set */ KeyBinding.unSet(); @@ -167,7 +160,7 @@ var CloudCommander, CloudFunc, CodeMirror; Util.hidePanel(); Util.Images.hideLoad(); - lThis.loading = false; + Loading = false; } }); }); @@ -183,10 +176,12 @@ var CloudCommander, CloudFunc, CodeMirror; Util.showPanel(); }); - cloudcmd.Editor.Keys = (function(pCurrentFile, pIsReadOnly){ + cloudcmd.Editor.Keys = (function(pIsReadOnly){ + ReadOnly = pIsReadOnly; + var lThis = this.CodeMirror; /* loading js and css of CodeMirror */ - lThis.show(pCurrentFile, pIsReadOnly); + lThis.show(); var key_event = function(pEvent){ diff --git a/lib/client/keyBinding.js b/lib/client/keyBinding.js index d8d4be5c..02328cf3 100644 --- a/lib/client/keyBinding.js +++ b/lib/client/keyBinding.js @@ -126,7 +126,7 @@ var CloudCommander; lViewer(lCurrentFile); else if (typeof lEditor === 'function') - lEditor(lCurrentFile, true); + lEditor(true); event.preventDefault();//запрет на дальнейшее действие } @@ -136,7 +136,7 @@ var CloudCommander; Util.Images.showLoad(); if (typeof cloudcmd.Editor === 'function') - cloudcmd.Editor(lCurrentFile); + cloudcmd.Editor(); event.preventDefault();//запрет на дальнейшее действие }