mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-19 01:17:18 +00:00
dded ability to add a couple events in Events.add
This commit is contained in:
parent
9f31ff3368
commit
0ac792c87e
3 changed files with 65 additions and 26 deletions
|
|
@ -21,6 +21,8 @@ dispatch
|
|||
|
||||
* Changed the way of work with listeners (DOM.addListener to DOM.Events.add).
|
||||
|
||||
* Added ability to add a couple events in Events.add.
|
||||
|
||||
|
||||
2012.04.22, v0.2.0
|
||||
|
||||
|
|
|
|||
|
|
@ -117,7 +117,7 @@ var Util, DOM, CloudFunc, $, KeyBinding, CloudCmd;
|
|||
* if user clicks somewhere keyBinded
|
||||
* backs
|
||||
*/
|
||||
DOM.Events.addOneTime('click', function(){
|
||||
Events.addOneTime('click', function(){
|
||||
//lA.contentEditable = false;
|
||||
//KeyBinding && KeyBinding.set();
|
||||
});
|
||||
|
|
@ -511,18 +511,20 @@ var Util, DOM, CloudFunc, $, KeyBinding, CloudCmd;
|
|||
if (lLi.className === 'path')
|
||||
Events.addClick( lLoadDir, ai );
|
||||
else {
|
||||
Events.addClick( DOM.preventDefault, lLi);
|
||||
Events.add('mousedown', lSetCurrentFile_f, lLi);
|
||||
Events.add({
|
||||
'click' : DOM.preventDefault,
|
||||
'mousedown' : lSetCurrentFile_f,
|
||||
'contextmenu' : lOnContextMenu_f
|
||||
}, lLi);
|
||||
|
||||
Events.add('dragstart', lOnDragStart_f, ai);
|
||||
/* if right button clicked menu will
|
||||
* loads and shows
|
||||
*/
|
||||
Events.add('contextmenu', lOnContextMenu_f, lLi);
|
||||
|
||||
/* если ссылка на папку, а не файл */
|
||||
if(ai.target !== '_blank'){
|
||||
Events.add('dblclick', lLoadDirOnce, lLi);
|
||||
Events.add('touchend', lLoadDirOnce, lLi);
|
||||
Events.add({
|
||||
'dblclick' : lLoadDirOnce,
|
||||
'touchend' : lLoadDirOnce
|
||||
}, lLi);
|
||||
}
|
||||
|
||||
lLi.id = (ai.title ? ai.title : ai.textContent) +
|
||||
|
|
|
|||
|
|
@ -265,6 +265,10 @@ var CloudCmd, Util, DOM, CloudFunc;
|
|||
};
|
||||
},
|
||||
EventsProto = function(){
|
||||
var Events = this,
|
||||
ADD = true,
|
||||
REMOVE = false;
|
||||
|
||||
/**
|
||||
* safe add event listener
|
||||
*
|
||||
|
|
@ -274,17 +278,13 @@ var CloudCmd, Util, DOM, CloudFunc;
|
|||
* @param pElement {document by default}
|
||||
*/
|
||||
this.add = function(pType, pListener, pElement, pUseCapture){
|
||||
var lRet = this,
|
||||
lElement = (pElement || window);
|
||||
|
||||
if( lElement.addEventListener)
|
||||
lElement.addEventListener(
|
||||
pType,
|
||||
pListener,
|
||||
pUseCapture
|
||||
);
|
||||
|
||||
return lRet;
|
||||
return process(
|
||||
ADD,
|
||||
pType,
|
||||
pListener,
|
||||
pElement,
|
||||
pUseCapture
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -316,15 +316,13 @@ var CloudCmd, Util, DOM, CloudFunc;
|
|||
* @param pElement {document by default}
|
||||
*/
|
||||
this.remove = function(pType, pListener, pElement, pUseCapture){
|
||||
var lRet = this;
|
||||
|
||||
(pElement || window).removeEventListener(
|
||||
return process(
|
||||
REMOVE,
|
||||
pType,
|
||||
pListener,
|
||||
pElement,
|
||||
pUseCapture
|
||||
);
|
||||
|
||||
return lRet;
|
||||
};
|
||||
|
||||
|
||||
|
|
@ -456,6 +454,43 @@ var CloudCmd, Util, DOM, CloudFunc;
|
|||
|
||||
return lRet;
|
||||
};
|
||||
|
||||
function process(pAdd, pType, pListener, pElement, pUseCapture){
|
||||
var lElement = (pElement || window),
|
||||
|
||||
lEventProcess = pAdd ?
|
||||
lElement.addEventListener :
|
||||
lElement.removeEventListener,
|
||||
|
||||
lProcessName = pAdd ? 'add' : 'remove',
|
||||
lProcess = Events[lProcessName],
|
||||
|
||||
lRet = pType && lEventProcess,
|
||||
lEvent = '';
|
||||
|
||||
lEventProcess = lEventProcess.bind(lElement);
|
||||
|
||||
if(lRet){
|
||||
if(Util.isString(pType) )
|
||||
lEventProcess(
|
||||
pType,
|
||||
pListener,
|
||||
pUseCapture
|
||||
);
|
||||
else if(Util.isObject(pType)){
|
||||
if(pListener)
|
||||
pElement = pListener;
|
||||
|
||||
for(lEvent in pType)
|
||||
lProcess(
|
||||
lEvent,
|
||||
pType[lEvent],
|
||||
pElement,
|
||||
pUseCapture
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
CacheProto = function(){
|
||||
/* приватный переключатель возможности работы с кэшем */
|
||||
|
|
@ -1347,7 +1382,7 @@ var CloudCmd, Util, DOM, CloudFunc;
|
|||
* @param pKey - 'f1'-'f10'
|
||||
*/
|
||||
this.setButtonKey = function(pKey, pFunc){
|
||||
Events.addClick(CloudCmd.KeysPanel[pKey], pFunc);
|
||||
Events.addClick(pFunc, CloudCmd.KeysPanel[pKey]);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue