You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
lychee/src/scripts/multiselect.js

232 lines
5.4 KiB

10 years ago
/**
* @description Select multiple albums or photos.
10 years ago
*/
10 years ago
multiselect = {}
10 years ago
10 years ago
multiselect.position = {
10 years ago
top : null,
right : null,
bottom : null,
left : null
10 years ago
10 years ago
}
10 years ago
multiselect.bind = function() {
$('.content').on('mousedown', (e) => { if (e.which===1) multiselect.show(e) })
return true
}
10 years ago
multiselect.show = function(e) {
10 years ago
if (lychee.publicMode) return false
if (!visible.albums() && !visible.album()) return false
if ($('.album:hover, .photo:hover').length!==0) return false
if (visible.search()) return false
if (visible.multiselect()) $('#multiselect').remove()
10 years ago
sidebar.setSelectable(false)
multiselect.position.top = e.pageY
multiselect.position.right = -1 * (e.pageX - $(document).width())
multiselect.position.bottom = -1 * (multiselect.position.top - $(window).height())
multiselect.position.left = e.pageX
10 years ago
$('body').append(build.multiselect(multiselect.position.top, multiselect.position.left))
$(document)
.on('mousemove', multiselect.resize)
.on('mouseup', (e) => { if (e.which===1) multiselect.getSelection(e) })
10 years ago
10 years ago
}
10 years ago
10 years ago
multiselect.selectAll = function() {
10 years ago
if (lychee.publicMode) return false
if (visible.search()) return false
if (!visible.albums() && !visible.album) return false
if (visible.multiselect()) $('#multiselect').remove()
10 years ago
sidebar.setSelectable(false)
10 years ago
multiselect.position.top = 70
multiselect.position.right = 40
multiselect.position.bottom = 90
multiselect.position.left = 20
$('body').append(build.multiselect(multiselect.position.top, multiselect.position.left))
10 years ago
let documentSize = {
width : $(document).width(),
height : $(document).height()
}
10 years ago
let newSize = {
width : documentSize.width - multiselect.position.right + 2,
height : documentSize.height - multiselect.position.bottom
}
10 years ago
let e = {
pageX : documentSize.width - (multiselect.position.right / 2),
pageY : documentSize.height - multiselect.position.bottom
}
10 years ago
$('#multiselect').css(newSize)
10 years ago
multiselect.getSelection(e)
10 years ago
10 years ago
}
10 years ago
10 years ago
multiselect.resize = function(e) {
10 years ago
if (multiselect.position.top === null ||
multiselect.position.right === null ||
multiselect.position.bottom === null ||
multiselect.position.left === null) return false
let newSize = {}
let documentSize = {}
// Get the position of the mouse
let mousePos = {
x : e.pageX,
y : e.pageY
}
// Default CSS
let newCSS = {
top : null,
bottom : null,
height : null,
left : null,
right : null,
width : null
}
10 years ago
if (mousePos.y>=multiselect.position.top) {
10 years ago
documentSize.height = $(document).height()
10 years ago
10 years ago
// Do not leave the screen
newSize.height = mousePos.y - multiselect.position.top
if ((multiselect.position.top + newSize.height)>=documentSize.height) {
newSize.height -= (multiselect.position.top + newSize.height) - documentSize.height + 2
}
10 years ago
newCSS.top = multiselect.position.top
newCSS.bottom = 'inherit'
newCSS.height = newSize.height
10 years ago
10 years ago
} else {
10 years ago
newCSS.top = 'inherit'
newCSS.bottom = multiselect.position.bottom
newCSS.height = multiselect.position.top - e.pageY
10 years ago
10 years ago
}
10 years ago
if (mousePos.x>=multiselect.position.left) {
documentSize.width = $(document).width()
10 years ago
10 years ago
// Do not leave the screen
newSize.width = mousePos.x - multiselect.position.left
if ((multiselect.position.left + newSize.width)>=documentSize.width) {
newSize.width -= (multiselect.position.left + newSize.width) - documentSize.width + 2
}
10 years ago
newCSS.right = 'inherit'
newCSS.left = multiselect.position.left
newCSS.width = newSize.width
10 years ago
10 years ago
} else {
10 years ago
newCSS.right = multiselect.position.right
newCSS.left = 'inherit'
newCSS.width = multiselect.position.left - e.pageX
10 years ago
10 years ago
}
10 years ago
// Updated all CSS properties at once
$('#multiselect').css(newCSS)
10 years ago
}
10 years ago
10 years ago
multiselect.stopResize = function() {
10 years ago
if (multiselect.position.top!==null) $(document).off('mousemove mouseup')
10 years ago
10 years ago
}
10 years ago
10 years ago
multiselect.getSize = function() {
10 years ago
if (!visible.multiselect()) return false
let $elem = $('#multiselect')
let offset = $elem.offset()
10 years ago
10 years ago
return {
top : offset.top,
left : offset.left,
width : parseInt($elem.css('width').replace('px', '')),
height : parseInt($elem.css('height').replace('px', ''))
}
10 years ago
10 years ago
}
10 years ago
10 years ago
multiselect.getSelection = function(e) {
10 years ago
let tolerance = 150
let ids = []
let size = multiselect.getSize()
10 years ago
if (visible.contextMenu()) return false
if (!visible.multiselect()) return false
10 years ago
10 years ago
$('.photo, .album').each(function() {
10 years ago
let offset = $(this).offset()
10 years ago
if (offset.top>=(size.top - tolerance) &&
offset.left>=(size.left - tolerance) &&
(offset.top + 206)<=(size.top + size.height + tolerance) &&
(offset.left + 206)<=(size.left + size.width + tolerance)) {
10 years ago
let id = $(this).data('id')
10 years ago
if (id!=='0' && id!==0 && id!=='f' && id!=='s' && id!=='r' && id!=null) {
10 years ago
ids.push(id)
$(this).addClass('active')
10 years ago
}
}
10 years ago
})
10 years ago
if (ids.length!==0 && visible.album()) contextMenu.photoMulti(ids, e)
else if (ids.length!==0 && visible.albums()) contextMenu.albumMulti(ids, e)
else multiselect.close()
10 years ago
10 years ago
}
10 years ago
10 years ago
multiselect.close = function() {
10 years ago
sidebar.setSelectable(true)
multiselect.stopResize()
10 years ago
multiselect.position.top = null
multiselect.position.right = null
multiselect.position.bottom = null
multiselect.position.left = null
10 years ago
lychee.animate('#multiselect', 'fadeOut')
setTimeout(() => $('#multiselect').remove(), 300)
10 years ago
10 years ago
}