fixed bug with menu items sshow and view

This commit is contained in:
coderaiser 2012-10-05 04:52:54 -04:00
parent b26be35ef6
commit d5ea30d4e9
7 changed files with 126 additions and 102 deletions

View file

@ -5,36 +5,38 @@ var CloudCommander, $;
(function(){
"use strict";
var cloudcmd = CloudCommander;
var KeyBinding = cloudcmd.KeyBinding;
cloudcmd.Menu = {};
var Util = CloudCommander.Util;
CloudCommander.Menu.dir = './lib/client/menu/';
var cloudcmd = CloudCommander,
KeyBinding = cloudcmd.KeyBinding,
Util = cloudcmd.Util,
MenuSeted = false,
Menu = {},
Position;
Menu.dir = './lib/client/menu/';
/* enable and disable menu constant */
CloudCommander.Menu.ENABLED = false;
Menu.ENABLED = false;
CloudCommander.Menu.showEditor = (function(pReadOnly){
/* PRIVATE FUNCTIONS */
/** function shows editor
* @param pReadOnly
*/
function showEditor(pReadOnly){
Util.Images.showLoad();
var lEditor = pReadOnly ? cloudcmd.Viewer : cloudcmd.Editor;
var lCurrent = Util.getCurrentFile();
if(lCurrent){
if(typeof lEditor === 'function')
lEditor(lCurrent);
else{
lEditor = lEditor.get();
if(lEditor && lEditor.show)
lEditor.show(lCurrent);
}
}
});
if( Util.isFunction(lEditor) )
lEditor(pReadOnly);
else{
lEditor = lEditor.get();
if(lEditor && lEditor.show)
lEditor.show();
}
}
/* function return configureation for menu */
CloudCommander.Menu.getConfig = (function(){
/** function return configureation for menu */
function getConfig (){
return{
// define which elements trigger this menu
selector: 'li',
@ -48,11 +50,11 @@ var CloudCommander, $;
// define the elements of the menu
items: {
view: {name: 'View', callback: function(key, opt){
CloudCommander.showEditor(true);
showEditor(true);
}},
edit: {name: 'Edit', callback: function(key, opt){
CloudCommander.showEditor(false);
showEditor();
}},
'delete': {name: 'Delete',
@ -94,24 +96,23 @@ var CloudCommander, $;
}}
}
};
});
}
/* function loads css and js of Menu
* @pParent - this
* @pPosition - position of menu
/** function loads css and js of Menu
* @param pParent - this
* @param pPosition - position of menu
*/
CloudCommander.Menu.load = (function(pPosition){
var lThis = this;
function load(){
var ljsLoad_f = function(){
var lUISrc = lThis.dir + 'ui.position.js';
var lMenuSrc = lThis.dir + 'contextMenu.js';
var lUISrc = Menu.dir + 'ui.position.js';
var lMenuSrc = Menu.dir + 'contextMenu.js';
Util.jsload(lUISrc, function(){
Util.jsload(lMenuSrc, lThis.show(lThis, pPosition));
Util.jsload(lMenuSrc, Menu.show());
});
};
var lSrc = this.dir + 'contextMenu.css';
var lSrc = Menu.dir + 'contextMenu.css';
Util.cssLoad({
src : lSrc,
@ -121,11 +122,11 @@ var CloudCommander, $;
}
}
});
});
}
CloudCommander.Menu.set = (function(){
if(!this.seted){
$.contextMenu(this.getConfig());
function set(){
if(!MenuSeted){
$.contextMenu(getConfig());
var lFunc_f = document.onclick;
/*
@ -183,44 +184,43 @@ var CloudCommander, $;
}
};
this.seted = true;
MenuSeted = true;
}
});
}
CloudCommander.Menu.seted = false;
/* function shows menu for the first time
/** function shows menu for the first time
* right away after loading
*/
CloudCommander.Menu.show = (function(pThis, pPosition){
Menu.show = function(){
return function(){
pThis.set();
set();
Util.Images.hideLoad();
if(pPosition && pPosition.x && pPosition.y)
$('li').contextMenu(pPosition);
if(Position && Position.x && Position.y)
$('li').contextMenu(Position);
else
$('li').contextMenu();
};
});
};
/* key binding function */
CloudCommander.Menu.Keys = (function(pPosition){
"use strict";
var lFunc = document.oncontextmenu;
Menu.Keys = function(pPosition){
Position = pPosition;
var lFunc = document.oncontextmenu;
document.oncontextmenu = function(){
if(typeof lFunc === 'function')
lFunc();
return CloudCommander.Menu.ENABLED;
return Menu.ENABLED;
};
var key_event = (function(pEvent){
/* если клавиши можно обрабатывать */
if( KeyBinding.get() )
/* if shift + F10 pressed */
if(pEvent.keyCode === CloudCommander.KEY.F10 &&
if(pEvent.keyCode === cloudcmd.KEY.F10 &&
pEvent.shiftKey){
var lCurrent = Util.getCurrentFile();
if(lCurrent)
@ -247,9 +247,11 @@ var CloudCommander, $;
};
/* showing context menu preview*/
CloudCommander.Menu.show();
Menu.show();
}
CloudCommander.Menu.load(pPosition);
});
load();
};
cloudcmd.Menu = Menu;
})();