mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 18:55:26 +00:00
refactored
This commit is contained in:
parent
217ec74304
commit
686a922c8f
4 changed files with 203 additions and 216 deletions
|
|
@ -930,7 +930,7 @@ CloudClient.init = (function()
|
|||
if(lTitle.length>0)lTitle[0].textContent='Cloud Commander';
|
||||
|
||||
/* загружаем jquery: */
|
||||
Util.jsload('//code.jquery.com/jquery-1.8.0.min.js',{
|
||||
Util.jsload('//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js',{
|
||||
onload: function(){
|
||||
$ = window.jQuery;
|
||||
},
|
||||
|
|
|
|||
|
|
@ -2,46 +2,48 @@ var CloudCommander, CloudFunc, CodeMirror;
|
|||
/* object contains editors CodeMirror
|
||||
* and later will be Ace
|
||||
*/
|
||||
CloudCommander.Editor = {
|
||||
get : (function(){
|
||||
return this.CodeMirror;
|
||||
})
|
||||
};
|
||||
CloudCommander.Editor.CodeMirror = new CloudCommander.Utils();
|
||||
|
||||
/* indicator says CodeMirror still loads */
|
||||
CloudCommander.Editor.CodeMirror.loading = false;
|
||||
|
||||
/* function loads CodeMirror js and css files */
|
||||
CloudCommander.Editor.CodeMirror.load = (function(pThis){
|
||||
/* function shows editor */
|
||||
var createEditorDiv = function(){
|
||||
if (!pThis.getById('CloudEditor')) {
|
||||
var lFM = pThis.getById('fm');
|
||||
if(lFM)
|
||||
pThis.anyload({
|
||||
name : 'div',
|
||||
id : 'CloudEditor',
|
||||
parent : lFM
|
||||
});
|
||||
else
|
||||
console.log('Error. Something went wrong FM not found');
|
||||
|
||||
pThis.show(pThis);
|
||||
}
|
||||
(function(){
|
||||
var Util = CloudCommander.Util;
|
||||
|
||||
CloudCommander.Editor = {
|
||||
get : (function(){
|
||||
return this.CodeMirror;
|
||||
})
|
||||
};
|
||||
/* function loads css files
|
||||
* of CodeMirror
|
||||
*/
|
||||
var loadAll = function(pParent) {
|
||||
return function(){
|
||||
pParent.cssLoad([
|
||||
CloudCommander.Editor.CodeMirror = new CloudCommander.Utils();
|
||||
|
||||
/* indicator says CodeMirror still loads */
|
||||
CloudCommander.Editor.CodeMirror.loading = false;
|
||||
|
||||
/* function loads CodeMirror js and css files */
|
||||
CloudCommander.Editor.CodeMirror.load = (function(pThis){
|
||||
/* function shows editor */
|
||||
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');
|
||||
|
||||
pThis.show(pThis);
|
||||
}
|
||||
};
|
||||
/* function loads css files
|
||||
* of CodeMirror
|
||||
*/
|
||||
var loadAll = function() {
|
||||
Util.cssLoad([
|
||||
{ src : 'lib/client/editor/codemirror/pack/codemirror.pack.css'},
|
||||
{ src : 'lib/client/editor/codemirror/pack/night.pack.css'}
|
||||
]);
|
||||
|
||||
|
||||
pParent.cssSet({id:'editor',
|
||||
Util.cssSet({id:'editor',
|
||||
inner : '.CodeMirror{' +
|
||||
'font-family :\'Droid Sans Mono\';' +
|
||||
'font-size :15px;' +
|
||||
|
|
@ -52,173 +54,172 @@ CloudCommander.Editor.CodeMirror.load = (function(pThis){
|
|||
'}'
|
||||
});
|
||||
|
||||
pParent.jsload('lib/client/editor/' +
|
||||
Util.jsload('lib/client/editor/' +
|
||||
'codemirror/pack/javascript.pack.js',
|
||||
createEditorDiv);
|
||||
};
|
||||
};
|
||||
|
||||
/* load CodeMirror main module */
|
||||
pThis.jsload('lib/client/editor/' +
|
||||
'codemirror/pack/codemirror.pack.js',
|
||||
loadAll(this));
|
||||
});
|
||||
|
||||
/* function shows CodeMirror editor */
|
||||
CloudCommander.Editor.CodeMirror.show = (function(pIsReadOnly){
|
||||
/* if CloudEditor is not loaded - loading him */
|
||||
if(!this.getById('CloudEditor'))
|
||||
return this.load(this);
|
||||
|
||||
/* 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){
|
||||
CodeMirror(lCloudEditor,{
|
||||
mode : 'javascript',
|
||||
value : pValue,
|
||||
theme : 'night',
|
||||
lineNumbers : true,
|
||||
//переносим длинные строки
|
||||
lineWrapping: false,
|
||||
autofocus : true,
|
||||
extraKeys: {
|
||||
//Сохранение
|
||||
"Esc": lThis.hide(lThis)
|
||||
},
|
||||
readOnly : lReadOnly
|
||||
});
|
||||
};
|
||||
|
||||
var lCloudEditor = this.getById('CloudEditor');
|
||||
|
||||
var lCurrent = this.getCurrentFile();
|
||||
var lA;
|
||||
|
||||
/* getting link */
|
||||
lA = this.getByTag('a', lCurrent);
|
||||
|
||||
lA = lA[0].href;
|
||||
|
||||
/* убираем адрес хоста*/
|
||||
lA = '/' + lA.replace(document.location.href,'');
|
||||
|
||||
/* checking is this link is to directory */
|
||||
var lSize = this.getByClass('size', lCurrent);
|
||||
if(lSize){
|
||||
lSize = lSize[0].textContent;
|
||||
|
||||
/* if directory - load json
|
||||
* not html data
|
||||
*/
|
||||
if (lSize === '<dir>'){
|
||||
if (lA.indexOf(CloudFunc.NOJS) ===
|
||||
CloudFunc.FS.length) {
|
||||
lA = lA.replace(CloudFunc.NOJS, '');
|
||||
lReadOnly = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.loading = true;
|
||||
setTimeout(function(){
|
||||
lThis.loading = false;},
|
||||
400);
|
||||
|
||||
/* reading data from current file */
|
||||
$.ajax({
|
||||
url:lA,
|
||||
error: (function(jqXHR, textStatus, errorThrown){
|
||||
lThis.loading = false;
|
||||
|
||||
return lThis.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);
|
||||
|
||||
/* removing keyBinding if set */
|
||||
CloudCommander.keyBinded = false;
|
||||
|
||||
lThis.hidePanel();
|
||||
lThis.Images.hideLoad();
|
||||
|
||||
lThis.loading = false;
|
||||
}
|
||||
Util.jsload('lib/client/editor/' +
|
||||
'codemirror/pack/codemirror.pack.js', loadAll);
|
||||
});
|
||||
});
|
||||
|
||||
/* function hides CodeMirror editor */
|
||||
CloudCommander.Editor.CodeMirror.hide = (function(pParent) {
|
||||
return function(){
|
||||
CloudCommander.keyBinded = true;
|
||||
pParent.showPanel();
|
||||
|
||||
var lCloudEditor = pParent.getById('CloudEditor');
|
||||
var lCodeMirror = pParent.getByClass('CodeMirror');
|
||||
/* function shows CodeMirror editor */
|
||||
CloudCommander.Editor.CodeMirror.show = (function(pIsReadOnly){
|
||||
/* if CloudEditor is not loaded - loading him */
|
||||
if(!Util.getById('CloudEditor'))
|
||||
return this.load(this);
|
||||
|
||||
if(lCodeMirror.length)
|
||||
lCloudEditor
|
||||
.removeChild(lCodeMirror[0]);
|
||||
};
|
||||
});
|
||||
|
||||
CloudCommander.Editor.Keys = (function(pIsReadOnly){
|
||||
"use strict";
|
||||
|
||||
var lThis = this.CodeMirror;
|
||||
/* loading js and css of CodeMirror */
|
||||
this.CodeMirror.show(lThis, 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){
|
||||
CodeMirror(lCloudEditor,{
|
||||
mode : 'javascript',
|
||||
value : pValue,
|
||||
theme : 'night',
|
||||
lineNumbers : true,
|
||||
//переносим длинные строки
|
||||
lineWrapping: false,
|
||||
autofocus : true,
|
||||
extraKeys: {
|
||||
//Сохранение
|
||||
"Esc": lThis.hide(lThis)
|
||||
},
|
||||
readOnly : lReadOnly
|
||||
});
|
||||
};
|
||||
|
||||
var lCloudEditor = Util.getById('CloudEditor');
|
||||
|
||||
var lCurrent = Util.getCurrentFile();
|
||||
var lA;
|
||||
|
||||
var key_event = function(pEvent){
|
||||
|
||||
/* если клавиши можно обрабатывать */
|
||||
if(CloudCommander.keyBinded){
|
||||
/* if f4 or f3 pressed */
|
||||
var lF3 = CloudCommander.KEY.F3;
|
||||
var lF4 = CloudCommander.KEY.F4;
|
||||
var lShow = lThis.show.bind(lThis);
|
||||
/* getting link */
|
||||
lA = Util.getByTag('a', lCurrent);
|
||||
|
||||
lA = lA[0].href;
|
||||
|
||||
/* убираем адрес хоста*/
|
||||
lA = '/' + lA.replace(document.location.href,'');
|
||||
|
||||
/* checking is this link is to directory */
|
||||
var lSize = Util.getByClass('size', lCurrent);
|
||||
if(lSize){
|
||||
lSize = lSize[0].textContent;
|
||||
|
||||
if(!pEvent.shiftKey){
|
||||
if(pEvent.keyCode === lF4)
|
||||
lShow();
|
||||
else if(pEvent.keyCode === lF3){
|
||||
lShow(true);
|
||||
/* if directory - load json
|
||||
* not html data
|
||||
*/
|
||||
if (lSize === '<dir>'){
|
||||
if (lA.indexOf(CloudFunc.NOJS) ===
|
||||
CloudFunc.FS.length) {
|
||||
lA = lA.replace(CloudFunc.NOJS, '');
|
||||
lReadOnly = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/* добавляем обработчик клавишь */
|
||||
if (document.addEventListener)
|
||||
document.addEventListener('keydown', key_event,false);
|
||||
|
||||
else{
|
||||
var lFunc;
|
||||
if(typeof document.onkeydown === 'function')
|
||||
lFunc = document.onkeydown;
|
||||
|
||||
document.onkeydown = function(){
|
||||
if(lFunc)
|
||||
lFunc();
|
||||
|
||||
key_event();
|
||||
this.loading = true;
|
||||
setTimeout(function(){
|
||||
lThis.loading = false;},
|
||||
400);
|
||||
|
||||
/* reading data from current file */
|
||||
$.ajax({
|
||||
url:lA,
|
||||
error: (function(jqXHR, textStatus, errorThrown){
|
||||
lThis.loading = false;
|
||||
|
||||
return lThis.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);
|
||||
|
||||
/* removing keyBinding if set */
|
||||
CloudCommander.keyBinded = false;
|
||||
|
||||
Util.hidePanel();
|
||||
Util.Images.hideLoad();
|
||||
|
||||
lThis.loading = false;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
/* function hides CodeMirror editor */
|
||||
CloudCommander.Editor.CodeMirror.hide = (function() {
|
||||
return function(){
|
||||
CloudCommander.keyBinded = true;
|
||||
Util.showPanel();
|
||||
|
||||
var lCloudEditor = Util.getById('CloudEditor');
|
||||
var lCodeMirror = Util.getByClass('CodeMirror');
|
||||
|
||||
if(lCodeMirror.length)
|
||||
lCloudEditor
|
||||
.removeChild(lCodeMirror[0]);
|
||||
};
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
CloudCommander.Editor.Keys = (function(pIsReadOnly){
|
||||
"use strict";
|
||||
|
||||
var lThis = this.CodeMirror;
|
||||
/* loading js and css of CodeMirror */
|
||||
this.CodeMirror.show(pIsReadOnly);
|
||||
|
||||
var key_event = function(pEvent){
|
||||
|
||||
/* если клавиши можно обрабатывать */
|
||||
if(CloudCommander.keyBinded){
|
||||
/* if f4 or f3 pressed */
|
||||
var lF3 = CloudCommander.KEY.F3;
|
||||
var lF4 = CloudCommander.KEY.F4;
|
||||
var lShow = lThis.show.bind(lThis);
|
||||
|
||||
if(!pEvent.shiftKey){
|
||||
if(pEvent.keyCode === lF4)
|
||||
lShow();
|
||||
else if(pEvent.keyCode === lF3){
|
||||
lShow(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/* добавляем обработчик клавишь */
|
||||
if (document.addEventListener)
|
||||
document.addEventListener('keydown', key_event,false);
|
||||
|
||||
else{
|
||||
var lFunc;
|
||||
if(typeof document.onkeydown === 'function')
|
||||
lFunc = document.onkeydown;
|
||||
|
||||
document.onkeydown = function(){
|
||||
if(lFunc)
|
||||
lFunc();
|
||||
|
||||
key_event();
|
||||
};
|
||||
}
|
||||
});
|
||||
})();
|
||||
|
|
@ -40,7 +40,8 @@ CloudCommander.keyBinding = (function(){
|
|||
var lKEY = CloudCommander.KEY;
|
||||
|
||||
var key_event = function(event){
|
||||
var lCurrentFile,
|
||||
/* получаем выдленный файл*/
|
||||
var lCurrentFile = Util.getCurrentFile(),
|
||||
lName, i;
|
||||
/* если клавиши можно обрабатывать*/
|
||||
if(CloudCommander.keyBinded && event){
|
||||
|
|
@ -53,9 +54,7 @@ CloudCommander.keyBinding = (function(){
|
|||
if(event.keyCode === lKEY.TAB){
|
||||
console.log('Tab pressed');
|
||||
|
||||
try{
|
||||
lCurrentFile = Util.getCurrentFile();
|
||||
|
||||
try{
|
||||
/* changing parent panel of curent-file */
|
||||
var lPanel = Util.getPanel();
|
||||
var lId = lPanel.id;
|
||||
|
|
@ -122,10 +121,7 @@ CloudCommander.keyBinding = (function(){
|
|||
}
|
||||
/* навигация по таблице файлов*/
|
||||
/* если нажали клавишу вверх*/
|
||||
else if(event.keyCode === lKEY.UP){
|
||||
/* получаем выдленный файл*/
|
||||
lCurrentFile = Util.getCurrentFile();
|
||||
|
||||
else if(event.keyCode === lKEY.UP){
|
||||
/* если ненайдены выделенные файлы - выходим*/
|
||||
if(!lCurrentFile) return;
|
||||
|
||||
|
|
@ -148,10 +144,7 @@ CloudCommander.keyBinding = (function(){
|
|||
}
|
||||
|
||||
/* если нажали клавишу в низ*/
|
||||
else if(event.keyCode === lKEY.DOWN){
|
||||
/* получаем выдленный файл*/
|
||||
lCurrentFile = Util.getCurrentFile();
|
||||
|
||||
else if(event.keyCode === lKEY.DOWN){
|
||||
/* если ненайдены выделенные файлы - выходим*/
|
||||
if(!lCurrentFile)return;
|
||||
|
||||
|
|
@ -172,7 +165,6 @@ CloudCommander.keyBinding = (function(){
|
|||
* элементу
|
||||
*/
|
||||
else if(event.keyCode === lKEY.HOME){
|
||||
lCurrentFile = Util.getCurrentFile();
|
||||
/* получаем первый элемент
|
||||
* пропускаем путь и заголовки столбиков
|
||||
* выделяем верхий файл
|
||||
|
|
@ -190,7 +182,6 @@ CloudCommander.keyBinding = (function(){
|
|||
* выделяем последний элемент
|
||||
*/
|
||||
else if( event.keyCode === lKEY.END){
|
||||
lCurrentFile = Util.getCurrentFile();
|
||||
/* выделяем самый нижний файл */
|
||||
Util.setCurrentFile(lCurrentFile
|
||||
.parentElement.lastElementChild);
|
||||
|
|
@ -207,7 +198,6 @@ CloudCommander.keyBinding = (function(){
|
|||
else if(event.keyCode === lKEY.PAGE_DOWN){
|
||||
Util.getPanel().scrollByPages(1);
|
||||
|
||||
lCurrentFile = Util.getCurrentFile();
|
||||
for(i=0; i<30; i++){
|
||||
if(!lCurrentFile.nextSibling) break;
|
||||
|
||||
|
|
@ -224,7 +214,6 @@ CloudCommander.keyBinding = (function(){
|
|||
else if(event.keyCode === lKEY.PAGE_UP){
|
||||
Util.getPanel().scrollByPages(-1);
|
||||
|
||||
lCurrentFile = Util.getCurrentFile();
|
||||
for(i=0; i<30; i++){
|
||||
if(!lCurrentFile.previousSibling) break;
|
||||
else try{
|
||||
|
|
@ -246,7 +235,6 @@ CloudCommander.keyBinding = (function(){
|
|||
|
||||
/* если нажали Enter - открываем папку*/
|
||||
else if(event.keyCode === lKEY.ENTER){
|
||||
lCurrentFile = Util.getCurrentFile();
|
||||
/* если ненайдены выделенные файлы - выходим*/
|
||||
if(!lCurrentFile)return;
|
||||
|
||||
|
|
@ -291,10 +279,7 @@ CloudCommander.keyBinding = (function(){
|
|||
* содержимого каталога
|
||||
*/
|
||||
var lRefreshIcon = Util.getRefreshButton();
|
||||
if(lRefreshIcon){
|
||||
/* находим файл который сейчас выделен */
|
||||
lCurrentFile = Util.getCurrentFile();
|
||||
|
||||
if(lRefreshIcon){
|
||||
/* получаем название файла*/
|
||||
var lSelectedName = Util
|
||||
.getByTag('a', lCurrentFile)[0].textContent;
|
||||
|
|
|
|||
|
|
@ -5,8 +5,9 @@ var CloudCommander, $;
|
|||
/* object contains jQuery-contextMenu
|
||||
* https://github.com/medialize/jQuery-contextMenu
|
||||
*/
|
||||
CloudCommander.Menu = new CloudCommander.Utils();
|
||||
var Util = CloudCommander.Util;
|
||||
CloudCommander.Menu = {};
|
||||
|
||||
var Util = CloudCommander.Util;
|
||||
|
||||
CloudCommander.Menu.dir = './lib/client/menu/';
|
||||
|
||||
|
|
@ -138,8 +139,8 @@ var CloudCommander, $;
|
|||
*/
|
||||
document.onclick = function(pEvent){
|
||||
if(pEvent && pEvent.x && pEvent.y){
|
||||
if(lLayer){
|
||||
var lLayer = Util.getById('context-menu-layer');
|
||||
var lLayer = Util.getById('context-menu-layer');
|
||||
if(lLayer){
|
||||
var lStyle;
|
||||
|
||||
if(lLayer)
|
||||
|
|
@ -191,7 +192,7 @@ var CloudCommander, $;
|
|||
return function(){
|
||||
pThis.set();
|
||||
|
||||
pThis.Images.hideLoad();
|
||||
Util.Images.hideLoad();
|
||||
|
||||
if(pPosition && pPosition.x && pPosition.y)
|
||||
$('li').contextMenu(pPosition);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue