refactored

This commit is contained in:
coderaiser 2013-01-16 10:36:44 -05:00
parent 7c5b85c1d4
commit dd2e067122
4 changed files with 121 additions and 92 deletions

View file

@ -145,8 +145,8 @@
Util.log('current dir: ' + DIR);
process.chdir(lServerDir);
}
Util.log('server dir: ' + lServerDir + '\n' +
'reading configuretion file config.json...');
Util.log('server dir: ' + lServerDir);
Util.log('reading configuretion file config.json...');
if(Config){
Util.log('config.json readed');

View file

@ -6,6 +6,8 @@
var Util, DOM, CloudFunc, $, KeyBinding, CloudCommander = (function(){
"use strict";
var Config, Modules;
/* Клиентский обьект, содержащий функциональную часть*/
var CloudCmd = {
/* Конструктор CloudClient, который выполняет
@ -15,7 +17,6 @@ var CloudCmd = {
KeyBinding : null, /* обьект обработки нажатий клавишь */
KeysPanel : null, /* panel with key buttons f1-f8 */
Config : null, /* function loads and shows config */
Editor : null, /* function loads and shows editor */
Storage : null, /* function loads storage */
Viewer : null, /* function loads and shows viewer */
@ -56,45 +57,6 @@ var CloudCmd = {
return lLocation.protocol + '//' + lLocation.host;
})()
};
/**
* function load modules
* @pParams = {name, path, func, dobefore, arg}
*/
var loadModule = function(pParams){
if(!pParams) return;
var lName = pParams.name,
lPath = pParams.path,
lFunc = pParams.func,
lDoBefore = pParams.dobefore;
if( Util.isString(pParams) )
lPath = pParams;
if(lPath && !lName){
lName = lPath[0].toUpperCase() + lPath.substring(1);
lName = Util.removeStr(lName, '.js');
var lSlash = lName.indexOf('/');
if(lSlash > 0){
var lAfterSlash = lName.substr(lSlash);
lName = Util.removeStr(lName, lAfterSlash);
}
}
if( !Util.isContainStr(lPath, '.js') )
lPath += '.js';
if(!CloudCmd[lName])
CloudCmd[lName] = function(pArg){
Util.exec(lDoBefore);
return DOM.jsload(CloudCmd.LIBDIRCLIENT + lPath, lFunc ||
function(){
Util.exec(CloudCmd[lName].init, pArg);
});
};
};
CloudCmd.GoogleAnalytics = function(){
/* google analytics */
@ -203,6 +165,45 @@ CloudCmd._currentToParent = function(pDirName){
}
};
/**
* function load modules
* @pParams = {name, path, func, dobefore, arg}
*/
function loadModule(pParams){
if(!pParams) return;
var lName = pParams.name,
lPath = pParams.path,
lFunc = pParams.func,
lDoBefore = pParams.dobefore;
if( Util.isString(pParams) )
lPath = pParams;
if(lPath && !lName){
lName = lPath[0].toUpperCase() + lPath.substring(1);
lName = Util.removeStr(lName, '.js');
var lSlash = lName.indexOf('/');
if(lSlash > 0){
var lAfterSlash = lName.substr(lSlash);
lName = Util.removeStr(lName, lAfterSlash);
}
}
if( !Util.isContainStr(lPath, '.js') )
lPath += '.js';
if(!CloudCmd[lName])
CloudCmd[lName] = function(pArg){
Util.exec(lDoBefore);
return DOM.jsload(CloudCmd.LIBDIRCLIENT + lPath, lFunc ||
function(){
Util.exec(CloudCmd[lName].init, pArg);
});
};
}
/** Конструктор CloudClient, который
* выполняет весь функционал по
* инициализации
@ -238,47 +239,44 @@ function initModules(pCallBack){
KeyBinding.init();
}
});
CloudCmd.getModules(function(pModules){
var lStorage = 'storage/',
lShowLoadFunc = Util.retFunc( DOM.Images.showLoad ),
lDisableMenuFunc = function(){
var lFunc = document.oncontextmenu;
document.oncontextmenu = function(){
Util.exec(lFunc);
return CloudCmd.Menu.ENABLED || false;
};
},
lDoBefore = {
'editor/_codemirror' : lShowLoadFunc,
'menu' : lDisableMenuFunc,
'viewer' : lShowLoadFunc
},
lNames = {};
lNames[lStorage + '_dropbox'] = 'DropBox',
lNames[lStorage + '_github' ] = 'GitHub',
lNames[lStorage + '_gdrive' ] = 'GDrive',
lNames[lStorage + '_vk' ] = 'VK',
DOM.ajax({
url:'/modules.json',
success: function(pModules){
var lStorage = 'storage/',
lShowLoadFunc = Util.retFunc( DOM.Images.showLoad ),
lDisableMenuFunc = function(){
var lFunc = document.oncontextmenu;
document.oncontextmenu = function(){
Util.exec(lFunc);
return CloudCmd.Menu.ENABLED || false;
};
},
lDisableMenuFunc();
if( Util.isArray(pModules) )
for(var i = 0, n = pModules.length; i < n ; i++){
var lModule = pModules[i];
lDoBefore = {
'editor/_codemirror' : lShowLoadFunc,
'menu' : lDisableMenuFunc,
'viewer' : lShowLoadFunc
},
lNames = {};
lNames[lStorage + '_dropbox'] = 'DropBox',
lNames[lStorage + '_github' ] = 'GitHub',
lNames[lStorage + '_gdrive' ] = 'GDrive',
lNames[lStorage + '_vk' ] = 'VK',
lDisableMenuFunc();
if( Util.isArray(pModules) )
for(var i = 0, n = pModules.length; i < n ; i++){
var lModule = pModules[i];
loadModule({
path : lModule,
dobefore : lDoBefore[lModule],
name : lNames[lModule]
});
}
Util.exec(pCallBack);
}
loadModule({
path : lModule,
dobefore : lDoBefore[lModule],
name : lNames[lModule]
});
}
Util.exec(pCallBack);
});
}
@ -383,17 +381,24 @@ function baseInit(pCallBack){
}
CloudCmd.getConfig = function(pCallBack){
if(!CloudCmd.Config)
return DOM.ajax({
Util.ifExec(Config, pCallBack, function(pCallBack){
DOM.ajax({
url:'/config.json',
success: function(pConfig){
CloudCmd.Config = pConfig;
Config = pConfig;
Util.exec(pCallBack, pConfig);
}
});
else
Util.exec(pCallBack, CloudCmd.Config);
});
};
CloudCmd.getModules = function(pCallBack){
Util.ifExec(Modules, pCallBack, function(pCallBack){
DOM.ajax({
url:'/modules.json',
success: Util.retExec(pCallBack)
});
});
};

View file

@ -201,9 +201,13 @@ var CloudCommander, Util, DOM, $;
*/
document.onclick = function(pEvent){
/* if clicked on menu item */
var lClassName = pEvent.target.parentElement.className ;
if(lClassName === 'context-menu-item')
return;
var lClassName = pEvent.target.parentElement.className;
switch(lClassName){
case 'context-menu-item':
return;
case 'context-menu-list ':
return;
}
if(pEvent && pEvent.x && pEvent.y){
var lLayer = DOM.getById('context-menu-layer');

View file

@ -60,8 +60,28 @@ var CloudCommander, Util, DOM, VK;
* @param {Function} callback Function to call when the request is complete.
*/
VKStorage.uploadFile = function(pParams, pCallBack) {
var lData = pParams.data,
lName = pParams.name;
/* http://vk.com/developers.php?oid=-1&p=docs.getUploadServer */
VK.Api.call('docs.getUploadServer', {}, function(pResult){
var lURL = pResult.response.upload_url,
lData = pParams.data,
lName = pParams.name;
DOM.ajax({
type : "POST",
url : lURL,
data : {
file: lData,
name: lName
},
dataType: 'application/x-www-form-urlencoded',
success : function(pData){
Util.log(pData);
VK.Api.call('docs.save', {}, Util.log);
},
error : Util.log
});
});
};