2013-05-03 11:57:08 +00:00
|
|
|
/**
|
2014-01-22 10:12:51 +00:00
|
|
|
* @name Lychee Module
|
|
|
|
* @description This module provides the basic functions of Lychee.
|
|
|
|
* @author Tobias Reich
|
|
|
|
* @copyright 2014 by Tobias Reich
|
2013-05-03 11:57:08 +00:00
|
|
|
*/
|
|
|
|
|
2013-09-03 09:59:30 +00:00
|
|
|
var lychee = {
|
2013-05-03 11:57:08 +00:00
|
|
|
|
2014-01-31 23:09:05 +00:00
|
|
|
version: "2.1",
|
2013-05-03 11:57:08 +00:00
|
|
|
|
2014-01-22 10:12:51 +00:00
|
|
|
api_path: "php/api.php",
|
|
|
|
update_path: "http://lychee.electerious.com/version/index.php",
|
|
|
|
updateURL: "https://github.com/electerious/Lychee",
|
|
|
|
website: "http://lychee.electerious.com",
|
2014-01-31 23:08:13 +00:00
|
|
|
website_donate: "http://lychee.electerious.com#donate",
|
2013-09-03 09:59:30 +00:00
|
|
|
|
2014-01-22 10:12:51 +00:00
|
|
|
upload_path_thumb: "uploads/thumb/",
|
|
|
|
upload_path_big: "uploads/big/",
|
2013-09-03 09:59:30 +00:00
|
|
|
|
2014-01-22 10:12:51 +00:00
|
|
|
publicMode: false,
|
|
|
|
viewMode: false,
|
|
|
|
debugMode: false,
|
2013-06-17 18:40:04 +00:00
|
|
|
|
2014-01-22 10:12:51 +00:00
|
|
|
username: "",
|
|
|
|
checkForUpdates: false,
|
|
|
|
sorting: "",
|
2013-09-03 09:59:30 +00:00
|
|
|
|
2014-01-22 10:12:51 +00:00
|
|
|
dropbox: false,
|
2013-05-03 11:57:08 +00:00
|
|
|
|
2014-01-22 10:12:51 +00:00
|
|
|
loadingBar: $("#loading"),
|
|
|
|
header: $("header"),
|
|
|
|
content: $("#content"),
|
|
|
|
imageview: $("#imageview"),
|
|
|
|
infobox: $("#infobox"),
|
2013-05-03 11:57:08 +00:00
|
|
|
|
2014-01-22 10:12:51 +00:00
|
|
|
init: function() {
|
|
|
|
|
|
|
|
lychee.api("init", function(data) {
|
|
|
|
|
|
|
|
if (data.loggedIn!==true) {
|
|
|
|
lychee.setMode("public");
|
|
|
|
} else {
|
|
|
|
lychee.username = data.config.username;
|
|
|
|
lychee.sorting = data.config.sorting;
|
|
|
|
}
|
|
|
|
|
|
|
|
// No configuration
|
|
|
|
if (data==="Warning: No configuration!") {
|
|
|
|
lychee.header.hide();
|
|
|
|
lychee.content.hide();
|
|
|
|
$("body").append(build.no_content("cog"));
|
|
|
|
settings.createConfig();
|
|
|
|
return true;
|
|
|
|
}
|
2013-05-03 11:57:08 +00:00
|
|
|
|
2014-01-22 10:12:51 +00:00
|
|
|
// No login
|
|
|
|
if (data.config.login===false) {
|
|
|
|
settings.createLogin();
|
|
|
|
}
|
2013-06-17 18:40:04 +00:00
|
|
|
|
|
|
|
lychee.checkForUpdates = data.config.checkForUpdates;
|
|
|
|
$(window).bind("popstate", lychee.load);
|
|
|
|
lychee.load();
|
2014-01-22 10:12:51 +00:00
|
|
|
|
2013-05-03 11:57:08 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2014-01-22 10:12:51 +00:00
|
|
|
api: function(params, callback, loading) {
|
2013-06-17 18:40:04 +00:00
|
|
|
|
|
|
|
if (loading==undefined) loadingBar.show();
|
2013-05-03 11:57:08 +00:00
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
type: "POST",
|
|
|
|
url: lychee.api_path,
|
|
|
|
data: "function=" + params,
|
2014-01-22 10:12:51 +00:00
|
|
|
dataType: "text",
|
|
|
|
success: function(data) {
|
|
|
|
|
|
|
|
setTimeout(function() { loadingBar.hide() }, 100);
|
|
|
|
|
|
|
|
if (typeof data==="string"&&data.substring(0, 7)==="Error: ") {
|
|
|
|
lychee.error(data.substring(7, data.length), params, data);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (data==="1") data = true;
|
|
|
|
else if (data==="") data = false;
|
|
|
|
|
|
|
|
if (typeof data==="string"&&data.substring(0, 1)==="{"&&data.substring(data.length-1, data.length)==="}") data = $.parseJSON(data);
|
|
|
|
|
|
|
|
if (lychee.debugMode) console.log(data);
|
|
|
|
|
|
|
|
callback(data);
|
|
|
|
|
|
|
|
},
|
|
|
|
error: function(jqXHR, textStatus, errorThrown) {
|
|
|
|
|
|
|
|
lychee.error("Server error or API not found.", params, errorThrown);
|
|
|
|
|
|
|
|
}
|
2013-05-03 11:57:08 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
login: function() {
|
|
|
|
|
2013-09-03 09:59:30 +00:00
|
|
|
var user = $("input#username").val(),
|
|
|
|
password = hex_md5($("input#password").val()),
|
|
|
|
params;
|
2013-05-03 11:57:08 +00:00
|
|
|
|
|
|
|
params = "login&user=" + user + "&password=" + password;
|
2014-01-22 10:12:51 +00:00
|
|
|
lychee.api(params, function(data) {
|
|
|
|
if (data===true) {
|
2013-06-17 18:40:04 +00:00
|
|
|
localStorage.setItem("username", user);
|
|
|
|
window.location.reload();
|
2013-05-03 11:57:08 +00:00
|
|
|
} else {
|
2014-02-01 19:27:25 +00:00
|
|
|
$("#password").val("").addClass("error").focus();
|
2013-05-03 11:57:08 +00:00
|
|
|
$(".message .button.active").removeClass("pressed");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-09-03 09:59:30 +00:00
|
|
|
loginDialog: function() {
|
2013-05-03 11:57:08 +00:00
|
|
|
|
2014-01-22 10:12:51 +00:00
|
|
|
var local_username;
|
|
|
|
|
2013-09-03 09:59:30 +00:00
|
|
|
$("body").append(build.signInModal());
|
|
|
|
$("#username").focus();
|
|
|
|
if (localStorage) {
|
|
|
|
local_username = localStorage.getItem("username");
|
|
|
|
if (local_username!=null) {
|
|
|
|
if (local_username.length>0) $("#username").val(local_username);
|
|
|
|
$("#password").focus();
|
|
|
|
}
|
|
|
|
}
|
2014-01-22 10:12:51 +00:00
|
|
|
if (lychee.checkForUpdates==="1") lychee.getUpdate();
|
2013-05-03 11:57:08 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-09-03 09:59:30 +00:00
|
|
|
logout: function() {
|
2013-06-17 18:40:04 +00:00
|
|
|
|
2014-01-22 10:12:51 +00:00
|
|
|
lychee.api("logout", function(data) {
|
2013-09-03 09:59:30 +00:00
|
|
|
window.location.reload();
|
2013-06-17 18:40:04 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-09-03 09:59:30 +00:00
|
|
|
goto: function(url) {
|
2013-06-17 18:40:04 +00:00
|
|
|
|
2013-09-03 09:59:30 +00:00
|
|
|
if (url==undefined) url = "";
|
|
|
|
document.location.hash = url;
|
2013-06-17 18:40:04 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-05-03 11:57:08 +00:00
|
|
|
load: function() {
|
|
|
|
|
2013-09-03 09:59:30 +00:00
|
|
|
var albumID = "",
|
|
|
|
photoID = "",
|
2014-01-22 10:12:51 +00:00
|
|
|
hash = document.location.hash.replace("#", "").split("/");
|
2013-05-03 11:57:08 +00:00
|
|
|
|
2013-09-03 09:59:30 +00:00
|
|
|
contextMenu.close();
|
2014-01-28 23:43:06 +00:00
|
|
|
multiselect.close();
|
2013-05-03 11:57:08 +00:00
|
|
|
|
2014-01-22 10:12:51 +00:00
|
|
|
if (hash[0]!==undefined) albumID = hash[0];
|
|
|
|
if (hash[1]!==undefined) photoID = hash[1];
|
2013-05-03 11:57:08 +00:00
|
|
|
|
|
|
|
if (albumID&&photoID) {
|
|
|
|
|
2013-09-03 09:59:30 +00:00
|
|
|
// Trash data
|
|
|
|
albums.json = null;
|
|
|
|
photo.json = null;
|
|
|
|
|
|
|
|
// Show Photo
|
2014-01-22 10:12:51 +00:00
|
|
|
if (lychee.content.html()===""||($("#search").length&&$("#search").val().length!==0)) {
|
2013-05-03 11:57:08 +00:00
|
|
|
lychee.content.hide();
|
2013-09-03 09:59:30 +00:00
|
|
|
album.load(albumID, true);
|
2013-05-03 11:57:08 +00:00
|
|
|
}
|
2013-09-03 09:59:30 +00:00
|
|
|
photo.load(photoID, albumID);
|
2013-05-03 11:57:08 +00:00
|
|
|
|
|
|
|
} else if (albumID) {
|
|
|
|
|
2013-09-03 09:59:30 +00:00
|
|
|
// Trash data
|
|
|
|
albums.json = null;
|
|
|
|
photo.json = null;
|
|
|
|
|
2013-05-03 11:57:08 +00:00
|
|
|
// Show Album
|
2013-09-03 09:59:30 +00:00
|
|
|
if (visible.photo()) view.photo.hide();
|
|
|
|
if (album.json&&albumID==album.json.id) view.album.title();
|
|
|
|
else album.load(albumID);
|
2013-05-03 11:57:08 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
|
2013-09-03 09:59:30 +00:00
|
|
|
// Trash data
|
|
|
|
albums.json = null;
|
|
|
|
album.json = null;
|
|
|
|
photo.json = null;
|
|
|
|
search.code = "";
|
|
|
|
|
2013-05-03 11:57:08 +00:00
|
|
|
// Show Albums
|
2014-01-22 10:12:51 +00:00
|
|
|
if (visible.album()) view.album.hide();
|
2013-09-03 09:59:30 +00:00
|
|
|
if (visible.photo()) view.photo.hide();
|
2013-05-03 11:57:08 +00:00
|
|
|
albums.load();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-09-03 09:59:30 +00:00
|
|
|
getUpdate: function() {
|
2013-05-03 11:57:08 +00:00
|
|
|
|
2013-09-03 09:59:30 +00:00
|
|
|
$.ajax({
|
|
|
|
url: lychee.update_path,
|
|
|
|
success: function(data) { if (data!=lychee.version) $("#version span").show(); }
|
|
|
|
});
|
2013-05-03 11:57:08 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
|
2014-01-22 10:12:51 +00:00
|
|
|
setTitle: function(title, editable) {
|
2013-09-03 09:59:30 +00:00
|
|
|
|
2014-01-22 10:12:51 +00:00
|
|
|
if (title==="Albums") document.title = "Lychee";
|
2013-09-03 09:59:30 +00:00
|
|
|
else document.title = "Lychee - " + title;
|
|
|
|
|
|
|
|
if (editable) $("#title").addClass("editable");
|
|
|
|
else $("#title").removeClass("editable");
|
2013-05-03 11:57:08 +00:00
|
|
|
|
2013-09-03 09:59:30 +00:00
|
|
|
$("#title").html(title);
|
2013-05-03 11:57:08 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-09-03 09:59:30 +00:00
|
|
|
setMode: function(mode) {
|
2013-05-03 11:57:08 +00:00
|
|
|
|
2014-01-22 10:12:51 +00:00
|
|
|
$("#button_settings, #button_settings, #button_search, #search, #button_trash_album, #button_share_album, .button_add, .button_divider").remove();
|
|
|
|
$("#button_trash, #button_move, #button_share, #button_star").remove();
|
2013-05-03 11:57:08 +00:00
|
|
|
|
2013-09-03 09:59:30 +00:00
|
|
|
$(document)
|
|
|
|
.on("mouseenter", "#title.editable", function() { $(this).removeClass("editable") })
|
|
|
|
.off("click", "#title.editable")
|
|
|
|
.off("touchend", "#title.editable")
|
|
|
|
.off("contextmenu", ".photo")
|
|
|
|
.off("contextmenu", ".album")
|
|
|
|
.off("drop");
|
2013-05-03 11:57:08 +00:00
|
|
|
|
2013-09-03 09:59:30 +00:00
|
|
|
Mousetrap
|
|
|
|
.unbind('n')
|
|
|
|
.unbind('u')
|
|
|
|
.unbind('s')
|
|
|
|
.unbind('backspace');
|
2013-05-03 11:57:08 +00:00
|
|
|
|
2014-01-22 10:12:51 +00:00
|
|
|
if (mode==="public") {
|
2013-05-03 11:57:08 +00:00
|
|
|
|
2014-01-22 10:12:51 +00:00
|
|
|
$("header #button_signin, header #hostedwith").show();
|
2013-09-03 09:59:30 +00:00
|
|
|
lychee.publicMode = true;
|
|
|
|
|
2014-01-22 10:12:51 +00:00
|
|
|
} else if (mode==="view") {
|
2013-05-03 11:57:08 +00:00
|
|
|
|
2013-09-03 09:59:30 +00:00
|
|
|
Mousetrap.unbind('esc');
|
|
|
|
$("#button_back, a#next, a#previous").remove();
|
2013-05-03 11:57:08 +00:00
|
|
|
|
2013-09-03 09:59:30 +00:00
|
|
|
lychee.publicMode = true;
|
|
|
|
lychee.viewMode = true;
|
|
|
|
|
|
|
|
}
|
2013-05-03 11:57:08 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
animate: function(obj, animation) {
|
|
|
|
|
2013-09-03 09:59:30 +00:00
|
|
|
var animations = [
|
2013-05-03 11:57:08 +00:00
|
|
|
["fadeIn", "fadeOut"],
|
|
|
|
["contentZoomIn", "contentZoomOut"]
|
|
|
|
];
|
|
|
|
|
|
|
|
if (!obj.jQuery) obj = $(obj);
|
|
|
|
|
2013-09-03 09:59:30 +00:00
|
|
|
for (var i = 0; i < animations.length; i++) {
|
2013-05-03 11:57:08 +00:00
|
|
|
for (var x = 0; x < animations[i].length; x++) {
|
|
|
|
if (animations[i][x]==animation) {
|
|
|
|
obj.removeClass(animations[i][0] + " " + animations[i][1]).addClass(animation);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-09-03 09:59:30 +00:00
|
|
|
loadDropbox: function(callback) {
|
|
|
|
|
|
|
|
if (!lychee.dropbox) {
|
|
|
|
|
|
|
|
loadingBar.show();
|
|
|
|
|
|
|
|
var g = document.createElement("script"),
|
|
|
|
s = document.getElementsByTagName("script")[0];
|
|
|
|
|
|
|
|
g.src = "https://www.dropbox.com/static/api/1/dropins.js";
|
|
|
|
g.id = "dropboxjs";
|
|
|
|
g.type = "text/javascript";
|
|
|
|
g.async = "true";
|
|
|
|
g.setAttribute("data-app-key", "iq7lioj9wu0ieqs");
|
|
|
|
g.onload = g.onreadystatechange = function() {
|
|
|
|
var rs = this.readyState;
|
2014-01-22 10:12:51 +00:00
|
|
|
if (rs&&rs!=="complete"&&rs!=="loaded") return;
|
2013-09-03 09:59:30 +00:00
|
|
|
lychee.dropbox = true;
|
|
|
|
loadingBar.hide();
|
|
|
|
callback();
|
|
|
|
};
|
|
|
|
s.parentNode.insertBefore(g, s);
|
|
|
|
|
|
|
|
} else callback();
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2014-01-22 10:12:51 +00:00
|
|
|
error: function(errorThrown, params, data) {
|
2013-05-03 11:57:08 +00:00
|
|
|
|
2014-01-22 10:12:51 +00:00
|
|
|
console.log("Error Description: " + errorThrown);
|
|
|
|
console.log("Error Params: " + params);
|
|
|
|
console.log("Server Response: " + data);
|
|
|
|
loadingBar.show("error", errorThrown);
|
2013-05-03 11:57:08 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|