diff --git a/src/scripts/init.js b/src/scripts/init.js index fa981b8..af0d349 100755 --- a/src/scripts/init.js +++ b/src/scripts/init.js @@ -96,12 +96,12 @@ $(document).ready(function() { $(document) // Navigation - .on('click', '.album', function() { lychee.goto($(this).attr('data-id')) }) - .on('click', '.photo', function() { lychee.goto(album.getID() + '/' + $(this).attr('data-id')) }) + .on('click', '.album', function(e) { multiselect.albumClick(e, $(this)) }) + .on('click', '.photo', function(e) { multiselect.photoClick(e, $(this)) }) // Context Menu - .on('contextmenu', '.photo', function(e) { contextMenu.photo(photo.getID(), e) }) - .on('contextmenu', '.album', function(e) { contextMenu.album(album.getID(), e) }) + .on('contextmenu', '.photo', function(e) { multiselect.photoContextMenu(e, $(this)) }) + .on('contextmenu', '.album', function(e) { multiselect.albumContextMenu(e, $(this)) }) // Upload .on('change', '#upload_files', function() { basicModal.close(); upload.start.local(this.files) }) diff --git a/src/scripts/multiselect.js b/src/scripts/multiselect.js index 5ee0084..c1bacd5 100644 --- a/src/scripts/multiselect.js +++ b/src/scripts/multiselect.js @@ -3,7 +3,11 @@ * @copyright 2015 by Tobias Reich */ -multiselect = {} +multiselect = { + + ids : [] + +} multiselect.position = { @@ -22,6 +26,72 @@ multiselect.bind = function() { } +multiselect.toggleItem = function(object, id) { + + if (album.isSmartID(id)) return + + let pos = $.inArray(id, multiselect.ids) + if (pos!=-1) { + multiselect.ids.splice(pos, 1) + multiselect.deselect(object) + } + else { + multiselect.ids.push(id) + multiselect.select(object) + } + +} + +multiselect.albumClick = function(e, albumObj) { + + let id = albumObj.attr('data-id') + + if (e.ctrlKey) multiselect.toggleItem(albumObj, id) + else lychee.goto(id) + +} + +multiselect.photoClick = function(e, photoObj) { + + let id = photoObj.attr('data-id') + + if (e.ctrlKey) multiselect.toggleItem(photoObj, id) + else lychee.goto(album.getID() + '/' + id) + +} + +multiselect.albumContextMenu = function(e, albumObj) { + + let id = albumObj.attr('data-id') + + if ($.inArray(id, multiselect.ids)!=-1) { + contextMenu.albumMulti(multiselect.ids, e) + } + else { + multiselect.deselect('.photo.active, .album.active') + contextMenu.album(album.getID(), e) + } + + multiselect.ids = [] + +} + +multiselect.photoContextMenu = function(e, photoObj) { + + let id = photoObj.attr('data-id') + + if ($.inArray(id, multiselect.ids)!=-1) { + contextMenu.photoMulti(multiselect.ids, e) + } + else { + multiselect.deselect('.photo.active, .album.active') + contextMenu.photo(photo.getID(), e) + } + + multiselect.ids = [] + +} + multiselect.show = function(e) { if (lychee.publicMode) return false @@ -234,6 +304,9 @@ multiselect.deselect = function(id) { multiselect.close = function() { + multiselect.deselect('.photo.active, .album.active') + multiselect.ids = [] + sidebar.setSelectable(true) multiselect.stopResize()