mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-21 02:29:23 +00:00
refactored
This commit is contained in:
parent
6e4016fd1f
commit
f3e346f539
1 changed files with 41 additions and 43 deletions
|
|
@ -4,34 +4,35 @@ var CloudCommander, CloudFunc, CodeMirror;
|
|||
*/
|
||||
(function(){
|
||||
"use strict";
|
||||
var cloudcmd = CloudCommander;
|
||||
var Util = CloudCommander.Util;
|
||||
var KeyBinding = CloudCommander.KeyBinding;
|
||||
var cloudcmd = CloudCommander,
|
||||
Util = CloudCommander.Util,
|
||||
KeyBinding = CloudCommander.KeyBinding,
|
||||
CodeMirrorEditor = {},
|
||||
CodeMirrorElement;
|
||||
|
||||
CloudCommander.Editor = {
|
||||
cloudcmd.Editor = {
|
||||
get : (function(){
|
||||
return this.CodeMirror;
|
||||
})
|
||||
};
|
||||
var CloudMirror = {};
|
||||
};
|
||||
|
||||
cloudcmd.Editor.dir = 'lib/client/editor/';
|
||||
CloudMirror.dir = cloudcmd.Editor.dir + 'codemirror/';
|
||||
cloudcmd.Editor.dir = 'lib/client/editor/';
|
||||
CodeMirrorEditor.dir = cloudcmd.Editor.dir + 'codemirror/';
|
||||
|
||||
/* indicator says CodeMirror still loads */
|
||||
CloudMirror.loading = false;
|
||||
CodeMirrorEditor.loading = false;
|
||||
|
||||
/* function loads CodeMirror js and css files */
|
||||
CloudMirror.load = (function(pCurrentFile, pIsReadOnly){
|
||||
CodeMirrorEditor.load = (function(pCurrentFile, pIsReadOnly){
|
||||
/* function shows editor */
|
||||
var lThis = this;
|
||||
var createEditorDiv = function(){
|
||||
if (!Util.getById('CloudEditor')) {
|
||||
if (!CodeMirrorElement) {
|
||||
var lFM = Util.getById('fm');
|
||||
if(lFM)
|
||||
Util.anyload({
|
||||
CodeMirrorElement = Util.anyload({
|
||||
name : 'div',
|
||||
id : 'CloudEditor',
|
||||
id : 'CodeMirrorEditor',
|
||||
parent : lFM
|
||||
});
|
||||
else
|
||||
|
|
@ -45,8 +46,8 @@ var CloudCommander, CloudFunc, CodeMirror;
|
|||
*/
|
||||
var loadAll = function() {
|
||||
Util.cssLoad([
|
||||
{ src : CloudMirror.dir + 'codemirror.css'},
|
||||
{ src : CloudMirror.dir + 'theme/night.css'}
|
||||
{ src : CodeMirrorEditor.dir + 'codemirror.css'},
|
||||
{ src : CodeMirrorEditor.dir + 'theme/night.css'}
|
||||
]);
|
||||
|
||||
|
||||
|
|
@ -61,20 +62,21 @@ var CloudCommander, CloudFunc, CodeMirror;
|
|||
'}'
|
||||
});
|
||||
|
||||
Util.jsload(CloudMirror.dir +
|
||||
Util.jsload(CodeMirrorEditor.dir +
|
||||
'mode/javascript.js', createEditorDiv);
|
||||
};
|
||||
|
||||
/* load CodeMirror main module */
|
||||
Util.jsload(CloudMirror.dir +
|
||||
Util.jsload(CodeMirrorEditor.dir +
|
||||
'codemirror.js', loadAll);
|
||||
});
|
||||
|
||||
/* function shows CodeMirror editor */
|
||||
CloudMirror.show = (function(pCurrentFile, pIsReadOnly){
|
||||
/* if CloudEditor is not loaded - loading him */
|
||||
var lCloudEditor = Util.getById('CloudEditor');
|
||||
if(!lCloudEditor)
|
||||
CodeMirrorEditor.show = (function(pCurrentFile, pIsReadOnly){
|
||||
|
||||
/* if CodeMirrorEditor is not loaded - loading him */
|
||||
var lCodeMirrorEditor = Util.getById('CodeMirrorEditor');
|
||||
if(!lCodeMirrorEditor)
|
||||
return this.load(pCurrentFile, pIsReadOnly);
|
||||
|
||||
/* if CodeMirror function show already
|
||||
|
|
@ -93,8 +95,8 @@ var CloudCommander, CloudFunc, CodeMirror;
|
|||
var lThis = this;
|
||||
|
||||
var initCodeMirror_f = function(pValue){
|
||||
lCloudEditor.className = 'panel';
|
||||
new CodeMirror(lCloudEditor,{
|
||||
lCodeMirrorEditor.className = 'panel';
|
||||
new CodeMirror(lCodeMirrorEditor,{
|
||||
mode : 'javascript',
|
||||
value : pValue,
|
||||
theme : 'night',
|
||||
|
|
@ -104,7 +106,7 @@ var CloudCommander, CloudFunc, CodeMirror;
|
|||
autofocus : true,
|
||||
extraKeys: {
|
||||
//Сохранение
|
||||
"Esc": lThis.hide(lThis)
|
||||
"Esc": lThis.hide
|
||||
},
|
||||
readOnly : lReadOnly
|
||||
});
|
||||
|
|
@ -170,29 +172,24 @@ var CloudCommander, CloudFunc, CodeMirror;
|
|||
});
|
||||
|
||||
/* function hides CodeMirror editor */
|
||||
CloudMirror.hide = (function() {
|
||||
return function(){
|
||||
KeyBinding.set();
|
||||
Util.showPanel();
|
||||
CodeMirrorEditor.hide = (function() {
|
||||
KeyBinding.set();
|
||||
|
||||
if(CodeMirrorElement){
|
||||
Util.hide(CodeMirrorElement);
|
||||
var lCodeMirror = Util.getByClass('CodeMirror', CodeMirrorElement);
|
||||
|
||||
var lCloudEditor = Util.getById('CloudEditor');
|
||||
if(lCloudEditor){
|
||||
Util.hide(lCloudEditor);
|
||||
var lCodeMirror = Util.getByClass('CodeMirror', lCloudEditor);
|
||||
|
||||
if(lCodeMirror.length)
|
||||
lCloudEditor
|
||||
.removeChild(lCodeMirror[0]);
|
||||
}
|
||||
};
|
||||
if(lCodeMirror.length)
|
||||
CodeMirrorElement.removeChild(lCodeMirror[0]);
|
||||
}
|
||||
|
||||
Util.showPanel();
|
||||
});
|
||||
|
||||
cloudcmd.Editor.Keys = (function(pCurrentFile, pIsReadOnly){
|
||||
"use strict";
|
||||
|
||||
var lThis = this.CodeMirror;
|
||||
/* loading js and css of CodeMirror */
|
||||
this.CodeMirror.show(pCurrentFile, pIsReadOnly);
|
||||
lThis.show(pCurrentFile, pIsReadOnly);
|
||||
|
||||
var key_event = function(pEvent){
|
||||
|
||||
|
|
@ -201,7 +198,8 @@ var CloudCommander, CloudFunc, CodeMirror;
|
|||
/* if f4 or f3 pressed */
|
||||
var lF3 = cloudcmd.KEY.F3;
|
||||
var lF4 = cloudcmd.KEY.F4;
|
||||
var lShow = lThis.show.bind(lThis);
|
||||
//var lShow = lThis.show.bind(lThis);
|
||||
var lShow = Util.bind(lThis.show, lThis);
|
||||
|
||||
var lCurrentFile = Util.getCurrentFile();
|
||||
|
||||
|
|
@ -233,5 +231,5 @@ var CloudCommander, CloudFunc, CodeMirror;
|
|||
}
|
||||
});
|
||||
|
||||
cloudcmd.Editor.CodeMirror = CloudMirror;
|
||||
cloudcmd.Editor.CodeMirror = CodeMirrorEditor;
|
||||
})();
|
||||
Loading…
Add table
Add a link
Reference in a new issue