var CloudCommander, Util, DOM, CloudFunc, CodeMirror; /* object contains editors CodeMirror */ (function(){ "use strict"; var cloudcmd = CloudCommander, KeyBinding = CloudCommander.KeyBinding, CodeMirrorEditor = {}, FM, CodeMirrorElement, CodeMirrorLoaded = false, /* indicator says CodeMirror still loads */ Loading = false, ReadOnly = false; cloudcmd.Editor = { get : (function(){ return this.CodeMirror; }) }; /* private functions */ function setCSS(){ return DOM.cssSet({ id : 'editor', inner : '.CodeMirror{' + 'font-family' + ': \'Droid Sans Mono\';' + 'font-size' + ': 15px;' + /* codemirror v3 */ //'height : ' + cloudcmd.HEIGHT + 'px' + '}' + '.CodeMirror-scroll{' + 'height' + ':' + cloudcmd.HEIGHT + 'px' + '}' + '#CodeMirrorEditor{' + 'float' + ':' + DOM.getPanel().id + // 'padding :20px 20px 20px 20px;' + '}' }); } /** * function initialize CodeMirror * @param {value, callback} */ function initCodeMirror(pData){ if(!pData) pData = {}; if(!FM) FM = DOM.getFM(); var lCSS = setCSS(); CodeMirrorElement = DOM.anyload({ name : 'div', id : 'CodeMirrorEditor', className : 'panel', parent : FM }); CodeMirrorEditor.CodeMirror = new CodeMirror(CodeMirrorElement,{ mode : 'javascript', value : pData.data, theme : 'night', lineNumbers : true, //переносим длинные строки lineWrapping: false, autofocus : true, extraKeys: { //Сохранение 'Esc': function(){ DOM.remove(lCSS, document.head); Util.exec(pData.callback); } }, readOnly : ReadOnly }); } /** * function loads CodeMirror js and css files */ function load(pCallBack){ console.time('codemirror load'); var lDir = cloudcmd.LIBDIRCLIENT + 'editor/codemirror/'; DOM.anyLoadOnLoad([ lDir + 'codemirror.css', lDir + 'theme/night.css', lDir + 'mode/javascript.js', lDir + 'codemirror.js'], function(){ console.timeEnd('codemirror load'); CodeMirrorLoaded = true; Util.exec(pCallBack); } ); } /** * function shows CodeMirror editor */ CodeMirrorEditor.show = function(pCallBack){ /* if CodeMirror function show already * called do not call it again * if f4 key pressed couple times */ if(Loading) return; /* getting link */ var lCurrentFile = DOM.getCurrentFile(), lA = DOM.getCurrentLink(lCurrentFile); lA = lA.href; /* убираем адрес хоста*/ lA = lA.replace(cloudcmd.HOST, ''); /* checking is this link is to directory */ var lSize = DOM.getByClass('size', lCurrentFile); if(lSize){ lSize = lSize[0].textContent; /* if directory - load json * not html data */ if (lSize === '