mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-18 00:47:01 +00:00
feature(listeners) changeLinks: set events to one main files element
This commit is contained in:
parent
6bb769cbb4
commit
96cd5e4a90
1 changed files with 40 additions and 37 deletions
|
|
@ -75,13 +75,12 @@ var Util, DOM, CloudCmd;
|
|||
* @param panelId
|
||||
*/
|
||||
this.changeLinks = function(panelId) {
|
||||
var i, n, a, ai, current, link, loadDir, events, id, isDir,
|
||||
var i, n, a, ai, current, link, loadDir, events, id,
|
||||
url = CloudCmd.HOST,
|
||||
loadDirOnce = CloudCmd.loadDir(),
|
||||
panel = DOM.getById(panelId),
|
||||
pathElement = DOM.getByDataName('js-path', panel),
|
||||
filesElement = DOM.getByClass('files', panel),
|
||||
|
||||
loadDirOnce = CloudCmd.loadDir(),
|
||||
files = filesElement.children,
|
||||
pathLinks = DOM.getByClass('links', pathElement).children,
|
||||
clearStorage = DOM.getByClass('clear-storage', pathElement),
|
||||
|
|
@ -94,15 +93,27 @@ var Util, DOM, CloudCmd;
|
|||
DOM.preventDefault(event);
|
||||
},
|
||||
|
||||
onDblClick = function(event) {
|
||||
var current = getLIElement(event.target),
|
||||
isDir = DOM.isCurrentIsDir(current);
|
||||
|
||||
if (isDir)
|
||||
loadDirOnce(event);
|
||||
},
|
||||
|
||||
onTouch = function(event) {
|
||||
setCurrentFile(event, function(element) {
|
||||
var isCurrent = DOM.isCurrentFile(element);
|
||||
|
||||
if (isCurrent)
|
||||
loadDirOnce(event);
|
||||
else
|
||||
DOM.setCurrentFile(element);
|
||||
});
|
||||
var current = getLIElement(event.target),
|
||||
isDir = DOM.isCurrentIsDir(current);
|
||||
|
||||
if (isDir)
|
||||
setCurrentFile(event, function(element) {
|
||||
var isCurrent = DOM.isCurrentFile(element);
|
||||
|
||||
if (isCurrent)
|
||||
loadDirOnce(event);
|
||||
else
|
||||
DOM.setCurrentFile(element);
|
||||
});
|
||||
};
|
||||
|
||||
/* ставим загрузку гифа на клик*/
|
||||
|
|
@ -122,12 +133,20 @@ var Util, DOM, CloudCmd;
|
|||
Events.addClick(loadDir, ai);
|
||||
}
|
||||
|
||||
Events.add({
|
||||
'mousedown' : setCurrentFile,
|
||||
'contextmenu' : onContextMenu,
|
||||
'dragstart' : onDragStart,
|
||||
'click' : onClick,
|
||||
'dblclick' : onDblClick,
|
||||
'touchstart' : onTouch
|
||||
}, filesElement);
|
||||
|
||||
a = DOM.getByTag('a', filesElement);
|
||||
|
||||
n = a.length;
|
||||
for (i = 0; i < n ; i++) {
|
||||
current = files[i];
|
||||
isDir = DOM.isCurrentIsDir(current);
|
||||
ai = a[i];
|
||||
|
||||
if (ai.title)
|
||||
|
|
@ -138,36 +157,20 @@ var Util, DOM, CloudCmd;
|
|||
id += '(' + panelId + ')';
|
||||
|
||||
current.id = id;
|
||||
|
||||
events = {
|
||||
'mousedown' : setCurrentFile,
|
||||
'contextmenu' : onContextMenu,
|
||||
'dragstart' : onDragStart,
|
||||
'click' : onClick
|
||||
};
|
||||
|
||||
if (isDir)
|
||||
Util.copyObj(events, {
|
||||
'dblclick' : loadDirOnce,
|
||||
'touchstart' : onTouch
|
||||
});
|
||||
|
||||
Events.add(events, current);
|
||||
}
|
||||
};
|
||||
|
||||
function onContextMenu(event) {
|
||||
var target,
|
||||
isFunc = Util.isFunction(CloudCmd.Menu),
|
||||
ret = true,
|
||||
Key = CloudCmd.Key;
|
||||
|
||||
/* getting html element
|
||||
* currentTarget - DOM event
|
||||
* target - jquery event
|
||||
*/
|
||||
target = event.currentTarget || event.target;
|
||||
DOM.setCurrentFile(target);
|
||||
var element = getLIElement(event.target),
|
||||
isFunc = Util.isFunction(CloudCmd.Menu),
|
||||
ret = true,
|
||||
Key = CloudCmd.Key;
|
||||
|
||||
DOM.setCurrentFile(element);
|
||||
|
||||
if (isFunc) {
|
||||
CloudCmd.Menu({
|
||||
|
|
@ -190,8 +193,8 @@ var Util, DOM, CloudCmd;
|
|||
var element = getLIElement(event.target),
|
||||
EXT = 'json',
|
||||
isDir = Info.isDir,
|
||||
link = element.href,
|
||||
name = element.textContent;
|
||||
link = DOM.getCurrentLink(element),
|
||||
name = DOM.getCurrentName(element);
|
||||
|
||||
/* if it's directory - adding json extension */
|
||||
if (isDir) {
|
||||
|
|
@ -206,7 +209,7 @@ var Util, DOM, CloudCmd;
|
|||
}
|
||||
|
||||
function getLIElement(element) {
|
||||
var tag = element.tagName;
|
||||
var tag = element.tagName;
|
||||
|
||||
if (tag !== 'LI')
|
||||
do {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue