Front-end rewrite #275

This commit is contained in:
Tobias Reich 2014-11-20 23:02:14 +01:00
parent b4d356f7e4
commit 752d094775
5 changed files with 442 additions and 439 deletions

BIN
dist/main.js vendored

Binary file not shown.

View File

@ -3,28 +3,28 @@
* @copyright 2014 by Tobias Reich
*/
album = {
album = {}
json: null,
album.json = null;
getID: function() {
album.getID = function() {
var id;
if (photo.json) id = photo.json.album;
else if (album.json) id = album.json.id;
else id = $(".album:hover, .album.active").attr("data-id");
else id = $('.album:hover, .album.active').attr('data-id');
// Search
if (!id) id = $(".album:hover, .album.active").attr("data-id");
if (!id) id = $(".photo:hover, .photo.active").attr("data-album-id");
if (!id) id = $('.album:hover, .album.active').attr('data-id');
if (!id) id = $('.photo:hover, .photo.active').attr('data-album-id');
if (id) return id;
else return false;
},
}
load: function(albumID, refresh) {
album.load = function(albumID, refresh) {
var startTime,
params,
@ -34,29 +34,28 @@ album = {
password.get(albumID, function() {
if (!refresh) {
loadingBar.show();
lychee.animate(".album:nth-child(-n+50), .photo:nth-child(-n+50)", "contentZoomOut");
lychee.animate(".divider", "fadeOut");
lychee.animate('.album:nth-child(-n+50), .photo:nth-child(-n+50)', 'contentZoomOut');
lychee.animate('.divider', 'fadeOut');
}
startTime = new Date().getTime();
params = "getAlbum&albumID=" + albumID + "&password=" + password.value;
params = 'getAlbum&albumID=' + albumID + '&password=' + password.value;
lychee.api(params, function(data) {
if (data==="Warning: Album private!") {
if (document.location.hash.replace("#", "").split("/")[1]!=undefined) {
if (data==='Warning: Album private!') {
if (document.location.hash.replace('#', '').split('/')[1]!=undefined) {
// Display photo only
lychee.setMode("view");
lychee.setMode('view');
} else {
// Album not public
lychee.content.show();
lychee.goto("");
lychee.goto('');
}
return false;
}
if (data==="Warning: Wrong password!") {
if (data==='Warning: Wrong password!') {
album.load(albumID, refresh);
return false;
}
@ -78,8 +77,8 @@ album = {
view.album.init();
if (!refresh) {
lychee.animate(".album:nth-child(-n+50), .photo:nth-child(-n+50)", "contentZoomIn");
view.header.mode("album");
lychee.animate('.album:nth-child(-n+50), .photo:nth-child(-n+50)', 'contentZoomIn');
view.header.mode('album');
}
}, waitTime);
@ -88,15 +87,15 @@ album = {
});
},
}
parse: function() {
album.parse = function() {
if (!album.json.title) album.json.title = "Untitled";
if (!album.json.title) album.json.title = 'Untitled';
},
}
add: function() {
album.add = function() {
var title,
params,
@ -104,18 +103,19 @@ album = {
isNumber = function(n) { return !isNaN(parseFloat(n)) && isFinite(n) };
buttons = [
["Create Album", function() {
['Create Album', function() {
title = $(".message input.text").val();
title = $('.message input.text').val();
if (title.length===0) title = "Untitled";
if (title.length===0) title = 'Untitled';
modal.close();
params = "addAlbum&title=" + escape(encodeURI(title));
params = 'addAlbum&title=' + escape(encodeURI(title));
lychee.api(params, function(data) {
if (data===true) data = 1; // Avoid first album to be true
// Avoid first album to be true
if (data===true) data = 1;
if (data!==false&&isNumber(data)) {
albums.refresh();
@ -127,14 +127,14 @@ album = {
});
}],
["Cancel", function() {}]
['Cancel', function() {}]
];
modal.show("New Album", "Enter a title for this album: <input class='text' type='text' maxlength='30' placeholder='Title' value='Untitled'>", buttons);
modal.show('New Album', "Enter a title for this album: <input class='text' type='text' maxlength='30' placeholder='Title' value='Untitled'>", buttons);
},
}
delete: function(albumIDs) {
album.delete = function(albumIDs) {
var params,
buttons,
@ -144,9 +144,9 @@ album = {
if (albumIDs instanceof Array===false) albumIDs = [albumIDs];
buttons = [
["", function() {
['', function() {
params = "deleteAlbum&albumIDs=" + albumIDs;
params = 'deleteAlbum&albumIDs=' + albumIDs;
lychee.api(params, function(data) {
if (visible.albums()) {
@ -160,7 +160,7 @@ album = {
} else {
albums.refresh();
lychee.goto("");
lychee.goto('');
}
@ -169,41 +169,41 @@ album = {
});
}],
["", function() {}]
['', function() {}]
];
if (albumIDs.toString()==="0") {
if (albumIDs.toString()==='0') {
buttons[0][0] = "Clear Unsorted";
buttons[1][0] = "Keep Unsorted";
buttons[0][0] = 'Clear Unsorted';
buttons[1][0] = 'Keep Unsorted';
modal.show("Clear Unsorted", "Are you sure you want to delete all photos from 'Unsorted'?<br>This action can't be undone!", buttons);
modal.show('Clear Unsorted', "Are you sure you want to delete all photos from 'Unsorted'?<br>This action can't be undone!", buttons);
} else if (albumIDs.length===1) {
buttons[0][0] = "Delete Album and Photos";
buttons[1][0] = "Keep Album";
buttons[0][0] = 'Delete Album and Photos';
buttons[1][0] = 'Keep Album';
// Get title
if (album.json) albumTitle = album.json.title;
else if (albums.json) albumTitle = albums.json.content[albumIDs].title;
modal.show("Delete Album", "Are you sure you want to delete the album '" + albumTitle + "' and all of the photos it contains? This action can't be undone!", buttons);
modal.show('Delete Album', "Are you sure you want to delete the album '" + albumTitle + "' and all of the photos it contains? This action can't be undone!", buttons);
} else {
buttons[0][0] = "Delete Albums and Photos";
buttons[1][0] = "Keep Albums";
buttons[0][0] = 'Delete Albums and Photos';
buttons[1][0] = 'Keep Albums';
modal.show("Delete Albums", "Are you sure you want to delete all " + albumIDs.length + " selected albums and all of the photos they contain? This action can't be undone!", buttons);
modal.show('Delete Albums', "Are you sure you want to delete all " + albumIDs.length + " selected albums and all of the photos they contain? This action can't be undone!", buttons);
}
},
}
setTitle: function(albumIDs) {
album.setTitle = function(albumIDs) {
var oldTitle = "",
var oldTitle = '',
newTitle,
params,
buttons;
@ -212,24 +212,27 @@ album = {
if (albumIDs instanceof Array===false) albumIDs = [albumIDs];
if (albumIDs.length===1) {
// Get old title if only one album is selected
if (album.json) oldTitle = album.json.title;
else if (albums.json) oldTitle = albums.json.content[albumIDs].title;
if (!oldTitle) oldTitle = "";
oldTitle = oldTitle.replace("'", "&apos;");
if (!oldTitle) oldTitle = '';
oldTitle = oldTitle.replace("'", '&apos;');
}
buttons = [
["Set Title", function() {
['Set Title', function() {
// Get input
newTitle = $(".message input.text").val();
newTitle = $('.message input.text').val();
// Remove html from input
newTitle = lychee.removeHTML(newTitle);
// Set to Untitled when empty
newTitle = (newTitle==="") ? "Untitled" : newTitle;
newTitle = (newTitle==='') ? 'Untitled' : newTitle;
if (visible.album()) {
@ -250,7 +253,7 @@ album = {
}
params = "setAlbumTitle&albumIDs=" + albumIDs + "&title=" + escape(encodeURI(newTitle));
params = 'setAlbumTitle&albumIDs=' + albumIDs + '&title=' + escape(encodeURI(newTitle));
lychee.api(params, function(data) {
if (data!==true) lychee.error(null, params, data);
@ -258,26 +261,26 @@ album = {
});
}],
["Cancel", function() {}]
['Cancel', function() {}]
];
if (albumIDs.length===1) modal.show("Set Title", "Enter a new title for this album: <input class='text' type='text' maxlength='30' placeholder='Title' value='" + oldTitle + "'>", buttons);
else modal.show("Set Titles", "Enter a title for all " + albumIDs.length + " selected album: <input class='text' type='text' maxlength='30' placeholder='Title' value='" + oldTitle + "'>", buttons);
if (albumIDs.length===1) modal.show('Set Title', "Enter a new title for this album: <input class='text' type='text' maxlength='30' placeholder='Title' value='" + oldTitle + "'>", buttons);
else modal.show('Set Titles', "Enter a title for all " + albumIDs.length + " selected album: <input class='text' type='text' maxlength='30' placeholder='Title' value='" + oldTitle + "'>", buttons);
},
}
setDescription: function(photoID) {
album.setDescription = function(photoID) {
var oldDescription = album.json.description.replace("'", "&apos;"),
var oldDescription = album.json.description.replace("'", '&apos;'),
description,
params,
buttons;
buttons = [
["Set Description", function() {
['Set Description', function() {
// Get input
description = $(".message input.text").val();
description = $('.message input.text').val();
// Remove html from input
description = lychee.removeHTML(description);
@ -287,7 +290,7 @@ album = {
view.album.description();
}
params = "setAlbumDescription&albumID=" + photoID + "&description=" + escape(encodeURI(description));
params = 'setAlbumDescription&albumID=' + photoID + '&description=' + escape(encodeURI(description));
lychee.api(params, function(data) {
if (data!==true) lychee.error(null, params, data);
@ -295,17 +298,17 @@ album = {
});
}],
["Cancel", function() {}]
['Cancel', function() {}]
];
modal.show("Set Description", "Please enter a description for this album: <input class='text' type='text' maxlength='800' placeholder='Description' value='" + oldDescription + "'>", buttons);
modal.show('Set Description', "Please enter a description for this album: <input class='text' type='text' maxlength='800' placeholder='Description' value='" + oldDescription + "'>", buttons);
},
}
setPublic: function(albumID, e) {
album.setPublic = function(albumID, e) {
var params,
password = "",
password = '',
listed = false,
downloadable = false;
@ -313,12 +316,12 @@ album = {
if (!visible.message()&&album.json.public==0) {
modal.show("Share Album", "This album will be shared with the following properties:</p><form><div class='choice'><input type='checkbox' name='listed' value='listed' checked><h2>Visible</h2><p>Listed to visitors of your Lychee.</p></div><div class='choice'><input type='checkbox' name='downloadable' value='downloadable'><h2>Downloadable</h2><p>Visitors of your Lychee can download this album.</p></div><div class='choice'><input type='checkbox' name='password' value='password'><h2>Password protected</h2><p>Only accessible with a valid password.<input class='text' type='password' placeholder='password' value='' style='display: none;'></p></div></form><p style='display: none;'>", [["Share Album", function() { album.setPublic(album.getID(), e) }], ["Cancel", function() {}]], -170);
modal.show('Share Album', "This album will be shared with the following properties:</p><form><div class='choice'><input type='checkbox' name='listed' value='listed' checked><h2>Visible</h2><p>Listed to visitors of your Lychee.</p></div><div class='choice'><input type='checkbox' name='downloadable' value='downloadable'><h2>Downloadable</h2><p>Visitors of your Lychee can download this album.</p></div><div class='choice'><input type='checkbox' name='password' value='password'><h2>Password protected</h2><p>Only accessible with a valid password.<input class='text' type='password' placeholder='password' value='' style='display: none;'></p></div></form><p style='display: none;'>", [['Share Album', function() { album.setPublic(album.getID(), e) }], ['Cancel', function() {}]], -170);
$(".message .choice input[name='password']").on("change", function() {
$('.message .choice input[name="password"]').on('change', function() {
if ($(this).prop('checked')===true) $(".message .choice input.text").show();
else $(".message .choice input.text").hide();
if ($(this).prop('checked')===true) $('.message .choice input.text').show();
else $('.message .choice input.text').hide();
});
@ -328,20 +331,20 @@ album = {
if (visible.message()) {
if ($(".message .choice input[name='password']:checked").val()==="password") {
password = md5($(".message input.text").val());
if ($('.message .choice input[name="password"]:checked').val()==='password') {
password = md5($('.message input.text').val());
album.json.password = 1;
} else {
password = "";
password = '';
album.json.password = 0;
}
if ($(".message .choice input[name='listed']:checked").val()==="listed") listed = true;
if ($(".message .choice input[name='downloadable']:checked").val()==="downloadable") downloadable = true;
if ($('.message .choice input[name="listed"]:checked').val()==='listed') listed = true;
if ($('.message .choice input[name="downloadable"]:checked').val()==='downloadable') downloadable = true;
}
params = "setAlbumPublic&albumID=" + albumID + "&password=" + password + "&visible=" + listed + "&downloadable=" + downloadable;
params = 'setAlbumPublic&albumID=' + albumID + '&password=' + password + '&visible=' + listed + '&downloadable=' + downloadable;
if (visible.album()) {
@ -361,44 +364,42 @@ album = {
});
},
}
share: function(service) {
album.share = function(service) {
var link = "",
var link = '',
url = location.href;
switch (service) {
case 0:
link = "https://twitter.com/share?url=" + encodeURI(url);
link = 'https://twitter.com/share?url=' + encodeURI(url);
break;
case 1:
link = "http://www.facebook.com/sharer.php?u=" + encodeURI(url) + "&t=" + encodeURI(album.json.title);
link = 'http://www.facebook.com/sharer.php?u=' + encodeURI(url) + '&t=' + encodeURI(album.json.title);
break;
case 2:
link = "mailto:?subject=" + encodeURI(album.json.title) + "&body=" + encodeURI(url);
link = 'mailto:?subject=' + encodeURI(album.json.title) + '&body=' + encodeURI(url);
break;
default:
link = "";
link = '';
break;
}
if (link.length>5) location.href = link;
},
}
getArchive: function(albumID) {
album.getArchive = function(albumID) {
var link,
url = "php/api.php?function=getAlbumArchive&albumID=" + albumID;
url = 'php/api.php?function=getAlbumArchive&albumID=' + albumID;
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;
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;
if (lychee.publicMode) link += "&password=" + password.value;
if (lychee.publicMode) link += '&password=' + password.value;
location.href = link;
}
};

View File

@ -3,11 +3,11 @@
* @copyright 2014 by Tobias Reich
*/
loadingBar = {
loadingBar = {}
status: null,
loadingBar.status = null;
show: function(status, errorText) {
loadingBar.show = function(status, errorText) {
if (status==='error') {
@ -61,9 +61,9 @@ loadingBar = {
}
},
}
hide: function(force) {
loadingBar.hide = function(force) {
if ((loadingBar.status!=='error'&&loadingBar.status!==null)||force) {
@ -85,5 +85,3 @@ loadingBar = {
}
}
};

View File

@ -54,6 +54,6 @@ password.getDialog = function(albumID, callback) {
['Enter', function() { password.get(albumID, callback) }],
['Cancel', lychee.goto]
];
modal.show('<a class="icon-lock"></a> Enter Password', 'This album is protected by a password. Enter the password below to view the photos of this album: <input class="text" type="password" placeholder="password" value="">', buttons, -110, false);
modal.show("<a class='icon-lock'></a> Enter Password", "This album is protected by a password. Enter the password below to view the photos of this album: <input class='text' type='password' placeholder='password' value=''>", buttons, -110, false);
}

View File

@ -174,10 +174,14 @@ photo.delete = function(photoIDs) {
if (photoIDs instanceof Array===false) photoIDs = [photoIDs];
if (photoIDs.length===1) {
// Get title if only one photo is selected
if (visible.photo()) photoTitle = photo.json.title;
else photoTitle = album.json.content[photoIDs].title;
// Fallback for photos without a title
if (photoTitle==='') photoTitle = 'Untitled';
}
buttons = [