mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-19 09:24:51 +00:00
minor changes
This commit is contained in:
parent
c4c99016ab
commit
999962f5ee
2 changed files with 51 additions and 56 deletions
|
|
@ -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 === '<dir>'){
|
||||
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){
|
||||
|
||||
|
|
|
|||
|
|
@ -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();//запрет на дальнейшее действие
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue