Updated photo.js (ES2015)
This commit is contained in:
parent
1987286efc
commit
f3c4662d2c
BIN
dist/main.js
vendored
Executable file → Normal file
BIN
dist/main.js
vendored
Executable file → Normal file
Binary file not shown.
@ -286,10 +286,10 @@ contextMenu.sharePhoto = function(photoID, e) {
|
|||||||
let items = [
|
let items = [
|
||||||
{ type: 'item', title: `<input readonly id="link" value="${ link }">`, fn: () => {}, class: 'noHover' },
|
{ type: 'item', title: `<input readonly id="link" value="${ link }">`, fn: () => {}, class: 'noHover' },
|
||||||
{ type: 'separator' },
|
{ type: 'separator' },
|
||||||
{ type: 'item', title: build.iconic('twitter', iconClass) + 'Twitter', fn: () => photo.share(photoID, 0) },
|
{ type: 'item', title: build.iconic('twitter', iconClass) + 'Twitter', fn: () => photo.share(photoID, 'twitter') },
|
||||||
{ type: 'item', title: build.iconic('facebook', iconClass) + 'Facebook', fn: () => photo.share(photoID, 1) },
|
{ type: 'item', title: build.iconic('facebook', iconClass) + 'Facebook', fn: () => photo.share(photoID, 'facebook') },
|
||||||
{ type: 'item', title: build.iconic('envelope-closed') + 'Mail', fn: () => photo.share(photoID, 2) },
|
{ type: 'item', title: build.iconic('envelope-closed') + 'Mail', fn: () => photo.share(photoID, 'mail') },
|
||||||
{ type: 'item', title: build.iconic('dropbox', iconClass) + 'Dropbox', fn: () => photo.share(photoID, 3) },
|
{ type: 'item', title: build.iconic('dropbox', iconClass) + 'Dropbox', fn: () => photo.share(photoID, 'dropbox') },
|
||||||
{ type: 'item', title: build.iconic('link-intact') + 'Direct Link', fn: () => window.open(photo.getDirectLink()) },
|
{ type: 'item', title: build.iconic('link-intact') + 'Direct Link', fn: () => window.open(photo.getDirectLink()) },
|
||||||
{ type: 'separator' },
|
{ type: 'separator' },
|
||||||
{ type: 'item', title: build.iconic('ban') + 'Make Private', fn: () => photo.setPublic(photoID) }
|
{ type: 'item', title: build.iconic('ban') + 'Make Private', fn: () => photo.setPublic(photoID) }
|
||||||
|
@ -1,33 +1,30 @@
|
|||||||
/**
|
/**
|
||||||
* @description Takes care of every action a photo can handle and execute.
|
* @description Takes care of every action a photo can handle and execute.
|
||||||
* @copyright 2015 by Tobias Reich
|
* @copyright 2015 by Tobias Reich
|
||||||
*/
|
*/
|
||||||
|
|
||||||
photo = {
|
photo = {
|
||||||
|
|
||||||
json: null,
|
json : null,
|
||||||
cache: null
|
cache : null
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
photo.getID = function() {
|
photo.getID = function() {
|
||||||
|
|
||||||
var id = null;
|
let id = null
|
||||||
|
|
||||||
if (photo.json) id = photo.json.id;
|
if (photo.json) id = photo.json.id
|
||||||
else id = $('.photo:hover, .photo.active').attr('data-id');
|
else id = $('.photo:hover, .photo.active').attr('data-id')
|
||||||
|
|
||||||
if ($.isNumeric(id)===true) return id;
|
if ($.isNumeric(id)===true) return id
|
||||||
else return false;
|
else return false
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
photo.load = function(photoID, albumID) {
|
photo.load = function(photoID, albumID) {
|
||||||
|
|
||||||
var params,
|
let params = {
|
||||||
checkPasswd;
|
|
||||||
|
|
||||||
params = {
|
|
||||||
photoID,
|
photoID,
|
||||||
albumID,
|
albumID,
|
||||||
password: password.value
|
password: password.value
|
||||||
@ -35,42 +32,40 @@ photo.load = function(photoID, albumID) {
|
|||||||
|
|
||||||
api.post('Photo::get', params, function(data) {
|
api.post('Photo::get', params, function(data) {
|
||||||
|
|
||||||
|
const checkPasswd = function() {
|
||||||
|
if (password.value!=='') photo.load(photoID, albumID)
|
||||||
|
else setTimeout(checkPasswd, 250)
|
||||||
|
}
|
||||||
|
|
||||||
if (data==='Warning: Photo private!') {
|
if (data==='Warning: Photo private!') {
|
||||||
lychee.content.show();
|
lychee.content.show()
|
||||||
lychee.goto('');
|
lychee.goto('')
|
||||||
return false;
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data==='Warning: Wrong password!') {
|
if (data==='Warning: Wrong password!') {
|
||||||
checkPasswd = function() {
|
checkPasswd()
|
||||||
if (password.value!=='') photo.load(photoID, albumID);
|
return false
|
||||||
else setTimeout(checkPasswd, 250);
|
|
||||||
};
|
|
||||||
checkPasswd();
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
photo.json = data;
|
photo.json = data
|
||||||
|
|
||||||
if (!visible.photo()) view.photo.show();
|
if (!visible.photo()) view.photo.show()
|
||||||
view.photo.init();
|
view.photo.init()
|
||||||
lychee.imageview.show();
|
lychee.imageview.show()
|
||||||
|
|
||||||
setTimeout(function() {
|
setTimeout(() => {
|
||||||
lychee.content.show();
|
lychee.content.show()
|
||||||
//photo.preloadNext(photoID, albumID);
|
//photo.preloadNext(photoID, albumID);
|
||||||
}, 300);
|
}, 300)
|
||||||
|
|
||||||
});
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Preload the next photo for better response time
|
// Preload the next photo for better response time
|
||||||
photo.preloadNext = function(photoID) {
|
photo.preloadNext = function(photoID) {
|
||||||
|
|
||||||
var nextPhoto,
|
|
||||||
url;
|
|
||||||
|
|
||||||
// Never preload on mobile devices with bare RAM and
|
// Never preload on mobile devices with bare RAM and
|
||||||
// mostly mobile internet
|
// mostly mobile internet
|
||||||
// {{ code }}
|
// {{ code }}
|
||||||
@ -80,12 +75,12 @@ photo.preloadNext = function(photoID) {
|
|||||||
album.json.content[photoID] &&
|
album.json.content[photoID] &&
|
||||||
album.json.content[photoID].nextPhoto!='') {
|
album.json.content[photoID].nextPhoto!='') {
|
||||||
|
|
||||||
nextPhoto = album.json.content[photoID].nextPhoto;
|
let nextPhoto = album.json.content[photoID].nextPhoto,
|
||||||
url = album.json.content[nextPhoto].url;
|
url = album.json.content[nextPhoto].url
|
||||||
|
|
||||||
photo.cache = new Image();
|
photo.cache = new Image()
|
||||||
photo.cache.src = url;
|
photo.cache.src = url
|
||||||
photo.cache.onload = function() { photo.cache = null };
|
photo.cache.onload = () => photo.cache = null
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,36 +88,36 @@ photo.preloadNext = function(photoID) {
|
|||||||
|
|
||||||
photo.parse = function() {
|
photo.parse = function() {
|
||||||
|
|
||||||
if (!photo.json.title) photo.json.title = 'Untitled';
|
if (!photo.json.title) photo.json.title = 'Untitled'
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
photo.previous = function(animate) {
|
photo.previous = function(animate) {
|
||||||
|
|
||||||
var delay = 0;
|
if (photo.getID()!==false &&
|
||||||
|
album.json &&
|
||||||
|
album.json.content[photo.getID()] &&
|
||||||
|
album.json.content[photo.getID()].previousPhoto!=='') {
|
||||||
|
|
||||||
if (photo.getID()!==false&&
|
let delay = 0
|
||||||
album.json&&
|
|
||||||
album.json.content[photo.getID()]&&
|
|
||||||
album.json.content[photo.getID()].previousPhoto!=='') {
|
|
||||||
|
|
||||||
if (animate===true) {
|
if (animate===true) {
|
||||||
|
|
||||||
delay = 200;
|
delay = 200
|
||||||
|
|
||||||
$('#image').css({
|
$('#image').css({
|
||||||
WebkitTransform: 'translateX(100%)',
|
WebkitTransform : 'translateX(100%)',
|
||||||
MozTransform: 'translateX(100%)',
|
MozTransform : 'translateX(100%)',
|
||||||
transform: 'translateX(100%)',
|
transform : 'translateX(100%)',
|
||||||
opacity: 0
|
opacity : 0
|
||||||
});
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setTimeout(function() {
|
setTimeout(() => {
|
||||||
if (photo.getID()===false) return false;
|
if (photo.getID()===false) return false
|
||||||
lychee.goto(album.getID() + '/' + album.json.content[photo.getID()].previousPhoto)
|
lychee.goto(album.getID() + '/' + album.json.content[photo.getID()].previousPhoto)
|
||||||
}, delay);
|
}, delay)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,30 +125,30 @@ photo.previous = function(animate) {
|
|||||||
|
|
||||||
photo.next = function(animate) {
|
photo.next = function(animate) {
|
||||||
|
|
||||||
var delay = 0;
|
if (photo.getID()!==false &&
|
||||||
|
album.json &&
|
||||||
|
album.json.content[photo.getID()] &&
|
||||||
|
album.json.content[photo.getID()].nextPhoto!=='') {
|
||||||
|
|
||||||
if (photo.getID()!==false&&
|
let delay = 0
|
||||||
album.json&&
|
|
||||||
album.json.content[photo.getID()]&&
|
|
||||||
album.json.content[photo.getID()].nextPhoto!=='') {
|
|
||||||
|
|
||||||
if (animate===true) {
|
if (animate===true) {
|
||||||
|
|
||||||
delay = 200;
|
delay = 200
|
||||||
|
|
||||||
$('#image').css({
|
$('#image').css({
|
||||||
WebkitTransform: 'translateX(-100%)',
|
WebkitTransform : 'translateX(-100%)',
|
||||||
MozTransform: 'translateX(-100%)',
|
MozTransform : 'translateX(-100%)',
|
||||||
transform: 'translateX(-100%)',
|
transform : 'translateX(-100%)',
|
||||||
opacity: 0
|
opacity : 0
|
||||||
});
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setTimeout(function() {
|
setTimeout(() => {
|
||||||
if (photo.getID()===false) return false;
|
if (photo.getID()===false) return false
|
||||||
lychee.goto(album.getID() + '/' + album.json.content[photo.getID()].nextPhoto);
|
lychee.goto(album.getID() + '/' + album.json.content[photo.getID()].nextPhoto)
|
||||||
}, delay);
|
}, delay)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -161,105 +156,102 @@ photo.next = function(animate) {
|
|||||||
|
|
||||||
photo.duplicate = function(photoIDs) {
|
photo.duplicate = function(photoIDs) {
|
||||||
|
|
||||||
var params;
|
if (!photoIDs) return false
|
||||||
|
if (photoIDs instanceof Array===false) photoIDs = [photoIDs]
|
||||||
|
|
||||||
if (!photoIDs) return false;
|
albums.refresh()
|
||||||
if (photoIDs instanceof Array===false) photoIDs = [photoIDs];
|
|
||||||
|
|
||||||
albums.refresh();
|
let params = {
|
||||||
|
|
||||||
params = {
|
|
||||||
photoIDs: photoIDs.join()
|
photoIDs: photoIDs.join()
|
||||||
}
|
}
|
||||||
|
|
||||||
api.post('Photo::duplicate', params, function(data) {
|
api.post('Photo::duplicate', params, function(data) {
|
||||||
|
|
||||||
if (data!==true) lychee.error(null, params, data);
|
if (data!==true) lychee.error(null, params, data)
|
||||||
else album.load(album.getID());
|
else album.load(album.getID())
|
||||||
|
|
||||||
});
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
photo.delete = function(photoIDs) {
|
photo.delete = function(photoIDs) {
|
||||||
|
|
||||||
var action = {},
|
let action = {},
|
||||||
cancel = {},
|
cancel = {},
|
||||||
msg = '',
|
msg = '',
|
||||||
photoTitle = '';
|
photoTitle = ''
|
||||||
|
|
||||||
if (!photoIDs) return false;
|
if (!photoIDs) return false
|
||||||
if (photoIDs instanceof Array===false) photoIDs = [photoIDs];
|
if (photoIDs instanceof Array===false) photoIDs = [photoIDs]
|
||||||
|
|
||||||
if (photoIDs.length===1) {
|
if (photoIDs.length===1) {
|
||||||
|
|
||||||
// Get title if only one photo is selected
|
// Get title if only one photo is selected
|
||||||
if (visible.photo()) photoTitle = photo.json.title;
|
if (visible.photo()) photoTitle = photo.json.title
|
||||||
else photoTitle = album.json.content[photoIDs].title;
|
else photoTitle = album.json.content[photoIDs].title
|
||||||
|
|
||||||
// Fallback for photos without a title
|
// Fallback for photos without a title
|
||||||
if (photoTitle==='') photoTitle = 'Untitled';
|
if (photoTitle==='') photoTitle = 'Untitled'
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
action.fn = function() {
|
action.fn = function() {
|
||||||
|
|
||||||
var params = '',
|
let nextPhoto,
|
||||||
nextPhoto = '',
|
previousPhoto
|
||||||
previousPhoto = '';
|
|
||||||
|
|
||||||
basicModal.close();
|
basicModal.close()
|
||||||
|
|
||||||
photoIDs.forEach(function(id, index, array) {
|
photoIDs.forEach(function(id, index, array) {
|
||||||
|
|
||||||
// Change reference for the next and previous photo
|
// Change reference for the next and previous photo
|
||||||
if (album.json.content[id].nextPhoto!==''||album.json.content[id].previousPhoto!=='') {
|
if (album.json.content[id].nextPhoto!=='' || album.json.content[id].previousPhoto!=='') {
|
||||||
|
|
||||||
nextPhoto = album.json.content[id].nextPhoto;
|
nextPhoto = album.json.content[id].nextPhoto
|
||||||
previousPhoto = album.json.content[id].previousPhoto;
|
previousPhoto = album.json.content[id].previousPhoto
|
||||||
|
|
||||||
album.json.content[previousPhoto].nextPhoto = nextPhoto;
|
album.json.content[previousPhoto].nextPhoto = nextPhoto
|
||||||
album.json.content[nextPhoto].previousPhoto = previousPhoto;
|
album.json.content[nextPhoto].previousPhoto = previousPhoto
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
delete album.json.content[id];
|
delete album.json.content[id]
|
||||||
view.album.content.delete(id);
|
view.album.content.delete(id)
|
||||||
|
|
||||||
});
|
})
|
||||||
|
|
||||||
albums.refresh();
|
albums.refresh()
|
||||||
|
|
||||||
// Go to next photo if there is a next photo and
|
// Go to next photo if there is a next photo and
|
||||||
// next photo is not the current one. Show album otherwise.
|
// next photo is not the current one. Show album otherwise.
|
||||||
if (visible.photo()&&nextPhoto!==''&&nextPhoto!==photo.getID()) lychee.goto(album.getID() + '/' + nextPhoto);
|
if (visible.photo() && nextPhoto!=='' && nextPhoto!==photo.getID()) lychee.goto(album.getID() + '/' + nextPhoto)
|
||||||
else if (!visible.albums()) lychee.goto(album.getID());
|
else if (!visible.albums()) lychee.goto(album.getID())
|
||||||
|
|
||||||
params = {
|
let params = {
|
||||||
photoIDs: photoIDs.join()
|
photoIDs: photoIDs.join()
|
||||||
}
|
}
|
||||||
|
|
||||||
api.post('Photo::delete', params, function(data) {
|
api.post('Photo::delete', params, function(data) {
|
||||||
|
|
||||||
if (data!==true) lychee.error(null, params, data);
|
if (data!==true) lychee.error(null, params, data)
|
||||||
|
|
||||||
});
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (photoIDs.length===1) {
|
if (photoIDs.length===1) {
|
||||||
|
|
||||||
action.title = 'Delete Photo';
|
action.title = 'Delete Photo'
|
||||||
cancel.title = 'Keep Photo';
|
cancel.title = 'Keep Photo'
|
||||||
|
|
||||||
msg = "<p>Are you sure you want to delete the photo '" + photoTitle + "'? This action can't be undone!</p>";
|
msg = `<p>Are you sure you want to delete the photo '${ photoTitle }'? This action can't be undone!</p>`
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
action.title = 'Delete Photo';
|
action.title = 'Delete Photo'
|
||||||
cancel.title = 'Keep Photo';
|
cancel.title = 'Keep Photo'
|
||||||
|
|
||||||
msg = "<p>Are you sure you want to delete all " + photoIDs.length + " selected photo? This action can't be undone!</p>";
|
msg = `<p>Are you sure you want to delete all ${ photoIDs.length } selected photo? This action can't be undone!</p>`
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -276,64 +268,63 @@ photo.delete = function(photoIDs) {
|
|||||||
fn: basicModal.close
|
fn: basicModal.close
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
photo.setTitle = function(photoIDs) {
|
photo.setTitle = function(photoIDs) {
|
||||||
|
|
||||||
var oldTitle = '',
|
let oldTitle = '',
|
||||||
input = '',
|
msg = ''
|
||||||
msg = '',
|
|
||||||
action;
|
|
||||||
|
|
||||||
if (!photoIDs) return false;
|
if (!photoIDs) return false
|
||||||
if (photoIDs instanceof Array===false) photoIDs = [photoIDs];
|
if (photoIDs instanceof Array===false) photoIDs = [photoIDs]
|
||||||
|
|
||||||
if (photoIDs.length===1) {
|
if (photoIDs.length===1) {
|
||||||
|
|
||||||
// Get old title if only one photo is selected
|
// Get old title if only one photo is selected
|
||||||
if (photo.json) oldTitle = photo.json.title;
|
if (photo.json) oldTitle = photo.json.title
|
||||||
else if (album.json) oldTitle = album.json.content[photoIDs].title;
|
else if (album.json) oldTitle = album.json.content[photoIDs].title
|
||||||
oldTitle = oldTitle.replace(/'/g, ''');
|
oldTitle = oldTitle.replace(/'/g, ''')
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
action = function(data) {
|
const action = function(data) {
|
||||||
|
|
||||||
var params,
|
basicModal.close()
|
||||||
newTitle = data.title;
|
|
||||||
|
|
||||||
basicModal.close();
|
let newTitle = data.title
|
||||||
|
|
||||||
// Remove html from input
|
// Remove html from input
|
||||||
newTitle = lychee.removeHTML(newTitle);
|
newTitle = lychee.removeHTML(newTitle)
|
||||||
|
|
||||||
if (visible.photo()) {
|
if (visible.photo()) {
|
||||||
photo.json.title = (newTitle==='') ? 'Untitled' : newTitle;
|
photo.json.title = (newTitle==='' ? 'Untitled' : newTitle)
|
||||||
view.photo.title();
|
view.photo.title()
|
||||||
}
|
}
|
||||||
|
|
||||||
photoIDs.forEach(function(id, index, array) {
|
photoIDs.forEach(function(id, index, array) {
|
||||||
album.json.content[id].title = newTitle;
|
album.json.content[id].title = newTitle
|
||||||
view.album.content.title(id);
|
view.album.content.title(id)
|
||||||
});
|
})
|
||||||
|
|
||||||
params = {
|
let params = {
|
||||||
photoIDs: photoIDs.join(),
|
photoIDs: photoIDs.join(),
|
||||||
title: newTitle
|
title: newTitle
|
||||||
}
|
}
|
||||||
|
|
||||||
api.post('Photo::setTitle', params, function(data) {
|
api.post('Photo::setTitle', params, function(data) {
|
||||||
|
|
||||||
if (data!==true) lychee.error(null, params, data);
|
if (data!==true) lychee.error(null, params, data)
|
||||||
|
|
||||||
});
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
input = "<input class='text' name='title' type='text' maxlength='50' placeholder='Title' value='" + oldTitle + "'>";
|
let input = `<input class='text' name='title' type='text' maxlength='50' placeholder='Title' value='${ oldTitle }'>`
|
||||||
|
|
||||||
if (photoIDs.length===1) msg = "<p>Enter a new title for this photo: " + input + "</p>";
|
if (photoIDs.length===1) msg = `<p>Enter a new title for this photo: ${ input }</p>`
|
||||||
else msg = "<p>Enter a title for all " + photoIDs.length + " selected photos: " + input + "</p>";
|
else msg = `<p>Enter a title for all ${ photoIDs.length } selected photos: ${ input }</p>`
|
||||||
|
|
||||||
basicModal.show({
|
basicModal.show({
|
||||||
body: msg,
|
body: msg,
|
||||||
@ -347,79 +338,78 @@ photo.setTitle = function(photoIDs) {
|
|||||||
fn: basicModal.close
|
fn: basicModal.close
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
photo.setAlbum = function(photoIDs, albumID) {
|
photo.setAlbum = function(photoIDs, albumID) {
|
||||||
|
|
||||||
var params,
|
let nextPhoto,
|
||||||
nextPhoto,
|
previousPhoto
|
||||||
previousPhoto;
|
|
||||||
|
|
||||||
if (!photoIDs) return false;
|
if (!photoIDs) return false
|
||||||
if (visible.photo) lychee.goto(album.getID());
|
if (photoIDs instanceof Array===false) photoIDs = [photoIDs]
|
||||||
if (photoIDs instanceof Array===false) photoIDs = [photoIDs];
|
|
||||||
|
if (visible.photo) lychee.goto(album.getID())
|
||||||
|
|
||||||
photoIDs.forEach(function(id, index, array) {
|
photoIDs.forEach(function(id, index, array) {
|
||||||
|
|
||||||
// Change reference for the next and previous photo
|
// Change reference for the next and previous photo
|
||||||
if (album.json.content[id].nextPhoto!==''||album.json.content[id].previousPhoto!=='') {
|
if (album.json.content[id].nextPhoto!==''||album.json.content[id].previousPhoto!=='') {
|
||||||
|
|
||||||
nextPhoto = album.json.content[id].nextPhoto;
|
nextPhoto = album.json.content[id].nextPhoto
|
||||||
previousPhoto = album.json.content[id].previousPhoto;
|
previousPhoto = album.json.content[id].previousPhoto
|
||||||
|
|
||||||
album.json.content[previousPhoto].nextPhoto = nextPhoto;
|
album.json.content[previousPhoto].nextPhoto = nextPhoto
|
||||||
album.json.content[nextPhoto].previousPhoto = previousPhoto;
|
album.json.content[nextPhoto].previousPhoto = previousPhoto
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
album.json.content[id] = null;
|
album.json.content[id] = null
|
||||||
view.album.content.delete(id);
|
view.album.content.delete(id)
|
||||||
|
|
||||||
});
|
})
|
||||||
|
|
||||||
albums.refresh();
|
albums.refresh()
|
||||||
|
|
||||||
params = {
|
let params = {
|
||||||
photoIDs: photoIDs.join(),
|
photoIDs: photoIDs.join(),
|
||||||
albumID
|
albumID
|
||||||
}
|
}
|
||||||
|
|
||||||
api.post('Photo::setAlbum', params, function(data) {
|
api.post('Photo::setAlbum', params, function(data) {
|
||||||
|
|
||||||
if (data!==true) lychee.error(null, params, data);
|
if (data!==true) lychee.error(null, params, data)
|
||||||
|
|
||||||
});
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
photo.setStar = function(photoIDs) {
|
photo.setStar = function(photoIDs) {
|
||||||
|
|
||||||
var params;
|
if (!photoIDs) return false
|
||||||
|
|
||||||
if (!photoIDs) return false;
|
|
||||||
if (visible.photo()) {
|
if (visible.photo()) {
|
||||||
photo.json.star = (photo.json.star==='0') ? '1' : '0';
|
photo.json.star = (photo.json.star==='0' ? '1' : '0')
|
||||||
view.photo.star();
|
view.photo.star()
|
||||||
}
|
}
|
||||||
|
|
||||||
photoIDs.forEach(function(id, index, array) {
|
photoIDs.forEach(function(id, index, array) {
|
||||||
album.json.content[id].star = (album.json.content[id].star==='0') ? '1' : '0';
|
album.json.content[id].star = (album.json.content[id].star==='0' ? '1' : '0')
|
||||||
view.album.content.star(id);
|
view.album.content.star(id)
|
||||||
});
|
})
|
||||||
|
|
||||||
albums.refresh();
|
albums.refresh()
|
||||||
|
|
||||||
params = {
|
let params = {
|
||||||
photoIDs: photoIDs.join()
|
photoIDs: photoIDs.join()
|
||||||
}
|
}
|
||||||
|
|
||||||
api.post('Photo::setStar', params, function(data) {
|
api.post('Photo::setStar', params, function(data) {
|
||||||
|
|
||||||
if (data!==true) lychee.error(null, params, data);
|
if (data!==true) lychee.error(null, params, data)
|
||||||
|
|
||||||
});
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -427,12 +417,10 @@ photo.setPublic = function(photoID, e) {
|
|||||||
|
|
||||||
if (photo.json.public==='2') {
|
if (photo.json.public==='2') {
|
||||||
|
|
||||||
var action;
|
const action = function() {
|
||||||
|
|
||||||
action = function() {
|
basicModal.close()
|
||||||
|
lychee.goto(photo.json.original_album)
|
||||||
basicModal.close();
|
|
||||||
lychee.goto(photo.json.original_album);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -448,68 +436,66 @@ photo.setPublic = function(photoID, e) {
|
|||||||
fn: basicModal.close
|
fn: basicModal.close
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
|
||||||
return false;
|
return false
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (visible.photo()) {
|
if (visible.photo()) {
|
||||||
|
|
||||||
photo.json.public = (photo.json.public==='0') ? '1' : '0';
|
photo.json.public = (photo.json.public==='0' ? '1' : '0')
|
||||||
view.photo.public();
|
view.photo.public()
|
||||||
if (photo.json.public==='1') contextMenu.sharePhoto(photoID, e);
|
if (photo.json.public==='1') contextMenu.sharePhoto(photoID, e)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
album.json.content[photoID].public = (album.json.content[photoID].public==='0') ? '1' : '0';
|
album.json.content[photoID].public = (album.json.content[photoID].public==='0' ? '1' : '0')
|
||||||
view.album.content.public(photoID);
|
view.album.content.public(photoID)
|
||||||
|
|
||||||
albums.refresh();
|
albums.refresh()
|
||||||
|
|
||||||
api.post('Photo::setPublic', { photoID }, function(data) {
|
api.post('Photo::setPublic', { photoID }, function(data) {
|
||||||
|
|
||||||
if (data!==true) lychee.error(null, params, data);
|
if (data!==true) lychee.error(null, params, data)
|
||||||
|
|
||||||
});
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
photo.setDescription = function(photoID) {
|
photo.setDescription = function(photoID) {
|
||||||
|
|
||||||
var oldDescription = photo.json.description.replace(/'/g, '''),
|
let oldDescription = photo.json.description.replace(/'/g, ''')
|
||||||
action;
|
|
||||||
|
|
||||||
action = function(data) {
|
const action = function(data) {
|
||||||
|
|
||||||
var params,
|
basicModal.close()
|
||||||
description = data.description;
|
|
||||||
|
|
||||||
basicModal.close();
|
let description = data.description
|
||||||
|
|
||||||
// Remove html from input
|
// Remove html from input
|
||||||
description = lychee.removeHTML(description);
|
description = lychee.removeHTML(description)
|
||||||
|
|
||||||
if (visible.photo()) {
|
if (visible.photo()) {
|
||||||
photo.json.description = description;
|
photo.json.description = description
|
||||||
view.photo.description();
|
view.photo.description()
|
||||||
}
|
}
|
||||||
|
|
||||||
params = {
|
let params = {
|
||||||
photoID,
|
photoID,
|
||||||
description
|
description
|
||||||
}
|
}
|
||||||
|
|
||||||
api.post('Photo::setDescription', params, function(data) {
|
api.post('Photo::setDescription', params, function(data) {
|
||||||
|
|
||||||
if (data!==true) lychee.error(null, params, data);
|
if (data!==true) lychee.error(null, params, data)
|
||||||
|
|
||||||
});
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
basicModal.show({
|
basicModal.show({
|
||||||
body: "<p>Enter a description for this photo: <input class='text' name='description' type='text' maxlength='800' placeholder='Description' value='" + oldDescription + "'></p>",
|
body: `<p>Enter a description for this photo: <input class='text' name='description' type='text' maxlength='800' placeholder='Description' value='${ oldDescription }'></p>`,
|
||||||
buttons: {
|
buttons: {
|
||||||
action: {
|
action: {
|
||||||
title: 'Set Description',
|
title: 'Set Description',
|
||||||
@ -520,46 +506,45 @@ photo.setDescription = function(photoID) {
|
|||||||
fn: basicModal.close
|
fn: basicModal.close
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
photo.editTags = function(photoIDs) {
|
photo.editTags = function(photoIDs) {
|
||||||
|
|
||||||
var oldTags = '',
|
let oldTags = '',
|
||||||
msg = '',
|
msg = ''
|
||||||
input = '';
|
|
||||||
|
|
||||||
if (!photoIDs) return false;
|
if (!photoIDs) return false
|
||||||
if (photoIDs instanceof Array===false) photoIDs = [photoIDs];
|
if (photoIDs instanceof Array===false) photoIDs = [photoIDs]
|
||||||
|
|
||||||
// Get tags
|
// Get tags
|
||||||
if (visible.photo()) oldTags = photo.json.tags;
|
if (visible.photo()) oldTags = photo.json.tags
|
||||||
if (visible.album()&&photoIDs.length===1) oldTags = album.json.content[photoIDs].tags;
|
else if (visible.album() && photoIDs.length===1) oldTags = album.json.content[photoIDs].tags
|
||||||
if (visible.search()&&photoIDs.length===1) oldTags = album.json.content[photoIDs].tags;
|
else if (visible.search() && photoIDs.length===1) oldTags = album.json.content[photoIDs].tags
|
||||||
if (visible.album()&&photoIDs.length>1) {
|
else if (visible.album() && photoIDs.length>1) {
|
||||||
let same = true;
|
let same = true
|
||||||
photoIDs.forEach(function(id, index, array) {
|
photoIDs.forEach(function(id, index, array) {
|
||||||
if(album.json.content[id].tags===album.json.content[photoIDs[0]].tags&&same===true) same = true;
|
if (album.json.content[id].tags===album.json.content[photoIDs[0]].tags && same===true) same = true
|
||||||
else same = false;
|
else same = false
|
||||||
});
|
})
|
||||||
if (same) oldTags = album.json.content[photoIDs[0]].tags;
|
if (same===true) oldTags = album.json.content[photoIDs[0]].tags
|
||||||
}
|
}
|
||||||
|
|
||||||
// Improve tags
|
// Improve tags
|
||||||
oldTags = oldTags.replace(/,/g, ', ');
|
oldTags = oldTags.replace(/,/g, ', ')
|
||||||
|
|
||||||
action = function(data) {
|
const action = function(data) {
|
||||||
|
|
||||||
basicModal.close();
|
basicModal.close()
|
||||||
photo.setTags(photoIDs, data.tags);
|
photo.setTags(photoIDs, data.tags)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
input = "<input class='text' name='tags' type='text' maxlength='800' placeholder='Tags' value='" + oldTags + "'>";
|
let input = `<input class='text' name='tags' type='text' maxlength='800' placeholder='Tags' value='${ oldTags }'>`
|
||||||
|
|
||||||
if (photoIDs.length===1) msg = "<p>Enter your tags for this photo. You can add multiple tags by separating them with a comma: " + input + "</p>";
|
if (photoIDs.length===1) msg = `<p>Enter your tags for this photo. You can add multiple tags by separating them with a comma: ${ input }</p>`
|
||||||
else msg = "<p>Enter your tags for all " + photoIDs.length + " selected photos. Existing tags will be overwritten. You can add multiple tags by separating them with a comma: " + input + "</p>";
|
else msg = `<p>Enter your tags for all ${ photoIDs.length } selected photos. Existing tags will be overwritten. You can add multiple tags by separating them with a comma: ${ input }</p>`
|
||||||
|
|
||||||
basicModal.show({
|
basicModal.show({
|
||||||
body: msg,
|
body: msg,
|
||||||
@ -573,88 +558,85 @@ photo.editTags = function(photoIDs) {
|
|||||||
fn: basicModal.close
|
fn: basicModal.close
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
photo.setTags = function(photoIDs, tags) {
|
photo.setTags = function(photoIDs, tags) {
|
||||||
|
|
||||||
var params;
|
if (!photoIDs) return false
|
||||||
|
if (photoIDs instanceof Array===false) photoIDs = [photoIDs]
|
||||||
if (!photoIDs) return false;
|
|
||||||
if (photoIDs instanceof Array===false) photoIDs = [photoIDs];
|
|
||||||
|
|
||||||
// Parse tags
|
// Parse tags
|
||||||
tags = tags.replace(/(\ ,\ )|(\ ,)|(,\ )|(,{1,}\ {0,})|(,$|^,)/g, ',');
|
tags = tags.replace(/(\ ,\ )|(\ ,)|(,\ )|(,{1,}\ {0,})|(,$|^,)/g, ',')
|
||||||
tags = tags.replace(/,$|^,|(\ ){0,}$/g, '');
|
tags = tags.replace(/,$|^,|(\ ){0,}$/g, '')
|
||||||
|
|
||||||
// Remove html from input
|
// Remove html from input
|
||||||
tags = lychee.removeHTML(tags);
|
tags = lychee.removeHTML(tags)
|
||||||
|
|
||||||
if (visible.photo()) {
|
if (visible.photo()) {
|
||||||
photo.json.tags = tags;
|
photo.json.tags = tags
|
||||||
view.photo.tags();
|
view.photo.tags()
|
||||||
}
|
}
|
||||||
|
|
||||||
photoIDs.forEach(function(id, index, array) {
|
photoIDs.forEach(function(id, index, array) {
|
||||||
album.json.content[id].tags = tags;
|
album.json.content[id].tags = tags
|
||||||
});
|
})
|
||||||
|
|
||||||
params = {
|
let params = {
|
||||||
photoIDs: photoIDs.join(),
|
photoIDs: photoIDs.join(),
|
||||||
tags
|
tags
|
||||||
}
|
}
|
||||||
|
|
||||||
api.post('Photo::setTags', params, function(data) {
|
api.post('Photo::setTags', params, function(data) {
|
||||||
|
|
||||||
if (data!==true) lychee.error(null, params, data);
|
if (data!==true) lychee.error(null, params, data)
|
||||||
|
|
||||||
});
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
photo.deleteTag = function(photoID, index) {
|
photo.deleteTag = function(photoID, index) {
|
||||||
|
|
||||||
var tags;
|
let tags
|
||||||
|
|
||||||
// Remove
|
// Remove
|
||||||
tags = photo.json.tags.split(',');
|
tags = photo.json.tags.split(',')
|
||||||
tags.splice(index, 1);
|
tags.splice(index, 1)
|
||||||
|
|
||||||
// Save
|
// Save
|
||||||
photo.json.tags = tags.toString();
|
photo.json.tags = tags.toString()
|
||||||
photo.setTags([photoID], photo.json.tags);
|
photo.setTags([photoID], photo.json.tags)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
photo.share = function(photoID, service) {
|
photo.share = function(photoID, service) {
|
||||||
|
|
||||||
var link = '',
|
let link = '',
|
||||||
url = photo.getViewLink(photoID),
|
url = photo.getViewLink(photoID)
|
||||||
filename = 'unknown';
|
|
||||||
|
|
||||||
switch (service) {
|
switch (service) {
|
||||||
case 0:
|
case 'twitter':
|
||||||
link = 'https://twitter.com/share?url=' + encodeURI(url);
|
link = `https://twitter.com/share?url=${ encodeURI(url) }`
|
||||||
break;
|
break
|
||||||
case 1:
|
case 'facebook':
|
||||||
link = 'http://www.facebook.com/sharer.php?u=' + encodeURI(url) + '&t=' + encodeURI(photo.json.title);
|
link = `http://www.facebook.com/sharer.php?u=${ encodeURI(url) }&t=${ encodeURI(photo.json.title) }`
|
||||||
break;
|
break
|
||||||
case 2:
|
case 'mail':
|
||||||
link = 'mailto:?subject=' + encodeURI(photo.json.title) + '&body=' + encodeURI(url);
|
link = `mailto:?subject=${ encodeURI(photo.json.title) }&body=${ encodeURI(url) }`
|
||||||
break;
|
break
|
||||||
case 3:
|
case 'dropbox':
|
||||||
lychee.loadDropbox(function() {
|
lychee.loadDropbox(function() {
|
||||||
filename = photo.json.title + '.' + photo.getDirectLink().split('.').pop();
|
let filename = photo.json.title + '.' + photo.getDirectLink().split('.').pop()
|
||||||
Dropbox.save(photo.getDirectLink(), filename);
|
Dropbox.save(photo.getDirectLink(), filename)
|
||||||
});
|
})
|
||||||
break;
|
break
|
||||||
default:
|
default:
|
||||||
link = '';
|
link = ''
|
||||||
break;
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
if (link.length>5) location.href = link;
|
if (link.length!=='') location.href = link
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -663,72 +645,66 @@ photo.getSize = function() {
|
|||||||
// Size can be 'big', 'medium' or 'small'
|
// Size can be 'big', 'medium' or 'small'
|
||||||
// Default is big
|
// Default is big
|
||||||
// Small is centered in the middle of the screen
|
// Small is centered in the middle of the screen
|
||||||
var size = 'big',
|
let size = 'big',
|
||||||
scaled = false,
|
scaled = false,
|
||||||
hasMedium = photo.json.medium!=='',
|
hasMedium = photo.json.medium!=='',
|
||||||
pixelRatio = window.devicePixelRatio,
|
pixelRatio = window.devicePixelRatio,
|
||||||
view = {
|
view = {
|
||||||
width: $(window).width()-60,
|
width : $(window).width() - 60,
|
||||||
height: $(window).height()-100
|
height : $(window).height() - 100
|
||||||
};
|
}
|
||||||
|
|
||||||
// Detect if the photo will be shown scaled,
|
// Detect if the photo will be shown scaled,
|
||||||
// because the screen size is smaller than the photo
|
// because the screen size is smaller than the photo
|
||||||
if (photo.json.width>view.width||
|
if (photo.json.width>view.width || photo.json.height>view.height) scaled = true
|
||||||
photo.json.height>view.height) scaled = true;
|
|
||||||
|
|
||||||
// Calculate pixel ratio of screen
|
// Calculate pixel ratio of screen
|
||||||
if (pixelRatio!==undefined&&pixelRatio>1) {
|
if (pixelRatio!==undefined && pixelRatio>1) {
|
||||||
view.width = view.width * pixelRatio;
|
view.width = view.width * pixelRatio
|
||||||
view.height = view.height * pixelRatio;
|
view.height = view.height * pixelRatio
|
||||||
}
|
}
|
||||||
|
|
||||||
// Medium available and
|
// Medium available and
|
||||||
// Medium still bigger than screen
|
// Medium still bigger than screen
|
||||||
if (hasMedium===true&&
|
if (hasMedium===true && (1920>view.width && 1080>view.height)) size = 'medium'
|
||||||
(1920>view.width&&1080>view.height)) size = 'medium';
|
|
||||||
|
|
||||||
// Photo not scaled
|
// Photo not scaled
|
||||||
// Photo smaller then screen
|
// Photo smaller then screen
|
||||||
if (scaled===false&&
|
if (scaled===false && (photo.json.width<view.width&& photo.json.width<view.height)) size = 'small'
|
||||||
(photo.json.width<view.width&&
|
|
||||||
photo.json.width<view.height)) size = 'small';
|
|
||||||
|
|
||||||
return size;
|
return size
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
photo.getArchive = function(photoID) {
|
photo.getArchive = function(photoID) {
|
||||||
|
|
||||||
var link,
|
let link,
|
||||||
url = api.path + '?function=Photo::getArchive&photoID=' + photoID;
|
url = `${ api.path }?function=Photo::getArchive&photoID=${ photoID }`
|
||||||
|
|
||||||
if (location.href.indexOf('index.html')>0) link = location.href.replace(location.hash, '').replace('index.html', url);
|
if (location.href.indexOf('index.html')>0) link = location.href.replace(location.hash, '').replace('index.html', url)
|
||||||
else link = location.href.replace(location.hash, '') + url;
|
else link = location.href.replace(location.hash, '') + url
|
||||||
|
|
||||||
if (lychee.publicMode===true) link += '&password=' + password.value;
|
if (lychee.publicMode===true) link += '&password=' + password.value
|
||||||
|
|
||||||
location.href = link;
|
location.href = link
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
photo.getDirectLink = function() {
|
photo.getDirectLink = function() {
|
||||||
|
|
||||||
var url = '';
|
let url = ''
|
||||||
|
|
||||||
if (photo.json&&
|
if (photo.json && photo.json.url && photo.json.url!=='') url = photo.json.url
|
||||||
photo.json.url&&
|
|
||||||
photo.json.url!=='') url = photo.json.url;
|
|
||||||
|
|
||||||
return url;
|
return url
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
photo.getViewLink = function(photoID) {
|
photo.getViewLink = function(photoID) {
|
||||||
|
|
||||||
var url = 'view.php?p=' + photoID;
|
let url = 'view.php?p=' + photoID
|
||||||
|
|
||||||
if (location.href.indexOf('index.html')>0) return location.href.replace('index.html' + location.hash, url);
|
if (location.href.indexOf('index.html')>0) return location.href.replace('index.html' + location.hash, url)
|
||||||
else return location.href.replace(location.hash, url);
|
else return location.href.replace(location.hash, url)
|
||||||
|
|
||||||
}
|
}
|
@ -1,6 +1,6 @@
|
|||||||
/**
|
/**
|
||||||
* @description Swipes and moves an object.
|
* @description Swipes and moves an object.
|
||||||
* @copyright 2015 by Tobias Reich
|
* @copyright 2015 by Tobias Reich
|
||||||
*/
|
*/
|
||||||
|
|
||||||
swipe = {
|
swipe = {
|
||||||
|
Loading…
Reference in New Issue
Block a user