<commit_before>/**
 * @description Select multiple albums or photos.
 * @copyright   2015 by <NAME>
 */

multiselect = {

	ids: []

}

multiselect.position = {

	top    : null,
	right  : null,
	bottom : null,
	left   : null

}

multiselect.bind = function() {

	$('.content').on('mousedown', (e) => { if (e.which===1) multiselect.show(e) })

	return true

}

multiselect.isSelected = function(id) {

	let pos = $.inArray(id, multiselect.ids)

	return {
		selected : (pos===-1 ? false : true),
		position : pos
	}

}

multiselect.toggleItem = function(object, id) {

	let selected = multiselect.isSelected(id).selected

	if (selected===false) multiselect.addItem(object, id)
	else                  multiselect.removeItem(object, id)

}

multiselect.addItem = function(object, id) {

	if (album.isSmartID(id)) return
	if (multiselect.isSelected(id).selected===true) return

	multiselect.ids.push(id)
	multiselect.select(object)

}

multiselect.removeItem = function(object, id) {

	let { selected, pos } = multiselect.isSelected(id)

	if (selected===false) return

	multiselect.ids.splice(pos, 1)
	multiselect.deselect(object)

}

multiselect.albumClick = function(e, albumObj) {

	let id = albumObj.attr('data-id')

	if (e.metaKey===true) multiselect.toggleItem(albumObj, id)
	else                  lychee.goto(id)

}

multiselect.photoClick = function(e, photoObj) {

	let id = photoObj.attr('data-id')

	if (e.metaKey===true) multiselect.toggleItem(photoObj, id)
	else                  lychee.goto(album.getID() + '/' + id)

}

multiselect.albumContextMenu = function(e, albumObj) {

	let id       = albumObj.attr('data-id')
	let selected = multiselect.isSelected(id).selected

	if (selected===false) {
		contextMenu.albumMulti(multiselect.ids, e)
		multiselect.ids = []
	} else {
		multiselect.clearSelection()
		contextMenu.album(album.getID(), e)
	}

}

multiselect.photoContextMenu = function(e, photoObj) {

	let id       = photoObj.attr('data-id')
	let selected = multiselect.isSelected(id).selected

	if (selected===false) {
		contextMenu.photoMulti(multiselect.ids, e)
		multiselect.ids = []
	} else {
		multiselect.clearSelection()
		contextMenu.photo(photo.getID(), e)
	}

}

multiselect.clearSelection = function() {

	multiselect.deselect('.photo.active, .album.active')
	multiselect.ids = []

}

multiselect.show = function(e) {

	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()

	sidebar.setSelectable(false)
<commit_msg>Fixed condition in {album,photo}ContextMenu.<commit_after>/**
 * @description Select multiple albums or photos.
 * @copyright   2015 by <NAME>
 */

multiselect = {

	ids: []

}

multiselect.position = {

	top    : null,
	right  : null,
	bottom : null,
	left   : null

}

multiselect.bind = function() {

	$('.content').on('mousedown', (e) => { if (e.which===1) multiselect.show(e) })

	return true

}

multiselect.isSelected = function(id) {

	let pos = $.inArray(id, multiselect.ids)

	return {
		selected : (pos===-1 ? false : true),
		position : pos
	}

}

multiselect.toggleItem = function(object, id) {

	let selected = multiselect.isSelected(id).selected

	if (selected===false) multiselect.addItem(object, id)
	else                  multiselect.removeItem(object, id)

}

multiselect.addItem = function(object, id) {

	if (album.isSmartID(id)) return
	if (multiselect.isSelected(id).selected===true) return

	multiselect.ids.push(id)
	multiselect.select(object)

}

multiselect.removeItem = function(object, id) {

	let { selected, pos } = multiselect.isSelected(id)

	if (selected===false) return

	multiselect.ids.splice(pos, 1)
	multiselect.deselect(object)

}

multiselect.albumClick = function(e, albumObj) {

	let id = albumObj.attr('data-id')

	if (e.metaKey===true) multiselect.toggleItem(albumObj, id)
	else                  lychee.goto(id)

}

multiselect.photoClick = function(e, photoObj) {

	let id = photoObj.attr('data-id')

	if (e.metaKey===true) multiselect.toggleItem(photoObj, id)
	else                  lychee.goto(album.getID() + '/' + id)

}

multiselect.albumContextMenu = function(e, albumObj) {

	let id       = albumObj.attr('data-id')
	let selected = multiselect.isSelected(id).selected

	if (selected!==false) {
		contextMenu.albumMulti(multiselect.ids, e)
		multiselect.ids = []
	} else {
		multiselect.clearSelection()
		contextMenu.album(album.getID(), e)
	}

}

multiselect.photoContextMenu = function(e, photoObj) {

	let id       = photoObj.attr('data-id')
	let selected = multiselect.isSelected(id).selected

	if (selected!==false) {
		contextMenu.photoMulti(multiselect.ids, e)
		multiselect.ids = []
	} else {
		multiselect.clearSelection()
		contextMenu.photo(photo.getID(), e)
	}

}

multiselect.clearSelection = function() {

	multiselect.deselect('.photo.active, .album.active')
	multiselect.ids = []

}

multiselect.show = function(e) {

	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()

	sidebar.setSelectable(false)

{'fraction_non_alphanumeric': 0.1492756280946268, 'fraction_numerical': 0.0029341646799926646, 'mean_word_length': 3.496290189612531, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1523128', 'n_tokens_mistral': 1974, 'n_tokens_neox': 1887, 'n_words': 345}