util object moved from client.js to modules dom.js and util.js

This commit is contained in:
coderaiser 2012-11-07 03:51:27 -05:00
parent 9c6c79c9f7
commit 4019922dc2
7 changed files with 65 additions and 905 deletions

View file

@ -72,6 +72,9 @@ listing in json from menu.
* Changed default port to 80.
* Util object moved from client.js to modules
dom.js and util.js.
2012.10.01, Version 0.1.7

838
client.js
View file

@ -176,844 +176,6 @@ CloudClient.Cache.clear = function(){
}
};
/* Object contain additional system functional */
CloudClient.Util = (function(){
/* private members */
var lXMLHTTP,
lLoadingImage,
lErrorImage,
lCURRENT_FILE = cloudcmd.CURRENT_FILE,
/* Обьект, который содержит
* функции для отображения
* картинок
*/
LImages_o = {
/* Функция создаёт картинку загрузки*/
loading : function(){
var lE = DOM.getById('loading-image');
if (!lE)
lE = DOM.anyload({
name : 'span',
className : 'icon loading',
id : 'loading-image',
not_append : true
});
lLoadingImage = lE;
return lE;
},
/* Функция создаёт картинку ошибки загрузки*/
error : function(){
var lE = Util.getById('error-image');
if (!lE)
lE = Util.anyload({
name : 'span',
className : 'icon error',
id : 'error-image',
not_append : true
});
return lE;
}
};
this.addClass = function(pElement, pClass){
var lRet_b = true;
var lClassList = pElement.classList;
if(lClassList){
if( !lClassList.contains(pClass) )
lClassList.add(pClass);
else
lRet_b = false;
}
return lRet_b;
};
/* Load file countent thrue ajax */
this.ajax = function(pParams){
/* if on webkit */
if(window.XMLHttpRequest){
if(!lXMLHTTP)
lXMLHTTP = new XMLHttpRequest();
var lMethod = 'GET';
if(pParams.method)
lMethod = pParams.method;
lXMLHTTP.open(lMethod, pParams.url, true);
lXMLHTTP.send(null);
var lSuccess_f = pParams.success;
if(typeof lSuccess_f !== 'function')
console.log('error in Util.ajax onSuccess:', pParams);
lXMLHTTP.onreadystatechange = function(pEvent){
if (lXMLHTTP.readyState === 4 /* Complete */){
var lJqXHR = pEvent.target;
var lContentType = lXMLHTTP.getResponseHeader('content-type');
if (lXMLHTTP.status === 200 /* OK */){
var lData = lJqXHR.response;
/* If it's json - parse it as json */
if(lContentType &&
lContentType.indexOf('application/json') === 0){
try{
lData = JSON.parse(lJqXHR.response);
}
catch(pError) {
/* if could not parse */
console.log('Error: could not parse' +
'json from server from url: ' +
pParams.url);
lData = lJqXHR.response;
}
}
lSuccess_f(lData, lJqXHR.statusText, lJqXHR);
}
else/* file not found or connection lost */{
var lError_f = pParams.error;
/* if html given or something like it
* getBack just status of result
*/
if(lContentType &&
lContentType.indexOf('text/plain') !== 0){
lJqXHR.responseText = lJqXHR.statusText;
}
if(typeof lError_f === 'function')
lError_f(lJqXHR);
}
}
};
}
else $.ajax(pParams);
};
/* setting function context (this) */
this.bind = function(pFunction, pContext){
return pFunction.bind(pContext);
};
/*
* Function gets id by src
* from http://domain.com/1.js to
* 1_js
*/
this.getIdBySrc = function(pSrc){
var lID = pSrc.replace(pSrc.substr(pSrc,
pSrc.lastIndexOf('/')+1),
'');
/* убираем точки */
while(lID.indexOf('.') > 0)
lID = lID.replace('.','_');
return lID;
},
this.loadOnload = function(pFunc_a){
if( Util.isArray(pFunc_a) ) {
var lFunc_f = pFunc_a.pop();
if(typeof lFunc_f === 'function')
lFunc_f();
return this.loadOnload(pFunc_a);
}
else if( Util.isFunction(pFunc_a) )
return pFunc_a();
};
this.anyLoadOnLoad = function(pParams_a, pFunc){
if( Util.isArray(pParams_a) ) {
var lParam = pParams_a.pop();
if(Util.isString(lParam) )
lParam = { src : lParam };
if(lParam && !lParam.func){
lParam.func = function(){
Util.anyLoadOnLoad(pParams_a, pFunc);
};
this.anyload(lParam);
}else if( Util.isFunction(pFunc) )
pFunc();
}
};
/**
* Функция создаёт элемент и
* загружает файл с src.
* @pName - название тэга
* @pSrc - путь к файлу
* @pFunc - обьект, содержаий одну из функций
* или сразу две onload и onerror
* {onload: function(){}, onerror: function();}
* @pStyle - стиль
* @pId - id
* @pElement - элемент, дочерним которо будет этот
* @param pParams_o = {name: '', src: ' ',func: '', style: '', id: '', parent: '',
async: false, inner: 'id{color:red, }, class:'', not_append: false}
*/
this.anyload = function(pParams_o){
if( !pParams_o ) return;
/* if a couple of params was
* processing every of params
* and quit
*/
if( Util.isArray(pParams_o) ){
var lElements_a = [];
for(var i = 0, n = pParams_o.length; i < n ; i++)
lElements_a[i] = this.anyload(pParams_o[i]);
return lElements_a;
}
var lName = pParams_o.name,
lID = pParams_o.id,
lClass = pParams_o.className,
lSrc = pParams_o.src,
lFunc = pParams_o.func,
lOnError,
lAsync = pParams_o.async,
lParent = pParams_o.parent,
lInner = pParams_o.inner,
lNotAppend = pParams_o.not_append;
if ( Util.isObject(lFunc) ){
lOnError = lFunc.onerror;
lFunc = lFunc.onload;
}
/* убираем путь к файлу, оставляя только название файла */
if(!lID && lSrc)
lID = this.getIdBySrc(lSrc);
var element = getById(lID);
/* если скрипт еще не загружен */
if(!element){
if(!lName && lSrc){
var lDot = lSrc.lastIndexOf('.'),
lExt = lSrc.substr(lDot);
switch(lExt){
case '.js':
lName = 'script';
break;
case '.css':
lName = 'link';
lParent = document.head;
break;
default:
return {code: -1, text: 'name can not be empty'};
}
}
element = document.createElement(lName);
if(lID)
element.id = lID;
if(lClass)
element.className = lClass;
/* if working with external css
* using href in any other case
* using src
*/
if(lName === 'link'){
element.href = lSrc;
element.rel = 'stylesheet';
}else
element.src = lSrc;
/*
* if passed arguments function
* then it's onload by default
*
* if object - then onload and onerror
*/
if( Util.isFunction(lFunc) )
element.onload = lFunc;
/* if element (js/css) will not loaded
* it would be removed from DOM tree
* and error image would be shown
*/
element.onerror = (function(){
(pParams_o.parent || document.body)
.removeChild(element);
Util.Images.showError({
responseText: 'file ' +
lSrc +
' could not be loaded',
status : 404
});
if( Util.isFunction(lOnError) )
lFunc();
});
if(pParams_o.style){
element.style.cssText = pParams_o.style;
}
if(lAsync || lAsync === undefined)
element.async = true;
if(!lNotAppend)
(lParent || document.body).appendChild(element);
if(lInner){
element.innerHTML = lInner;
}
}
/* если js-файл уже загружен
* запускаем функцию onload
*/
else if( Util.isFunction(lFunc) ) lFunc();
return element;
},
/* Функция загружает js-файл */
this.jsload = function(pSrc, pFunc){
if(pSrc instanceof Array){
for(var i=0; i < pSrc.length; i++)
pSrc[i].name = 'script';
return this.anyload(pSrc);
}
return this.anyload({
name : 'script',
src : pSrc,
func : pFunc
});
},
/* Функция создаёт елемент style и записывает туда стили
* @pParams_o - структура параметров, заполняеться таким
* образом: {src: ' ',func: '', id: '', element: '', inner: ''}
* все параметры опциональны
*/
this.cssSet = function(pParams_o){
pParams_o.name = 'style';
pParams_o.parent = pParams_o.parent || document.head;
return this.anyload(pParams_o);
},
/* Function loads external css files
* @pParams_o - структура параметров, заполняеться таким
* образом: {src: ' ',func: '', id: '', element: '', inner: ''}
* все параметры опциональны
*/
this.cssLoad = function(pParams_o){
if( Util.isArray(pParams_o) ){
for(var i = 0, n = pParams_o.length; i < n; i++){
pParams_o[i].name = 'link';
pParams_o[i].parent = pParams_o.parent || document.head;
}
return this.anyload(pParams_o);
}
else if( Util.isString(pParams_o) )
pParams_o = { src: pParams_o };
pParams_o.name = 'link';
pParams_o.parent = pParams_o.parent || document.head;
return this.anyload(pParams_o);
};
this.jqueryLoad = function(pCallBack){
/* загружаем jquery: */
DOM.jsload('//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js',{
onload: function(){
$ = window.jQuery;
if(typeof pCallBack === 'function')
pCallBack();
},
onerror: function(){
DOM.jsload('lib/client/jquery.js');
/*
* if could not load jquery from google server
* maybe we offline, load font from local
* directory
*/
DOM.cssSet({id:'local-droids-font',
element : document.head,
inner : '@font-face {font-family: "Droid Sans Mono";' +
'font-style: normal;font-weight: normal;' +
'src: local("Droid Sans Mono"), local("DroidSansMono"),'+
' url("font/DroidSansMono.woff") format("woff");}'
});
}
});
};
this.socketLoad = function(){
DOM.jsload('lib/client/socket.js');
};
/* DOM */
/**
* Function search element by tag
* @pTag - className
* @pElement - element
*/
this.getByTag = function(pTag, pElement){
return (pElement || document).getElementsByTagName(pTag);
};
/**
* Function search element by id
* @Id - className
* @pElement - element
*/
this.getById = function(pId, pElement){
return (pElement || document).getElementById(pId);
};
/**
* Function search element by class name
* @pClass - className
* @pElement - element
*/
this.getByClass = function(pClass, pElement){
return (pElement || document).getElementsByClassName(pClass);
};
/* STRINGS */
/**
* function check is strings are equal
* @param pStr1
* @param pStr2
*/
this.strCmp = function (pStr1, pStr2){
return this.isContainStr(pStr1, pStr2) &&
pStr1.length == pStr2.length;
};
/**
* function returns is pStr1 contains pStr2
* @param pStr1
* @param pStr2
*/
this.isContainStr = function(pStr1, pStr2){
return pStr1 &&
pStr2 &&
pStr1.indexOf(pStr2) >= 0;
};
/**
* function remove substring from string
* @param pStr
* @param pSubStr
*/
this.removeStr = function(pStr, pSubStr){
return pStr.replace(pSubStr,'');
};
this.Images = {
/*
* Function shows loading spinner
* @pElem - top element of screen
* pPosition = {top: true};
*/
showLoad : function(pPosition){
var lRet_b = true;
lLoadingImage = LImages_o.loading();
lErrorImage = LImages_o.error();
DOM.hide(lErrorImage);
var lCurrent;
if(pPosition){
if(pPosition.top){
lCurrent = DOM.getRefreshButton();
if(lCurrent)
lCurrent = lCurrent.parentElement;
else
lRet_b = false;
}
}
else
{
lCurrent = DOM.getCurrentFile();
lCurrent = lCurrent.firstChild.nextSibling;
}
/* show loading icon
* if it not showed
* and if error was not
* heppen
*/
if(lRet_b){
var lParent = lLoadingImage.parentElement;
if(!lParent ||
(lParent && lParent !== lCurrent))
lCurrent.appendChild(lLoadingImage);
DOM.show(lLoadingImage); /* показываем загрузку*/
}
return lRet_b;
},
hideLoad : function(){
lLoadingImage = LImages_o.loading();
DOM.hide(lLoadingImage);
},
showError : function(jqXHR, textStatus, errorThrown){
lLoadingImage = LImages_o.loading();
lErrorImage = LImages_o.error();
var lText;
if(jqXHR.status === 404)
lText = jqXHR.responseText;
else
lText = jqXHR.statusText;
/* если файла не существует*/
if(!lText.indexOf('Error: ENOENT, '))
lText = lText.replace('Error: ENOENT, n','N');
/* если не хватает прав для чтения файла*/
else if(!lText.indexOf('Error: EACCES,'))
lText = lText.replace('Error: EACCES, p','P');
DOM.show(lErrorImage);
lErrorImage.title = lText;
var lParent = lLoadingImage.parentElement;
if(lParent)
lParent.appendChild(lErrorImage);
DOM.hide(lLoadingImage);
console.log(lText);
}
};
this.getCurrentFile = function(){
var lCurrent = DOM.getByClass(lCURRENT_FILE)[0];
if(!lCurrent)
this.addCloudStatus({
code : -1,
msg : 'Error: can not find ' +
'CurrentFile ' +
'in getCurrentFile'
});
return lCurrent;
};
this.getRefreshButton = function(){
var lPanel = this.getPanel(),
lRefresh = this.getByClass(CloudFunc.REFRESHICON, lPanel);
if (lRefresh.length)
lRefresh = lRefresh[0];
else {
this.addCloudStatus({
code : -3,
msg : 'Error Refresh icon not found'
});
lRefresh = false;
}
return lRefresh;
};
this.setCurrentFile = function(pCurrentFile){
var lRet_b = true;
if(!pCurrentFile){
this.addCloudStatus({
code : -1,
msg : 'Error pCurrentFile in' +
'setCurrentFile' +
'could not be none'
});
lRet_b = false;
}
var lCurrentFileWas = this.getCurrentFile();
if (pCurrentFile.className === 'path')
pCurrentFile = pCurrentFile.nextSibling;
if (pCurrentFile.className === 'fm_header')
pCurrentFile = pCurrentFile.nextSibling;
if(lCurrentFileWas)
lUnSetCurrentFile(lCurrentFileWas);
this.addClass(pCurrentFile, lCURRENT_FILE);
/* scrolling to current file */
DOM.scrollIntoViewIfNeeded(pCurrentFile);
return lRet_b;
};
var lUnSetCurrentFile = function(pCurrentFile){
if(!pCurrentFile)
DOM.addCloudStatus({
code : -1,
msg : 'Error pCurrentFile in' +
'unSetCurrentFile' +
'could not be none'
});
var lRet_b = DOM.isCurrentFile(pCurrentFile);
if(lRet_b)
DOM.removeClass(pCurrentFile, lCURRENT_FILE);
return lRet_b;
};
this.isCurrentFile = function(pCurrentFile){
if(!pCurrentFile)
this.addCloudStatus({
code : -1,
msg : 'Error pCurrentFile in' +
'isCurrentFile' +
'could not be none'
});
var lCurrentFileClass = pCurrentFile.className,
lIsCurrent = lCurrentFileClass.indexOf(lCURRENT_FILE) >= 0;
return lIsCurrent;
};
/**
* functions check is pVarible is array
* @param pVarible
*/
this.isArray = function(pVarible){
return pVarible instanceof Array;
};
/**
* functions check is pVarible is boolean
* @param pVarible
*/
this.isBoolean = function(pVarible){
return this.isType(pVarible, 'boolean');
};
/**
* functions check is pVarible is object
* @param pVarible
*/
this.isObject = function(pVarible){
return this.isType(pVarible, 'object');
};
/**
* functions check is pVarible is string
* @param pVarible
*/
this.isString = function(pVarible){
return this.isType(pVarible, 'string');
};
/**
* functions check is pVarible is function
* @param pVarible
*/
this.isFunction = function(pVarible){
return this.isType(pVarible, 'function');
};
/**
* functions check is pVarible is pType
* @param pVarible
* @param pType
*/
this.isType = function(pVarible, pType){
return typeof pVarible === pType;
};
this.getCurrentLink = function(pCurrentFile){
var lLink = this.getByTag('a',
pCurrentFile || this.getCurrentFile()),
lRet = lLink.length > 0 ? lLink[0] : -1;
if(!lRet)
this.addCloudStatus({
code : -1,
msg : 'Error current element do not contain links'
});
return lRet;
};
this.getCurrentName = function(pCurrentFile){
var lLink = this.getCurrentLink(
pCurrentFile || this.getCurrentFile());
if(!lLink)
this.addCloudStatus({
code : -1,
msg : 'Error current element do not contain links'
});
else lLink = lLink.textContent;
return lLink;
};
/* function getting panel active, or passive
* @pPanel_o = {active: true}
*/
this.getPanel = function(pActive){
var lPanel = this.getCurrentFile().parentElement;
/* if {active : false} getting passive panel */
if(pActive && !pActive.active){
var lId = lPanel.id === 'left' ? 'right' : 'left';
lPanel = this.getById(lId);
}
/* if two panels showed
* then always work with passive
* panel
*/
if(window.innerWidth < CloudCommander.MIN_ONE_PANEL_WIDTH)
lPanel = this.getById('left');
if(!lPanel)
console.log('Error can not find Active Panel');
return lPanel;
};
this.show = function(pElement){
DOM.removeClass(pElement, 'hidden');
};
this.showPanel = function(pActive){
var lRet = true,
lPanel = this.getPanel(pActive);
if(lPanel)
this.show(lPanel);
else
lRet = false;
return lRet;
};
this.hidePanel = function(pActive){
var lRet = false,
lPanel = this.getPanel(pActive);
if(lPanel)
lRet = this.hide(lPanel);
return lRet;
};
this.hide = function(pElement){
return this.addClass(pElement, 'hidden');
};
this.removeClass = function(pElement, pClass){
var lRet_b = true,
lClassList = pElement.classList;
if(pElement && lClassList)
lClassList.remove(pClass);
else
lRet_b = false;
return lRet_b;
};
this.removeCurrent = function(pCurrent){
var lParent = pCurrent.parentElement;
if(!pCurrent)
pCurrent = this.getCurrentFile();
var lName = this.getCurrentName(pCurrent);
if(pCurrent && lParent){
if(lName !== '..'){
var lNext = pCurrent.nextSibling;
var lPrevious = pCurrent.previousSibling;
if(lNext)
DOM.setCurrentFile(lNext);
else if(lPrevious)
DOM.setCurrentFile(lPrevious);
lParent.removeChild(pCurrent);
}
else
this.addCloudStatus({
code : -1,
msg : 'Could not remove parrent dir'
});
}
else
this.addCloudStatus({
code : -1,
msg : 'Current file (or parent of current) could not be empty'
});
return pCurrent;
};
this.scrollIntoViewIfNeeded = function(pElement){
var lRet = true;
if(pElement && pElement.scrollIntoViewIfNeeded)
pElement.scrollIntoViewIfNeeded();
else
lRet = false;
return lRet;
};
this.CloudStatus = [];
this.addCloudStatus = function(pStatus){
this.CloudStatus[this.CloudStatus.length] = pStatus;
};
});
var Util = CloudClient.Util = new CloudClient.Util();
CloudClient.GoogleAnalytics = function(){
/* google analytics */
var lFunc = document.onmousemove;

View file

@ -5,7 +5,6 @@ var CloudCommander, CloudFunc, CodeMirror;
(function(){
"use strict";
var cloudcmd = CloudCommander,
Util = CloudCommander.Util,
KeyBinding = CloudCommander.KeyBinding,
CodeMirrorEditor = {},
FM,
@ -31,9 +30,9 @@ var CloudCommander, CloudFunc, CodeMirror;
*/
function initCodeMirror(pValue){
if(!FM)
FM = Util.getById('fm');
FM = DOM.getById('fm');
CodeMirrorElement = Util.anyload({
CodeMirrorElement = DOM.anyload({
name : 'div',
id : 'CodeMirrorEditor',
className : 'panel',
@ -63,7 +62,7 @@ var CloudCommander, CloudFunc, CodeMirror;
console.time('codemirror load');
var lDir = CodeMirrorEditor.dir;
Util.anyLoadOnLoad(
DOM.anyLoadOnLoad(
[{
name: 'style',
id:'editor',
@ -114,15 +113,15 @@ var CloudCommander, CloudFunc, CodeMirror;
return;
/* getting link */
var lCurrentFile = Util.getCurrentFile(),
lA = Util.getCurrentLink(lCurrentFile);
var lCurrentFile = DOM.getCurrentFile(),
lA = DOM.getCurrentLink(lCurrentFile);
lA = lA.href;
/* убираем адрес хоста*/
lA = '/' + lA.replace(document.location.href,'');
/* checking is this link is to directory */
var lSize = Util.getByClass('size', lCurrentFile);
var lSize = DOM.getByClass('size', lCurrentFile);
if(lSize){
lSize = lSize[0].textContent;
@ -149,11 +148,11 @@ var CloudCommander, CloudFunc, CodeMirror;
400);
/* reading data from current file */
Util.ajax({
DOM.ajax({
url:lA,
error: function(jqXHR, textStatus, errorThrown){
Loading = false;
return Util.Images.showError(jqXHR);
return DOM.Images.showError(jqXHR);
},
success:function(data, textStatus, jqXHR){
@ -161,7 +160,7 @@ var CloudCommander, CloudFunc, CodeMirror;
if(typeof data === 'object')
data = JSON.stringify(data, null, 4);
var lHided = Util.hidePanel();
var lHided = DOM.hidePanel();
if(lHided){
initCodeMirror(data);
@ -169,7 +168,7 @@ var CloudCommander, CloudFunc, CodeMirror;
KeyBinding.unSet();
}
Util.Images.hideLoad();
DOM.Images.hideLoad();
Loading = false;
}
@ -186,7 +185,7 @@ var CloudCommander, CloudFunc, CodeMirror;
if(lElem && FM)
FM.removeChild(lElem);
Util.showPanel();
DOM.showPanel();
};
/**
@ -205,7 +204,7 @@ var CloudCommander, CloudFunc, CodeMirror;
/* if f4 or f3 pressed */
var lF3 = cloudcmd.KEY.F3;
var lF4 = cloudcmd.KEY.F4;
var lShow = Util.bind( CodeMirrorEditor.show, CodeMirrorEditor );
var lShow = DOM.bind( CodeMirrorEditor.show, CodeMirrorEditor );
if(!pEvent.shiftKey){
switch(pEvent.keyCode)

View file

@ -1,13 +1,12 @@
/* object contains jQuery-contextMenu
* https://github.com/medialize/jQuery-contextMenu
*/
var CloudCommander, $;
var CloudCommander, Util, DOM, $;
(function(){
"use strict";
var cloudcmd = CloudCommander,
KeyBinding = cloudcmd.KeyBinding,
Util = cloudcmd.Util,
MenuSeted = false,
Menu = {},
Position;
@ -23,9 +22,9 @@ var CloudCommander, $;
* @param pReadOnly
*/
function showEditor(pReadOnly){
Util.Images.showLoad();
DOM.Images.showLoad();
var lEditor = pReadOnly ? cloudcmd.Viewer : cloudcmd.Editor;
if( Util.isFunction(lEditor) )
lEditor(pReadOnly);
else{
@ -64,36 +63,36 @@ var CloudCommander, $;
}},
download: {name: 'Download',callback: function(key, opt){
Util.Images.showLoad();
DOM.Images.showLoad();
var lCurrent = Util.getCurrentFile(),
lLink = Util.getByTag('a', lCurrent)[0].href;
var lCurrent = DOM.getCurrentFile(),
lLink = DOM.getByTag('a', lCurrent)[0].href;
console.log('downloading file ' + lLink +'...');
lLink = lLink + '?download';
lLink = Util.removeStr( lLink, CloudFunc.NOJS );
var lId = Util.getIdBySrc(lLink);
var lId = DOM.getIdBySrc(lLink);
if(!Util.getById(lId)){
var lDownload = Util.anyload({
if(!DOM.getById(lId)){
var lDownload = DOM.anyload({
name : 'iframe',
async : false,
className : 'hidden',
src : lLink,
func : function(){
Util.Images.hideLoad();
DOM.Images.hideLoad();
}
});
Util.Images.hideLoad();
DOM.Images.hideLoad();
setTimeout(function() {
document.body.removeChild(lDownload);
}, 10000);
}
else
Util.Images.showError({
DOM.Images.showError({
responseText: 'Error: You trying to' +
'download same file to often'});
}}
@ -110,7 +109,7 @@ var CloudCommander, $;
var lDir = Menu.dir;
Util.anyLoadOnLoad([
DOM.anyLoadOnLoad([
lDir + 'contextMenu.js',
lDir + 'contextMenu.css'],
function(){
@ -138,7 +137,7 @@ var CloudCommander, $;
*/
document.onclick = function(pEvent){
if(pEvent && pEvent.x && pEvent.y){
var lLayer = Util.getById('context-menu-layer');
var lLayer = DOM.getById('context-menu-layer');
if(lLayer){
var lStyle;
@ -161,7 +160,7 @@ var CloudCommander, $;
lParent = lElement.parentElement;
if(lParent.className === '')
Util.setCurrentFile(lParent);
DOM.setCurrentFile(lParent);
}
/* show invisible menu layer */
@ -190,7 +189,7 @@ var CloudCommander, $;
Menu.show = function(){
set();
Util.Images.hideLoad();
DOM.Images.hideLoad();
if(Position && Position.x && Position.y)
$('li').contextMenu(Position);
@ -214,7 +213,7 @@ var CloudCommander, $;
if( KeyBinding.get() ){
/* if shift + F10 pressed */
if(pEvent.keyCode === cloudcmd.KEY.F10 && pEvent.shiftKey){
var lCurrent = Util.getCurrentFile();
var lCurrent = DOM.getCurrentFile();
if(lCurrent)
$(lCurrent).contextMenu();
pEvent.preventDefault();
@ -244,7 +243,7 @@ var CloudCommander, $;
Menu.show();
}
Util.jqueryLoad( load );
DOM.jqueryLoad( load );
};
cloudcmd.Menu = Menu;

View file

@ -1,10 +1,9 @@
/* module make possible connectoin thrue socket.io on a client */
var CloudCommander, io;
var CloudCommander, DOM, Util, io;
(function(){
"use strict";
var cloudcmd = CloudCommander,
Util = cloudcmd.Util,
Messages = [],
socket,
JqueryTerminal;
@ -13,7 +12,7 @@ var CloudCommander, io;
return cloudcmd.Terminal.JqueryTerminal;
}
Util.jsload('/socket.io/lib/socket.io.js', {
DOM.jsload('/socket.io/lib/socket.io.js', {
onload : function(){
socket = io.connect(document.location.hostname);

View file

@ -1,4 +1,4 @@
var CloudCommander, $;
var CloudCommander, DOM, $;
/* object contains terminal jqconsole */
(function(){
@ -6,7 +6,6 @@ var CloudCommander, $;
var cloudcmd = CloudCommander,
Util = cloudcmd.Util,
KeyBinding = cloudcmd.KeyBinding,
TerminalId,
Term,
@ -26,12 +25,12 @@ var CloudCommander, $;
var lDir = 'lib/client/terminal/jquery-terminal/jquery.';
Util.cssLoad(lDir + 'terminal.css');
DOM.cssLoad(lDir + 'terminal.css');
Util.socketLoad();
DOM.socketLoad();
Util.anyLoadOnLoad([
DOM.anyLoadOnLoad([
lDir + 'terminal.js',
lDir + 'mousewheel.js'],
@ -63,9 +62,9 @@ var CloudCommander, $;
*/
function init(){
if(!TerminalId){
var lFM = Util.getById('fm');
var lFM = DOM.getById('fm');
if(lFM)
TerminalId = Util.anyload({
TerminalId = DOM.anyload({
name : 'div',
id : 'terminal',
className : 'panel',
@ -82,13 +81,13 @@ var CloudCommander, $;
* functin show jquery-terminal
*/
JqueryTerminal.show = function(){
Util.Images.hideLoad();
DOM.Images.hideLoad();
/* only if panel was hided */
var lHided = Util.hidePanel();
var lHided = DOM.hidePanel();
if(lHided){
Hidden = false;
Util.show(TerminalId);
DOM.show(TerminalId);
KeyBinding.unSet();
@ -102,8 +101,8 @@ var CloudCommander, $;
JqueryTerminal.hide = function(){
Hidden = true;
Util.hide(TerminalId);
Util.showPanel();
DOM.hide(TerminalId);
DOM.showPanel();
KeyBinding.set();
@ -113,9 +112,9 @@ var CloudCommander, $;
/**
* function bind keys
*/
cloudcmd.Terminal.Keys = function(){
cloudcmd.Terminal.Keys = function(){
/* loading js and css*/
Util.jqueryLoad( load );
DOM.jqueryLoad( load );
var key_event = function(event){
/* если клавиши можно обрабатывать */

View file

@ -1,4 +1,4 @@
var CloudCommander, CloudFunc, $;
var CloudCommander, Util, DOM, CloudFunc, $;
/* object contains viewer FancyBox
* https://github.com/fancyapps/fancyBox
*/
@ -6,7 +6,6 @@ var CloudCommander, CloudFunc, $;
"use strict";
var cloudcmd = CloudCommander,
Util = CloudCommander.Util,
KeyBinding = CloudCommander.KeyBinding,
FancyBox = {};
@ -22,14 +21,14 @@ var CloudCommander, CloudFunc, $;
/* PRIVATE FUNCTIONS */
function set(){
if(Util.getByClass('fancybox').length)
if(DOM.getByClass('fancybox').length)
return;
try{
/* get current panel (left or right) */
var lPanel = Util.getPanel();
var lPanel = DOM.getPanel();
/* get all file links */
var lA = Util.getByTag('a', lPanel);
var lA = DOM.getByTag('a', lPanel);
var lDblClick_f = function(pA){
return function(){
@ -75,7 +74,7 @@ var CloudCommander, CloudFunc, $;
},
afterShow : function(){
var lEditor = Util.getById('CloudViewer');
var lEditor = DOM.getById('CloudViewer');
if(lEditor)
lEditor.focus();
},
@ -108,7 +107,7 @@ var CloudCommander, CloudFunc, $;
console.time('fancybox load');
var lDir = FancyBox.dir;
Util.anyLoadOnLoad([
DOM.anyLoadOnLoad([
lDir + 'jquery.fancybox.css',
lDir + 'jquery.fancybox.js'],
@ -117,7 +116,7 @@ var CloudCommander, CloudFunc, $;
pCallBack();
});
Util.cssSet({id:'viewer',
DOM.cssSet({id:'viewer',
inner : '#CloudViewer{' +
'font-size: 16px;' +
'white-space :pre' +
@ -142,7 +141,7 @@ var CloudCommander, CloudFunc, $;
* Example: loadData('index.html', function(pData){console.log(pData)});
*/
FancyBox.loadData = function(pA, pSuccess_f){
Util.Images.showLoad();
DOM.Images.showLoad();
var lThis = this;
var lLink = pA.href;
@ -153,18 +152,18 @@ var CloudCommander, CloudFunc, $;
if (lLink.indexOf(CloudFunc.NOJS) === CloudFunc.FS.length)
lLink = lLink.replace(CloudFunc.NOJS, '');
Util.ajax({
DOM.ajax({
url : lLink,
error : (function(jqXHR, textStatus, errorThrown){
lThis.loading = false;
return Util.Images.showError(jqXHR, textStatus, errorThrown);
return DOM.Images.showError(jqXHR, textStatus, errorThrown);
}),
success:function(data, textStatus, jqXHR){
if(typeof pSuccess_f === 'function')
pSuccess_f(data);
Util.Images.hideLoad();
DOM.Images.hideLoad();
}
});
};
@ -190,9 +189,9 @@ var CloudCommander, CloudFunc, $;
if( Util.isFunction(pCallBack) )
pCallBack();
else{
var lCurrentFile = Util.getCurrentFile();
var lCurrentFile = DOM.getCurrentFile();
var lA = Util.getByClass('fancybox', lCurrentFile)[0];
var lA = DOM.getByClass('fancybox', lCurrentFile)[0];
if(lA){
if(lA.rel)
$.fancybox.open({ href : lA.href },
@ -201,7 +200,7 @@ var CloudCommander, CloudFunc, $;
}
}
Util.Images.hideLoad();
DOM.Images.hideLoad();
};
cloudcmd.Viewer.Keys = function(){
@ -211,7 +210,7 @@ var CloudCommander, CloudFunc, $;
/* если клавиши можно обрабатывать */
if( KeyBinding.get() )
if(pEvent.keyCode === lF3 && pEvent.shiftKey){
var lCurrentFile = Util.getCurrentFile();
var lCurrentFile = DOM.getCurrentFile();
FancyBox.show(lCurrentFile);
pEvent.preventDefault();
@ -237,10 +236,10 @@ var CloudCommander, CloudFunc, $;
/* showing images preview*/
FancyBox.show();
Util.Images.hideLoad();
DOM.Images.hideLoad();
};
Util.jqueryLoad(function(){
DOM.jqueryLoad(function(){
FancyBox.load(lCallBack_f);
});
};