2013-05-03 11:57:08 +00:00
|
|
|
/**
|
|
|
|
* @name lychee.js
|
|
|
|
* @author Philipp Maurer
|
|
|
|
* @author Tobias Reich
|
|
|
|
* @copyright 2013 by Philipp Maurer, Tobias Reich
|
|
|
|
*
|
|
|
|
* Lychee Module
|
|
|
|
* This module provides the basic functions of Lychee.
|
|
|
|
*/
|
|
|
|
|
2013-09-03 09:59:30 +00:00
|
|
|
var lychee = {
|
2013-05-03 11:57:08 +00:00
|
|
|
|
2013-09-03 09:59:30 +00:00
|
|
|
init: function() {
|
2013-05-03 11:57:08 +00:00
|
|
|
|
2013-10-20 11:08:39 +00:00
|
|
|
this.version = "1.3.2";
|
2013-09-03 09:59:30 +00:00
|
|
|
this.api_path = "php/api.php";
|
2013-06-17 18:40:04 +00:00
|
|
|
this.update_path = "http://lychee.electerious.com/version/index.php";
|
|
|
|
this.updateURL = "https://github.com/electerious/Lychee";
|
2013-09-03 09:59:30 +00:00
|
|
|
|
|
|
|
this.upload_path_thumb = "uploads/thumb/";
|
|
|
|
this.upload_path_big = "uploads/big/";
|
|
|
|
|
2013-06-17 18:40:04 +00:00
|
|
|
this.publicMode = false;
|
2013-09-03 09:59:30 +00:00
|
|
|
this.viewMode = false;
|
2013-06-17 18:40:04 +00:00
|
|
|
|
|
|
|
this.checkForUpdates = false;
|
2013-09-03 09:59:30 +00:00
|
|
|
|
|
|
|
this.dropbox = false;
|
2013-05-03 11:57:08 +00:00
|
|
|
|
|
|
|
this.loadingBar = $("#loading");
|
|
|
|
this.header = $("header");
|
|
|
|
this.content = $("#content");
|
2013-09-03 09:59:30 +00:00
|
|
|
this.imageview = $("#imageview");
|
2013-05-03 11:57:08 +00:00
|
|
|
this.infobox = $("#infobox");
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-09-03 09:59:30 +00:00
|
|
|
run: function() {
|
2013-06-17 18:40:04 +00:00
|
|
|
|
|
|
|
lychee.api("init", "json", function(data) {
|
|
|
|
lychee.checkForUpdates = data.config.checkForUpdates;
|
2013-09-03 09:59:30 +00:00
|
|
|
if (!data.loggedIn) lychee.setMode("public");
|
2013-06-17 18:40:04 +00:00
|
|
|
$(window).bind("popstate", lychee.load);
|
|
|
|
lychee.load();
|
2013-05-03 11:57:08 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-06-17 18:40:04 +00:00
|
|
|
api: function(params, type, callback, loading) {
|
|
|
|
|
|
|
|
if (loading==undefined) loadingBar.show();
|
2013-05-03 11:57:08 +00:00
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
type: "POST",
|
|
|
|
url: lychee.api_path,
|
|
|
|
data: "function=" + params,
|
|
|
|
dataType: type,
|
2013-06-17 18:40:04 +00:00
|
|
|
success:
|
|
|
|
function(data) {
|
2013-09-08 17:50:31 +00:00
|
|
|
setTimeout(function() { loadingBar.hide() }, 100);
|
2013-06-17 18:40:04 +00:00
|
|
|
callback(data);
|
|
|
|
},
|
2013-05-03 11:57:08 +00:00
|
|
|
error: lychee.error
|
|
|
|
});
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
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;
|
|
|
|
lychee.api(params, "text", function(data) {
|
|
|
|
if (data) {
|
2013-06-17 18:40:04 +00:00
|
|
|
localStorage.setItem("username", user);
|
|
|
|
window.location.reload();
|
2013-05-03 11:57:08 +00:00
|
|
|
} else {
|
|
|
|
$("#password").val("").addClass("error");
|
|
|
|
$(".message .button.active").removeClass("pressed");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-09-03 09:59:30 +00:00
|
|
|
loginDialog: function() {
|
2013-05-03 11:57:08 +00:00
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (lychee.checkForUpdates) 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
|
|
|
|
2013-09-03 09:59:30 +00:00
|
|
|
lychee.api("logout", "text", function(data) {
|
|
|
|
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 = "",
|
|
|
|
hash = document.location.hash.replace("#", "");
|
2013-05-03 11:57:08 +00:00
|
|
|
|
2013-09-03 09:59:30 +00:00
|
|
|
contextMenu.close();
|
2013-05-03 11:57:08 +00:00
|
|
|
|
2013-09-03 09:59:30 +00:00
|
|
|
if (hash.indexOf("a")!=-1) albumID = hash.split("p")[0].replace("a", "");
|
|
|
|
if (hash.indexOf("p")!=-1) photoID = hash.split("p")[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
|
2013-06-17 18:40:04 +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
|
|
|
if (!visible.photo()) view.photo.show();
|
|
|
|
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
|
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
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-09-03 09:59:30 +00:00
|
|
|
setTitle: function(title, count, editable) {
|
|
|
|
|
|
|
|
if (title=="Albums") document.title = "Lychee";
|
|
|
|
else document.title = "Lychee - " + title;
|
|
|
|
|
|
|
|
if (count) title += "<span> - " + count + " photos</span>";
|
|
|
|
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
|
|
|
|
2013-09-03 09:59:30 +00:00
|
|
|
$("#button_signout, #search, #button_trash_album, #button_share_album, #button_edit_album, .button_add, #button_archive, .button_divider").remove();
|
|
|
|
$("#button_trash, #button_move, #button_edit, #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
|
|
|
|
2013-09-03 09:59:30 +00:00
|
|
|
if (mode=="public") {
|
2013-05-03 11:57:08 +00:00
|
|
|
|
2013-09-03 09:59:30 +00:00
|
|
|
$("#button_signin").show();
|
|
|
|
lychee.publicMode = true;
|
|
|
|
|
|
|
|
} 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;
|
|
|
|
if (rs&&rs!="complete"&&rs!="loaded") return;
|
|
|
|
lychee.dropbox = true;
|
|
|
|
loadingBar.hide();
|
|
|
|
callback();
|
|
|
|
};
|
|
|
|
s.parentNode.insertBefore(g, s);
|
|
|
|
|
|
|
|
} else callback();
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-05-03 11:57:08 +00:00
|
|
|
error: function(jqXHR, textStatus, errorThrown) {
|
|
|
|
|
|
|
|
console.log(jqXHR);
|
|
|
|
console.log(textStatus);
|
|
|
|
console.log(errorThrown);
|
|
|
|
loadingBar.show("error", textStatus, errorThrown);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|