added ability to download files

This commit is contained in:
coderaiser 2012-08-17 10:30:13 -04:00
parent f3f3d380ae
commit a87309a447
7 changed files with 860 additions and 803 deletions

View file

@ -48,6 +48,8 @@ current, file that was previously current must be unset automatically.
* Moved error message a little bit lower.
* Added ability to download files.
2012.08.06, Version 0.1.5

View file

@ -680,12 +680,12 @@ CloudClient.keyBinding=(function(){
});
/* function loads and shows editor */
CloudClient.Editor = (function() {
CloudClient.Editor = (function(pIsReadOnly) {
/* loading CloudMirror plagin */
Util.jsload(CloudClient.LIBDIRCLIENT +
'editor.js',{
onload:(function(){
CloudCommander.Editor.Keys();
CloudCommander.Editor.Keys(pIsReadOnly);
})
});
});

View file

@ -13,13 +13,13 @@ CloudCommander.Editor.CodeMirror = new CloudCommander.Util();
CloudCommander.Editor.CodeMirror.loading = false;
/* function loads CodeMirror js and css files */
CloudCommander.Editor.CodeMirror.load = (function(pParent){
CloudCommander.Editor.CodeMirror.load = (function(pThis){
/* function shows editor */
var createEditorDiv = function(){
if (!pParent.getById('CloudEditor')) {
var lFM = pParent.getById('fm');
if (!pThis.getById('CloudEditor')) {
var lFM = pThis.getById('fm');
if(lFM)
pParent.anyload({
pThis.anyload({
name : 'div',
id : 'CloudEditor',
parent : lFM
@ -27,7 +27,7 @@ CloudCommander.Editor.CodeMirror.load = (function(pParent){
else
console.log('Error. Something went wrong FM not found');
pParent.show();
pThis.show(pThis);
}
};
/* function loads css files
@ -59,31 +59,30 @@ CloudCommander.Editor.CodeMirror.load = (function(pParent){
};
/* load CodeMirror main module */
pParent.jsload('lib/client/editor/' +
pThis.jsload('lib/client/editor/' +
'codemirror/pack/codemirror.pack.js',
loadAll(this));
});
/* function shows CodeMirror editor */
CloudCommander.Editor.CodeMirror.show = (function(){
CloudCommander.Editor.CodeMirror.show = (function(pThis, pIsReadOnly){
/* if CloudEditor is not loaded - loading him */
if(!this.getById('CloudEditor'))
return this.load(this);
if(!pThis.getById('CloudEditor'))
return pThis.load(pThis);
/* if CodeMirror function show already
* called do not call it again
* if f4 key pressed couple times
*/
if(this.loading)
if(pThis.loading)
return;
/* when folder view
* is no need to edit
* data
*/
var lReadOnly = false;
var lReadOnly = pIsReadOnly || false;
var lThis = this;
var initCodeMirror_f = function(pValue){
CodeMirror(lCloudEditor,{
mode : 'javascript',
@ -92,22 +91,22 @@ CloudCommander.Editor.CodeMirror.show = (function(){
lineNumbers : true,
//переносим длинные строки
lineWrapping: false,
autofocus : true,
autofocus : true,
extraKeys: {
//Сохранение
"Esc": lThis.hide(lThis)
"Esc": pThis.hide(pThis)
},
readOnly : lReadOnly
});
};
var lCloudEditor = this.getById('CloudEditor');
var lCloudEditor = pThis.getById('CloudEditor');
var lCurrent = this.getCurrentFile();
var lCurrent = pThis.getCurrentFile();
var lA;
/* getting link */
lA = this.getByTag('a', lCurrent);
lA = pThis.getByTag('a', lCurrent);
lA = lA[0].href;
@ -115,7 +114,7 @@ CloudCommander.Editor.CodeMirror.show = (function(){
lA = '/' + lA.replace(document.location.href,'');
/* checking is this link is to directory */
var lSize = this.getByClass('size', lCurrent);
var lSize = pThis.getByClass('size', lCurrent);
if(lSize){
lSize = lSize[0].textContent;
@ -124,8 +123,7 @@ CloudCommander.Editor.CodeMirror.show = (function(){
*/
if (lSize === '<dir>'){
if (lA.indexOf(CloudFunc.NOJS) ===
CloudFunc.FS.length) {
CloudFunc.FS.length) {
lA = lA.replace(CloudFunc.NOJS, '');
lReadOnly = true;
}
@ -134,15 +132,16 @@ CloudCommander.Editor.CodeMirror.show = (function(){
this.loading = true;
setTimeout(function(){
lThis.loading = false;},
pThis.loading = false;},
400);
/* reading data from current file */
$.ajax({
url:lA,
error: (function(jqXHR, textStatus, errorThrown){
lThis.loading = false;
return lThis.Images.showError(jqXHR, textStatus, errorThrown);
pThis.loading = false;
return pThis.Images.showError(jqXHR);
}),
success:function(data, textStatus, jqXHR){
@ -155,10 +154,10 @@ CloudCommander.Editor.CodeMirror.show = (function(){
/* removing keyBinding if set */
CloudCommander.keyBinded = false;
lThis.hidePanel();
lThis.Images.hideLoad();
pThis.hidePanel();
pThis.Images.hideLoad();
lThis.loading = false;
pThis.loading = false;
}
});
});
@ -178,19 +177,28 @@ CloudCommander.Editor.CodeMirror.hide = (function(pParent) {
};
});
CloudCommander.Editor.Keys = (function(){
CloudCommander.Editor.Keys = (function(pIsReadOnly){
"use strict";
var lThis = this.CodeMirror;
/* loading js and css of CodeMirror */
this.CodeMirror.show(this.CodeMirror);
this.CodeMirror.show(lThis, pIsReadOnly);
var key_event = function(event){
var key_event = function(pEvent){
/* если клавиши можно обрабатывать */
if(CloudCommander.keyBinded){
/* if f4 pressed */
if(event.keyCode === CloudCommander.KEY.F4){
CloudCommander.Editor.CodeMirror.show();
/* if f4 or f3 pressed */
var lF3 = CloudCommander.KEY.F3;
var lF4 = CloudCommander.KEY.F4;
var lShow = CloudCommander.Editor.CodeMirror.show;
if(!pEvent.shiftKey){
if(pEvent.keyCode === lF4)
lShow(lThis);
else if(pEvent.keyCode === lF3){
lShow(lThis, true);
}
}
}
};

View file

@ -82,7 +82,16 @@ CloudCommander.keyBinding = (function(){
}
/* if f3 pressed */
else if(event.keyCode === lKEY.F3){
else if(event.keyCode === lKEY.F3 && !event.shiftKey){
if (typeof CloudCommander.Editor === 'function')
CloudCommander.Editor(true);
event.preventDefault();//запрет на дальнейшее действие
}
/* if <shift> + f3 pressed */
else if(event.keyCode === lKEY.F3 &&
event.shiftKey){
if (typeof CloudCommander.Viewer === 'function')
CloudCommander.Viewer();

View file

@ -44,6 +44,14 @@ CloudCommander.Menu.getConfig = (function(){
'delete': {name: 'Delete',
callback: function(key, opt){
console.log('delete menu item choosen');
}},
download: {name: 'Download',callback: function(key, opt){
var lCurrent = lThis.getCurrentFile();
var lLink = lThis.getByTag('a', lCurrent)[0];
console.log('downloadin file...');
}}
}
};

View file

@ -94,9 +94,17 @@ CloudCommander.Viewer.FancyBox.loadData = (function(pA){
var lConfig = this.getConfig();
this.Images.showLoad();
var lLink = pA.href;
/* убираем адрес хоста*/
lLink = '/' + lLink.replace(document.location.href,'');
if (lLink.indexOf(CloudFunc.NOJS) === CloudFunc.FS.length)
lLink = lLink.replace(CloudFunc.NOJS, '');
$.ajax({
url : pA.href,
url : lLink,
error : (function(jqXHR, textStatus, errorThrown){
lThis.loading = false;
return lThis.Images.showError(jqXHR, textStatus, errorThrown);
@ -179,7 +187,8 @@ CloudCommander.Viewer.Keys = (function(){
/* если клавиши можно обрабатывать */
if(CloudCommander.keyBinded)
/* if f3 pressed */
if(pEvent.keyCode === CloudCommander.KEY.F3){
if(pEvent.keyCode === CloudCommander.KEY.F3 &&
pEvent.shiftKey){
CloudCommander.Viewer.FancyBox.show();
pEvent.preventDefault();

1553
server.js

File diff suppressed because it is too large Load diff