var CloudCommander, CloudFunc, CodeMirror; /* object contains editors CodeMirror * and later will be Ace */ (function(){ "use strict"; var cloudcmd = CloudCommander; var Util = CloudCommander.Util; var KeyBinding = CloudCommander.KeyBinding; CloudCommander.Editor = { get : (function(){ return this.CodeMirror; }) }; var Cloud_CodeMirror = {}; /* indicator says CodeMirror still loads */ Cloud_CodeMirror.loading = false; /* function loads CodeMirror js and css files */ Cloud_CodeMirror.load = (function(pCurrentFile, pIsReadOnly){ /* function shows editor */ var lThis = this; var createEditorDiv = function(){ if (!Util.getById('CloudEditor')) { var lFM = Util.getById('fm'); if(lFM) Util.anyload({ name : 'div', id : 'CloudEditor', parent : lFM }); else console.log('Error. Something went wrong FM not found'); lThis.show(pCurrentFile, pIsReadOnly); } }; /* function loads css files * of CodeMirror */ var loadAll = function() { Util.cssLoad([ { src : 'lib/client/editor/codemirror/codemirror.css'}, { src : 'lib/client/editor/codemirror/theme/night.css'} ]); Util.cssSet({id:'editor', inner : '.CodeMirror{' + 'font-family :\'Droid Sans Mono\';' + 'font-size :15px;' + 'padding :20px 0 0 0;' + '}' + '.CodeMirror-scroll{' + 'height : ' + (cloudcmd.HEIGHT-40) + 'px' + '}' }); Util.jsload('lib/client/editor/' + 'codemirror/mode/javascript.js', createEditorDiv); }; /* load CodeMirror main module */ Util.jsload('lib/client/editor/' + 'codemirror/codemirror.js', loadAll); }); /* function shows CodeMirror editor */ Cloud_CodeMirror.show = (function(pCurrentFile, pIsReadOnly){ /* if CloudEditor is not loaded - loading him */ var lCloudEditor = Util.getById('CloudEditor'); if(!lCloudEditor) return this.load(pCurrentFile, pIsReadOnly); /* if CodeMirror function show already * called do not call it again * if f4 key pressed couple times */ if(this.loading) return; /* when folder view * is no need to edit * data */ var lReadOnly = pIsReadOnly || false; var lThis = this; var initCodeMirror_f = function(pValue){ lCloudEditor.className = 'panel'; new CodeMirror(lCloudEditor,{ mode : 'javascript', value : pValue, theme : 'night', lineNumbers : true, //переносим длинные строки lineWrapping: false, autofocus : true, extraKeys: { //Сохранение "Esc": lThis.hide(lThis) }, readOnly : lReadOnly }); }; var lA; /* getting link */ lA = Util.getByTag('a', pCurrentFile); lA = lA[0].href; /* убираем адрес хоста*/ lA = '/' + lA.replace(document.location.href,''); /* checking is this link is to directory */ var lSize = Util.getByClass('size', pCurrentFile); if(lSize){ lSize = lSize[0].textContent; /* if directory - load json * not html data */ if (lSize === '