|
|
|
@ -299,6 +299,33 @@ define([
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
APP.selectedFiles = [];
|
|
|
|
|
|
|
|
|
|
var isElementSelected = function ($element) {
|
|
|
|
|
var elementId = $element.data("path").slice(-1)[0];
|
|
|
|
|
return APP.selectedFiles.indexOf(elementId) !== -1;
|
|
|
|
|
};
|
|
|
|
|
var selectElement = function ($element) {
|
|
|
|
|
var elementId = $element.data("path").slice(-1)[0];
|
|
|
|
|
if (APP.selectedFiles.indexOf(elementId) === -1) {
|
|
|
|
|
APP.selectedFiles.push(elementId);
|
|
|
|
|
}
|
|
|
|
|
$element.addClass("cp-app-drive-element-selected");
|
|
|
|
|
};
|
|
|
|
|
var unselectElement = function ($element) {
|
|
|
|
|
var elementId = $element.data("path").slice(-1)[0];
|
|
|
|
|
var index = APP.selectedFiles.indexOf(elementId);
|
|
|
|
|
if (index !== -1) {
|
|
|
|
|
APP.selectedFiles.splice(index, 1);
|
|
|
|
|
}
|
|
|
|
|
$element.removeClass("cp-app-drive-element-selected");
|
|
|
|
|
};
|
|
|
|
|
var findSelectedElements = function () {
|
|
|
|
|
return $(".cp-app-drive-element-selected");
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var createContextMenu = function () {
|
|
|
|
|
var menu = h('div.cp-contextmenu.dropdown.cp-unselectable', [
|
|
|
|
|
h('ul.dropdown-menu', {
|
|
|
|
@ -564,7 +591,8 @@ define([
|
|
|
|
|
var sel = {};
|
|
|
|
|
|
|
|
|
|
var removeSelected = function (keepObj) {
|
|
|
|
|
$('.cp-app-drive-element-selected').removeClass("cp-app-drive-element-selected");
|
|
|
|
|
APP.selectedFiles = [];
|
|
|
|
|
findSelectedElements().removeClass("cp-app-drive-element-selected");
|
|
|
|
|
var $container = $driveToolbar.find('#cp-app-drive-toolbar-contextbuttons');
|
|
|
|
|
if (!$container.length) { return; }
|
|
|
|
|
$container.html('');
|
|
|
|
@ -674,7 +702,9 @@ define([
|
|
|
|
|
delete sel.move;
|
|
|
|
|
$content.find('.cp-app-drive-element-selected-tmp')
|
|
|
|
|
.removeClass('cp-app-drive-element-selected-tmp')
|
|
|
|
|
.addClass('cp-app-drive-element-selected');
|
|
|
|
|
.each(function (idx, element) {
|
|
|
|
|
selectElement($(element));
|
|
|
|
|
});
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
@ -709,7 +739,9 @@ define([
|
|
|
|
|
// Ctrl+A select all
|
|
|
|
|
if (e.which === 65 && (e.ctrlKey || (e.metaKey && APP.isMac))) {
|
|
|
|
|
$content.find('.cp-app-drive-element:not(.cp-app-drive-element-selected)')
|
|
|
|
|
.addClass('cp-app-drive-element-selected');
|
|
|
|
|
.each(function (idx, element) {
|
|
|
|
|
selectElement($(element));
|
|
|
|
|
});
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -722,7 +754,7 @@ define([
|
|
|
|
|
APP.onElementClick(ev, $(el));
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var $selection = $content.find('.cp-app-drive-element.cp-app-drive-element-selected');
|
|
|
|
|
var $selection = findSelectedElements();
|
|
|
|
|
if ($selection.length === 0) { return void click($elements.first()[0]); }
|
|
|
|
|
|
|
|
|
|
var lastIndex = typeof sel.endSelected === "number" ? sel.endSelected :
|
|
|
|
@ -841,12 +873,12 @@ define([
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
removeInput();
|
|
|
|
|
removeSelected();
|
|
|
|
|
var $name = $element.find('.cp-app-drive-element-name');
|
|
|
|
|
if (!$name.length) {
|
|
|
|
|
$name = $element.find('> .cp-app-drive-element');
|
|
|
|
|
}
|
|
|
|
|
$name.hide();
|
|
|
|
|
var isFolder = $element.is(".cp-app-drive-element-folder:not(.cp-app-drive-element-sharedf)");
|
|
|
|
|
var el = manager.find(path);
|
|
|
|
|
var name = manager.isFile(el) ? manager.getTitle(el) : path[path.length - 1];
|
|
|
|
|
if (manager.isSharedFolder(el)) {
|
|
|
|
@ -868,14 +900,21 @@ define([
|
|
|
|
|
var newName = $input.val();
|
|
|
|
|
if (JSON.stringify(path) === JSON.stringify(currentPath)) {
|
|
|
|
|
manager.rename(path, $input.val(), function () {
|
|
|
|
|
renameFoldersOpened(path, newName);
|
|
|
|
|
path[path.length - 1] = newName;
|
|
|
|
|
if (isFolder) {
|
|
|
|
|
renameFoldersOpened(path, newName);
|
|
|
|
|
path[path.length - 1] = newName;
|
|
|
|
|
}
|
|
|
|
|
APP.displayDirectory(path);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
manager.rename(path, $input.val(), function () {
|
|
|
|
|
renameFoldersOpened(path, newName);
|
|
|
|
|
if (isFolder) {
|
|
|
|
|
renameFoldersOpened(path, newName);
|
|
|
|
|
unselectElement($element);
|
|
|
|
|
$element.data("path", $element.data("path").slice(0, -1).concat(newName));
|
|
|
|
|
selectElement($element);
|
|
|
|
|
}
|
|
|
|
|
refresh();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
@ -896,7 +935,6 @@ define([
|
|
|
|
|
|
|
|
|
|
// We don't want to open the file/folder when clicking on the input
|
|
|
|
|
$input.on('click dblclick', function (e) {
|
|
|
|
|
removeSelected();
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
});
|
|
|
|
|
// Remove the browser ability to drag text from the input to avoid
|
|
|
|
@ -1116,8 +1154,9 @@ define([
|
|
|
|
|
|
|
|
|
|
var getSelectedPaths = function ($element) {
|
|
|
|
|
var paths = [];
|
|
|
|
|
if ($('.cp-app-drive-element-selected').length > 1) {
|
|
|
|
|
var $selected = $('.cp-app-drive-element-selected');
|
|
|
|
|
if ($element.length === 0) { return paths; }
|
|
|
|
|
if (findSelectedElements().length > 1) {
|
|
|
|
|
var $selected = findSelectedElements();
|
|
|
|
|
$selected.each(function (idx, elmt) {
|
|
|
|
|
var ePath = $(elmt).data('path');
|
|
|
|
|
if (ePath) {
|
|
|
|
@ -1146,7 +1185,7 @@ define([
|
|
|
|
|
} else {
|
|
|
|
|
$driveToolbar.find('cp-app-drive-toolbar-emptytrash').hide();
|
|
|
|
|
}
|
|
|
|
|
var $li = $content.find('.cp-app-drive-element-selected');
|
|
|
|
|
var $li = findSelectedElements();
|
|
|
|
|
if ($li.length === 0) {
|
|
|
|
|
$li = findDataHolder($tree.find('.cp-app-drive-element-active'));
|
|
|
|
|
}
|
|
|
|
@ -1213,6 +1252,7 @@ define([
|
|
|
|
|
if (pos+eh <= h && pos >= 0) { return; }
|
|
|
|
|
$content.scrollTop(v);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Add the "selected" class to the "li" corresponding to the clicked element
|
|
|
|
|
var onElementClick = APP.onElementClick = function (e, $element) {
|
|
|
|
|
// If "Ctrl" is pressed, do not remove the current selection
|
|
|
|
@ -1249,23 +1289,23 @@ define([
|
|
|
|
|
var $el;
|
|
|
|
|
removeSelected(true);
|
|
|
|
|
sel.oldSelection.forEach(function (el) {
|
|
|
|
|
if (!$(el).hasClass("cp-app-drive-element-selected")) {
|
|
|
|
|
$(el).addClass("cp-app-drive-element-selected");
|
|
|
|
|
if (!isElementSelected($(el))) {
|
|
|
|
|
selectElement($(el));
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
for (var i = Math.min(sel.startSelected, sel.endSelected);
|
|
|
|
|
i <= Math.max(sel.startSelected, sel.endSelected);
|
|
|
|
|
i++) {
|
|
|
|
|
$el = $($elements.get(i));
|
|
|
|
|
if (!$el.hasClass("cp-app-drive-element-selected")) {
|
|
|
|
|
$el.addClass("cp-app-drive-element-selected");
|
|
|
|
|
if (!isElementSelected($el)) {
|
|
|
|
|
selectElement($el);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (!$element.hasClass("cp-app-drive-element-selected")) {
|
|
|
|
|
$element.addClass("cp-app-drive-element-selected");
|
|
|
|
|
if (!isElementSelected($element)) {
|
|
|
|
|
selectElement($element);
|
|
|
|
|
} else {
|
|
|
|
|
$element.removeClass("cp-app-drive-element-selected");
|
|
|
|
|
unselectElement($element);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
updateContextButton();
|
|
|
|
@ -1352,6 +1392,17 @@ define([
|
|
|
|
|
} else {
|
|
|
|
|
var $element = findDataHolder($(e.target));
|
|
|
|
|
|
|
|
|
|
// if clicked from tree
|
|
|
|
|
var fromTree = $element.closest("#cp-app-drive-tree").length;
|
|
|
|
|
if (fromTree) {
|
|
|
|
|
removeSelected();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// if clicked on non selected element
|
|
|
|
|
if (!isElementSelected($element)) {
|
|
|
|
|
removeSelected();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (type === 'trash' && !$element.data('path')) { return; }
|
|
|
|
|
|
|
|
|
|
if (!$element.length) {
|
|
|
|
@ -1360,8 +1411,8 @@ define([
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!$element.hasClass('cp-app-drive-element-selected')) {
|
|
|
|
|
onElementClick(undefined, $element);
|
|
|
|
|
if (!isElementSelected($element)) {
|
|
|
|
|
selectElement($element);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
paths = getSelectedPaths($element);
|
|
|
|
@ -1398,6 +1449,7 @@ define([
|
|
|
|
|
var newCb = function () {
|
|
|
|
|
paths.forEach(function (path) {
|
|
|
|
|
moveFoldersOpened(path, newPath);
|
|
|
|
|
// removeSelected();
|
|
|
|
|
});
|
|
|
|
|
cb();
|
|
|
|
|
};
|
|
|
|
@ -1431,6 +1483,7 @@ define([
|
|
|
|
|
if (!res) { return; }
|
|
|
|
|
manager.delete(pathsList, function () {
|
|
|
|
|
pathsList.forEach(removeFoldersOpened);
|
|
|
|
|
removeSelected();
|
|
|
|
|
refresh();
|
|
|
|
|
});
|
|
|
|
|
}, null, true);
|
|
|
|
@ -1441,7 +1494,7 @@ define([
|
|
|
|
|
var paths = [];
|
|
|
|
|
var $element = findDataHolder($(ev.target));
|
|
|
|
|
if ($element.hasClass('cp-app-drive-element-selected')) {
|
|
|
|
|
var $selected = $('.cp-app-drive-element-selected');
|
|
|
|
|
var $selected = findSelectedElements();
|
|
|
|
|
$selected.each(function (idx, elmt) {
|
|
|
|
|
var ePath = $(elmt).data('path');
|
|
|
|
|
if (ePath) {
|
|
|
|
@ -1458,7 +1511,7 @@ define([
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
removeSelected();
|
|
|
|
|
$element.addClass('cp-app-drive-element-selected');
|
|
|
|
|
selectElement($element);
|
|
|
|
|
var val = manager.find(path);
|
|
|
|
|
if (!val) { return; } // The element is not in the object
|
|
|
|
|
paths = [{
|
|
|
|
@ -1738,12 +1791,9 @@ define([
|
|
|
|
|
draggable: true,
|
|
|
|
|
'class': 'cp-app-drive-element-row'
|
|
|
|
|
});
|
|
|
|
|
if (!isFolder && Array.isArray(APP.selectedFiles)) {
|
|
|
|
|
var idx = APP.selectedFiles.indexOf(element);
|
|
|
|
|
if (idx !== -1) {
|
|
|
|
|
$element.addClass('cp-app-drive-element-selected');
|
|
|
|
|
APP.selectedFiles.splice(idx, 1);
|
|
|
|
|
}
|
|
|
|
|
$element.data('path', newPath);
|
|
|
|
|
if (isElementSelected($element)) {
|
|
|
|
|
selectElement($element);
|
|
|
|
|
}
|
|
|
|
|
$element.prepend($icon).dblclick(function () {
|
|
|
|
|
if (isFolder) {
|
|
|
|
@ -1759,11 +1809,10 @@ define([
|
|
|
|
|
addFileData(element, $element);
|
|
|
|
|
}
|
|
|
|
|
$element.addClass(liClass);
|
|
|
|
|
$element.data('path', newPath);
|
|
|
|
|
addDragAndDropHandlers($element, newPath, isFolder, !isTrash);
|
|
|
|
|
$element.click(function(e) {
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
onElementClick(e, $element, newPath);
|
|
|
|
|
onElementClick(e, $element);
|
|
|
|
|
});
|
|
|
|
|
if (!isTrash) {
|
|
|
|
|
$element.contextmenu(openContextMenu('tree'));
|
|
|
|
@ -2551,22 +2600,19 @@ define([
|
|
|
|
|
'class': 'cp-app-drive-element cp-app-drive-element-file cp-app-drive-element-row' + roClass,
|
|
|
|
|
draggable: draggable
|
|
|
|
|
});
|
|
|
|
|
if (Array.isArray(APP.selectedFiles)) {
|
|
|
|
|
var sidx = APP.selectedFiles.indexOf(id);
|
|
|
|
|
if (sidx !== -1) {
|
|
|
|
|
$element.addClass('cp-app-drive-element-selected');
|
|
|
|
|
APP.selectedFiles.splice(sidx, 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var path = [rootName, idx];
|
|
|
|
|
$element.data('path', path);
|
|
|
|
|
if (isElementSelected($element)) {
|
|
|
|
|
selectElement($element);
|
|
|
|
|
}
|
|
|
|
|
$element.prepend($icon).dblclick(function () {
|
|
|
|
|
openFile(id);
|
|
|
|
|
});
|
|
|
|
|
addFileData(id, $element);
|
|
|
|
|
var path = [rootName, idx];
|
|
|
|
|
$element.data('path', path);
|
|
|
|
|
$element.click(function(e) {
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
onElementClick(e, $element, path);
|
|
|
|
|
onElementClick(e, $element);
|
|
|
|
|
});
|
|
|
|
|
$element.contextmenu(openContextMenu('default'));
|
|
|
|
|
$element.data('context', 'default');
|
|
|
|
@ -2693,8 +2739,8 @@ define([
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
if (manager.isInTrashRoot(parentPath)) { parentPath = [TRASH]; }
|
|
|
|
|
else { parentPath.pop(); }
|
|
|
|
|
APP.selectedFiles = [r.id];
|
|
|
|
|
APP.displayDirectory(parentPath);
|
|
|
|
|
APP.selectedFiles = path.slice(-1);
|
|
|
|
|
}).appendTo($openDir);
|
|
|
|
|
}
|
|
|
|
|
$('<a>').text(Messages.fc_prop).click(function () {
|
|
|
|
@ -2785,7 +2831,7 @@ define([
|
|
|
|
|
$element.data('path', path);
|
|
|
|
|
$element.click(function(e) {
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
onElementClick(e, $element, path);
|
|
|
|
|
onElementClick(e, $element);
|
|
|
|
|
});
|
|
|
|
|
$element.contextmenu(openContextMenu('default'));
|
|
|
|
|
$element.data('context', 'default');
|
|
|
|
@ -3009,7 +3055,7 @@ define([
|
|
|
|
|
$context.click(function (e) {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
var $li = $content.find('.cp-app-drive-element-selected');
|
|
|
|
|
var $li = findSelectedElements();
|
|
|
|
|
if ($li.length !== 1) {
|
|
|
|
|
$li = findDataHolder($tree.find('.cp-app-drive-element-active'));
|
|
|
|
|
}
|
|
|
|
@ -3091,7 +3137,7 @@ define([
|
|
|
|
|
}
|
|
|
|
|
});*/
|
|
|
|
|
|
|
|
|
|
var $sel = $content.find('.cp-app-drive-element-selected');
|
|
|
|
|
var $sel = findSelectedElements();
|
|
|
|
|
if ($sel.length) {
|
|
|
|
|
$sel[0].scrollIntoView();
|
|
|
|
|
} else {
|
|
|
|
@ -3103,6 +3149,9 @@ define([
|
|
|
|
|
if (history.isHistoryMode) {
|
|
|
|
|
return void _displayDirectory(path, force);
|
|
|
|
|
}
|
|
|
|
|
if (!manager.comparePath(currentPath, path)) {
|
|
|
|
|
removeSelected();
|
|
|
|
|
}
|
|
|
|
|
updateObject(sframeChan, proxy, function () {
|
|
|
|
|
copyObjectValue(files, proxy.drive);
|
|
|
|
|
updateSharedFolders(sframeChan, manager, files, folders, function () {
|
|
|
|
@ -3451,6 +3500,7 @@ define([
|
|
|
|
|
if (!res) { return; }
|
|
|
|
|
manager.delete(pathsList, function () {
|
|
|
|
|
pathsList.forEach(removeFoldersOpened);
|
|
|
|
|
removeSelected();
|
|
|
|
|
refresh();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
@ -3694,16 +3744,15 @@ define([
|
|
|
|
|
var parentPath = paths[0].path.slice();
|
|
|
|
|
if (manager.isInTrashRoot(parentPath)) { parentPath = [TRASH]; }
|
|
|
|
|
else { parentPath.pop(); }
|
|
|
|
|
el = manager.find(paths[0].path);
|
|
|
|
|
APP.selectedFiles = [el];
|
|
|
|
|
APP.displayDirectory(parentPath);
|
|
|
|
|
APP.selectedFiles = paths[0].path.slice(-1);
|
|
|
|
|
}
|
|
|
|
|
APP.hideMenu();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$content.on("keydown", function (e) {
|
|
|
|
|
if (e.which === 113) {
|
|
|
|
|
var paths = $contextMenu.data('paths');
|
|
|
|
|
$(window).on("keydown", function (e) {
|
|
|
|
|
if (e.which === 113) { // if F2 key pressed
|
|
|
|
|
var paths = getSelectedPaths(findSelectedElements().first());
|
|
|
|
|
if (paths.length !== 1) { return; }
|
|
|
|
|
displayRenameInput(paths[0].element, paths[0].path);
|
|
|
|
|
}
|
|
|
|
@ -3737,7 +3786,7 @@ define([
|
|
|
|
|
if (manager.isPathIn(currentPath, [FILES_DATA]) && APP.loggedIn) {
|
|
|
|
|
return; // We can't remove elements directly from filesData
|
|
|
|
|
}
|
|
|
|
|
var $selected = $('.cp-app-drive-element-selected');
|
|
|
|
|
var $selected = findSelectedElements();
|
|
|
|
|
if (!$selected.length) { return; }
|
|
|
|
|
var paths = [];
|
|
|
|
|
var isTrash = manager.isPathIn(currentPath, [TRASH]);
|
|
|
|
|