mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-24 03:05:41 +00:00
from now Util would not be inherited by any of client libs, would be use link on it, no need of inheritence
This commit is contained in:
parent
f0e479d260
commit
010fd74898
2 changed files with 239 additions and 234 deletions
|
|
@ -890,7 +890,7 @@ CloudClient.init=(function()
|
|||
document.head = document.getElementsByTagName("head")[0];
|
||||
}
|
||||
|
||||
Util = new CloudClient.Util();
|
||||
Util = new CloudClient.Utils();
|
||||
getByClass = Util.getByClass;
|
||||
getById = Util.getById;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,248 +1,253 @@
|
|||
var CloudCommander, $;
|
||||
/* object contains jQuery-contextMenu
|
||||
* https://github.com/medialize/jQuery-contextMenu
|
||||
*/
|
||||
CloudCommander.Menu = new CloudCommander.Util();
|
||||
|
||||
CloudCommander.Menu.dir = './lib/client/menu/';
|
||||
|
||||
/* enable and disable menu constant */
|
||||
CloudCommander.Menu.ENABLED = false;
|
||||
(function(){
|
||||
"use strict";
|
||||
|
||||
/* object contains jQuery-contextMenu
|
||||
* https://github.com/medialize/jQuery-contextMenu
|
||||
*/
|
||||
CloudCommander.Menu = new CloudCommander.Utils();
|
||||
var Util = CloudCommander.Util();
|
||||
|
||||
/* function return configureation
|
||||
* for menu
|
||||
*/
|
||||
CloudCommander.Menu.getConfig = (function(){
|
||||
var lThis = this;
|
||||
return{
|
||||
// define which elements trigger this menu
|
||||
selector: 'li',
|
||||
|
||||
callback: function(key, options) {
|
||||
var m = "clicked: " + key;
|
||||
console.log(m, options);
|
||||
|
||||
CloudCommander.keyBinded = true;
|
||||
},
|
||||
// define the elements of the menu
|
||||
items: {
|
||||
view: {name: 'View', callback: function(key, opt){
|
||||
if(typeof CloudCommander.Viewer === 'function')
|
||||
CloudCommander.Viewer();
|
||||
else{
|
||||
var lViewer = CloudCommander.Viewer.get();
|
||||
if(lViewer && lViewer.show)
|
||||
lViewer.show();
|
||||
}
|
||||
}},
|
||||
|
||||
edit: {name: 'Edit', callback: function(key, opt){
|
||||
lThis.Images.showLoad();
|
||||
|
||||
if(typeof CloudCommander.Editor === 'function')
|
||||
CloudCommander.Editor();
|
||||
else{
|
||||
var lEditor = CloudCommander.Editor.get();
|
||||
if(lEditor && lEditor.show)
|
||||
lEditor.show();
|
||||
}
|
||||
|
||||
}},
|
||||
|
||||
'delete': {name: 'Delete',
|
||||
callback: function(key, opt){
|
||||
console.log('delete menu item choosen');
|
||||
}},
|
||||
|
||||
download: {name: 'Download',callback: function(key, opt){
|
||||
lThis.Images.showLoad();
|
||||
|
||||
var lCurrent = lThis.getCurrentFile();
|
||||
var lLink = lThis.getByTag('a', lCurrent)[0].href;
|
||||
|
||||
console.log('downloading file ' + lLink +'...');
|
||||
|
||||
lLink = lLink + '?download';
|
||||
var lId = lThis.getIdBySrc(lLink);
|
||||
if(!lThis.getById(lId)){
|
||||
var lDownload = lThis.anyload({
|
||||
name : 'iframe',
|
||||
async : false,
|
||||
className : 'hidden',
|
||||
src : lLink,
|
||||
func : function(){
|
||||
lThis.Images.hideLoad();
|
||||
}
|
||||
});
|
||||
|
||||
lThis.Images.hideLoad();
|
||||
setTimeout(function() {
|
||||
document.body.removeChild(lDownload);
|
||||
}, 10000);
|
||||
}
|
||||
else{
|
||||
lThis.Images.showError({
|
||||
responseText: 'Error: You trying to' +
|
||||
'download same file to often'});
|
||||
}
|
||||
}}
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
/* function loads css and js of Menu
|
||||
* @pParent - this
|
||||
* @pPosition - position of menu
|
||||
*/
|
||||
CloudCommander.Menu.load = (function(pParent, pPosition){
|
||||
return function(){
|
||||
var ljsLoad_f = function(){
|
||||
var lUISrc = pParent.dir + 'jquery.ui.position.js';
|
||||
var lMenuSrc = pParent.dir + 'jquery.contextMenu.js';
|
||||
|
||||
pParent.jsload(lUISrc, function(){
|
||||
pParent.jsload(lMenuSrc, pParent.show(pParent, pPosition));
|
||||
});
|
||||
};
|
||||
|
||||
var lSrc = pParent.dir + 'jquery.contextMenu.css';
|
||||
|
||||
pParent.cssLoad({
|
||||
src : lSrc,
|
||||
func : {
|
||||
onload: ljsLoad_f
|
||||
}
|
||||
});
|
||||
}();
|
||||
});
|
||||
|
||||
CloudCommander.Menu.set = (function(){
|
||||
if(!this.seted){
|
||||
$.contextMenu(this.getConfig());
|
||||
|
||||
var lThis = this;
|
||||
|
||||
var lFunc_f = document.onclick;
|
||||
/*
|
||||
* Menu works in some crazy way so need a
|
||||
* little hack to get every thing work out.
|
||||
* When menu shows up, it drawing invisible
|
||||
* layer wich hides all elements of
|
||||
* Cloud Commander so it could not handle
|
||||
* onclick events. To get every thing work
|
||||
* how expected we hide out invisible layer
|
||||
* so for observer it is nothing special
|
||||
* is not going on. All magic happening in
|
||||
* DOM tree
|
||||
*/
|
||||
document.onclick = function(pEvent){
|
||||
if(pEvent && pEvent.x && pEvent.y){
|
||||
if(lLayer){
|
||||
var lLayer = lThis.getById('context-menu-layer');
|
||||
var lStyle;
|
||||
|
||||
if(lLayer)
|
||||
lStyle = lLayer.style.cssText;
|
||||
/* hide invisible menu layer */
|
||||
if(lStyle)
|
||||
lLayer.style.cssText = lStyle
|
||||
.replace('z-index: 1', 'z-index:-1');
|
||||
|
||||
/* get element by point */
|
||||
var lElement = document.elementFromPoint(pEvent.x, pEvent.y);
|
||||
var lTag = lElement.tagName;
|
||||
var lParent;
|
||||
CloudCommander.Menu.dir = './lib/client/menu/';
|
||||
|
||||
if(lTag === 'A' || lTag === 'SPAN'){
|
||||
if (lElement.tagName === 'A')
|
||||
lParent = lElement.parentElement.parentElement;
|
||||
else if(lElement.tagName === 'SPAN')
|
||||
lParent = lElement.parentElement;
|
||||
|
||||
lThis.setCurrentFile(lParent);
|
||||
/* enable and disable menu constant */
|
||||
CloudCommander.Menu.ENABLED = false;
|
||||
|
||||
/* function return configureation
|
||||
* for menu
|
||||
*/
|
||||
CloudCommander.Menu.getConfig = (function(){
|
||||
return{
|
||||
// define which elements trigger this menu
|
||||
selector: 'li',
|
||||
|
||||
callback: function(key, options) {
|
||||
var m = "clicked: " + key;
|
||||
console.log(m, options);
|
||||
|
||||
CloudCommander.keyBinded = true;
|
||||
},
|
||||
// define the elements of the menu
|
||||
items: {
|
||||
view: {name: 'View', callback: function(key, opt){
|
||||
if(typeof CloudCommander.Viewer === 'function')
|
||||
CloudCommander.Viewer();
|
||||
else{
|
||||
var lViewer = CloudCommander.Viewer.get();
|
||||
if(lViewer && lViewer.show)
|
||||
lViewer.show();
|
||||
}
|
||||
}},
|
||||
|
||||
edit: {name: 'Edit', callback: function(key, opt){
|
||||
Util.Images.showLoad();
|
||||
|
||||
if(typeof CloudCommander.Editor === 'function')
|
||||
CloudCommander.Editor();
|
||||
else{
|
||||
var lEditor = CloudCommander.Editor.get();
|
||||
if(lEditor && lEditor.show)
|
||||
lEditor.show();
|
||||
}
|
||||
|
||||
/* show invisible menu layer */
|
||||
if(lLayer && lStyle)
|
||||
lLayer.style.cssText = lStyle;
|
||||
|
||||
/* if document.onclick was set up
|
||||
* before us, it's best time to call it
|
||||
*/
|
||||
if(typeof lFunc_f === 'function')
|
||||
lFunc_f();
|
||||
}},
|
||||
|
||||
CloudCommander.keyBinded = true;
|
||||
}
|
||||
'delete': {name: 'Delete',
|
||||
callback: function(key, opt){
|
||||
console.log('delete menu item choosen');
|
||||
}},
|
||||
|
||||
download: {name: 'Download',callback: function(key, opt){
|
||||
Util.Images.showLoad();
|
||||
|
||||
var lCurrent = Util.getCurrentFile();
|
||||
var lLink = Util.getByTag('a', lCurrent)[0].href;
|
||||
|
||||
console.log('downloading file ' + lLink +'...');
|
||||
|
||||
lLink = lLink + '?download';
|
||||
var lId = Util.getIdBySrc(lLink);
|
||||
|
||||
if(!Util.getById(lId)){
|
||||
var lDownload = Util.anyload({
|
||||
name : 'iframe',
|
||||
async : false,
|
||||
className : 'hidden',
|
||||
src : lLink,
|
||||
func : function(){
|
||||
Util.Images.hideLoad();
|
||||
}
|
||||
});
|
||||
|
||||
Util.Images.hideLoad();
|
||||
setTimeout(function() {
|
||||
document.body.removeChild(lDownload);
|
||||
}, 10000);
|
||||
}
|
||||
else{
|
||||
Util.Images.showError({
|
||||
responseText: 'Error: You trying to' +
|
||||
'download same file to often'});
|
||||
}
|
||||
}}
|
||||
}
|
||||
};
|
||||
|
||||
this.seted = true;
|
||||
}
|
||||
});
|
||||
|
||||
CloudCommander.Menu.seted = false;
|
||||
|
||||
/* function shows menu for the first time
|
||||
* right away after loading
|
||||
*/
|
||||
CloudCommander.Menu.show = (function(pParent, pPosition){
|
||||
return function(){
|
||||
pParent.set();
|
||||
|
||||
pParent.Images.hideLoad();
|
||||
|
||||
if(pPosition && pPosition.x && pPosition.y)
|
||||
$('li').contextMenu(pPosition);
|
||||
else
|
||||
$('li').contextMenu();
|
||||
};
|
||||
});
|
||||
|
||||
/* key binding function */
|
||||
CloudCommander.Menu.Keys = (function(pPosition){
|
||||
"use strict";
|
||||
|
||||
var lFunc = document.oncontextmenu;
|
||||
document.oncontextmenu = function(){
|
||||
if(typeof lFunc === 'function')
|
||||
lFunc();
|
||||
return CloudCommander.Menu.ENABLED;
|
||||
};
|
||||
});
|
||||
|
||||
var key_event = (function(pEvent){
|
||||
/* если клавиши можно обрабатывать */
|
||||
if(CloudCommander.keyBinded)
|
||||
/* if shift + F10 pressed */
|
||||
if(pEvent.keyCode === CloudCommander.KEY.F10 &&
|
||||
pEvent.shiftKey){
|
||||
var lCurrent = this.getCurrentFile();
|
||||
if(lCurrent)
|
||||
$(lCurrent).contextMenu();
|
||||
/* function loads css and js of Menu
|
||||
* @pParent - this
|
||||
* @pPosition - position of menu
|
||||
*/
|
||||
CloudCommander.Menu.load = (function(pParent, pPosition){
|
||||
return function(){
|
||||
var ljsLoad_f = function(){
|
||||
var lUISrc = pParent.dir + 'jquery.ui.position.js';
|
||||
var lMenuSrc = pParent.dir + 'jquery.contextMenu.js';
|
||||
|
||||
Util.jsload(lUISrc, function(){
|
||||
pParent.jsload(lMenuSrc, pParent.show(pParent, pPosition));
|
||||
});
|
||||
};
|
||||
|
||||
pEvent.preventDefault();
|
||||
var lSrc = pParent.dir + 'jquery.contextMenu.css';
|
||||
|
||||
pParent.cssLoad({
|
||||
src : lSrc,
|
||||
func : {
|
||||
onload: ljsLoad_f
|
||||
}
|
||||
});
|
||||
}();
|
||||
});
|
||||
|
||||
CloudCommander.Menu.set = (function(){
|
||||
if(!this.seted){
|
||||
$.contextMenu(this.getConfig());
|
||||
|
||||
var lThis = this;
|
||||
|
||||
var lFunc_f = document.onclick;
|
||||
/*
|
||||
* Menu works in some crazy way so need a
|
||||
* little hack to get every thing work out.
|
||||
* When menu shows up, it drawing invisible
|
||||
* layer wich hides all elements of
|
||||
* Cloud Commander so it could not handle
|
||||
* onclick events. To get every thing work
|
||||
* how expected we hide out invisible layer
|
||||
* so for observer it is nothing special
|
||||
* is not going on. All magic happening in
|
||||
* DOM tree
|
||||
*/
|
||||
document.onclick = function(pEvent){
|
||||
if(pEvent && pEvent.x && pEvent.y){
|
||||
if(lLayer){
|
||||
var lLayer = Util.getById('context-menu-layer');
|
||||
var lStyle;
|
||||
|
||||
if(lLayer)
|
||||
lStyle = lLayer.style.cssText;
|
||||
/* hide invisible menu layer */
|
||||
if(lStyle)
|
||||
lLayer.style.cssText = lStyle
|
||||
.replace('z-index: 1', 'z-index:-1');
|
||||
|
||||
/* get element by point */
|
||||
var lElement = document.elementFromPoint(pEvent.x, pEvent.y);
|
||||
var lTag = lElement.tagName;
|
||||
var lParent;
|
||||
|
||||
if(lTag === 'A' || lTag === 'SPAN'){
|
||||
if (lElement.tagName === 'A')
|
||||
lParent = lElement.parentElement.parentElement;
|
||||
else if(lElement.tagName === 'SPAN')
|
||||
lParent = lElement.parentElement;
|
||||
|
||||
lThis.setCurrentFile(lParent);
|
||||
}
|
||||
|
||||
/* show invisible menu layer */
|
||||
if(lLayer && lStyle)
|
||||
lLayer.style.cssText = lStyle;
|
||||
|
||||
/* if document.onclick was set up
|
||||
* before us, it's best time to call it
|
||||
*/
|
||||
if(typeof lFunc_f === 'function')
|
||||
lFunc_f();
|
||||
|
||||
CloudCommander.keyBinded = true;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
this.seted = true;
|
||||
}
|
||||
});
|
||||
|
||||
/* добавляем обработчик клавишь */
|
||||
if (document.addEventListener)
|
||||
document.addEventListener('keydown', key_event.bind(this),false);
|
||||
|
||||
else{
|
||||
var lFunc;
|
||||
if(typeof document.onkeydown === 'function')
|
||||
lFunc = document.onkeydown;
|
||||
|
||||
document.onkeydown = function(){
|
||||
if(lFunc)
|
||||
lFunc();
|
||||
|
||||
CloudCommander.Menu.seted = false;
|
||||
|
||||
/* function shows menu for the first time
|
||||
* right away after loading
|
||||
*/
|
||||
CloudCommander.Menu.show = (function(pParent, pPosition){
|
||||
return function(){
|
||||
pParent.set();
|
||||
|
||||
key_event();
|
||||
pParent.Images.hideLoad();
|
||||
|
||||
if(pPosition && pPosition.x && pPosition.y)
|
||||
$('li').contextMenu(pPosition);
|
||||
else
|
||||
$('li').contextMenu();
|
||||
};
|
||||
});
|
||||
|
||||
/* key binding function */
|
||||
CloudCommander.Menu.Keys = (function(pPosition){
|
||||
"use strict";
|
||||
|
||||
var lFunc = document.oncontextmenu;
|
||||
document.oncontextmenu = function(){
|
||||
if(typeof lFunc === 'function')
|
||||
lFunc();
|
||||
return CloudCommander.Menu.ENABLED;
|
||||
};
|
||||
|
||||
/* showing context menu preview*/
|
||||
CloudCommander.Menu.show();
|
||||
}
|
||||
|
||||
CloudCommander.Menu.load(this, pPosition);
|
||||
});
|
||||
var key_event = (function(pEvent){
|
||||
/* если клавиши можно обрабатывать */
|
||||
if(CloudCommander.keyBinded)
|
||||
/* if shift + F10 pressed */
|
||||
if(pEvent.keyCode === CloudCommander.KEY.F10 &&
|
||||
pEvent.shiftKey){
|
||||
var lCurrent = Util.getCurrentFile();
|
||||
if(lCurrent)
|
||||
$(lCurrent).contextMenu();
|
||||
|
||||
pEvent.preventDefault();
|
||||
}
|
||||
});
|
||||
|
||||
/* добавляем обработчик клавишь */
|
||||
if (document.addEventListener)
|
||||
document.addEventListener('keydown', key_event.bind(this),false);
|
||||
|
||||
else{
|
||||
lFunc;
|
||||
if(typeof document.onkeydown === 'function')
|
||||
lFunc = document.onkeydown;
|
||||
|
||||
document.onkeydown = function(){
|
||||
if(lFunc)
|
||||
lFunc();
|
||||
|
||||
key_event();
|
||||
};
|
||||
|
||||
/* showing context menu preview*/
|
||||
CloudCommander.Menu.show();
|
||||
}
|
||||
|
||||
CloudCommander.Menu.load(this, pPosition);
|
||||
});
|
||||
})();
|
||||
Loading…
Add table
Add a link
Reference in a new issue