2012-10-02 15:48:08 +00:00
|
|
|
/**
|
|
|
|
* @name main.js
|
|
|
|
* @author Philipp Maurer
|
|
|
|
* @author Tobias Reich
|
2013-05-03 11:57:08 +00:00
|
|
|
* @copyright 2013 by Philipp Maurer, Tobias Reich
|
2012-10-02 15:48:08 +00:00
|
|
|
*/
|
|
|
|
|
2013-05-03 11:57:08 +00:00
|
|
|
/* Modules */
|
|
|
|
lychee.init("php/api.php", "");
|
2012-10-02 15:48:08 +00:00
|
|
|
|
|
|
|
$(document).ready(function(){
|
|
|
|
|
2013-01-15 20:21:36 +00:00
|
|
|
/* Event Name */
|
|
|
|
if (mobileBrowser()) event_name = "touchend";
|
|
|
|
else event_name = "click";
|
|
|
|
|
2013-05-03 11:57:08 +00:00
|
|
|
/* Toolbar */
|
2013-06-17 18:40:04 +00:00
|
|
|
$("#button_signout").on(event_name, lychee.logout);
|
2013-05-03 11:57:08 +00:00
|
|
|
$("#button_download").on(event_name, function() {
|
2012-10-02 15:48:08 +00:00
|
|
|
link = $("#image_view #image").css("background-image").replace(/"/g,"").replace(/url\(|\)$/ig, "");
|
|
|
|
window.open(link,"_newtab");
|
|
|
|
});
|
2013-05-03 11:57:08 +00:00
|
|
|
$("#button_share").on(event_name, function(e) {
|
|
|
|
if ($("#button_share a.active").length) contextMenu.share(lychee.image_view.attr("data-id"), e.pageX, e.pageY);
|
|
|
|
else photos.setPublic(e);
|
2012-10-02 15:48:08 +00:00
|
|
|
});
|
2013-06-17 18:40:04 +00:00
|
|
|
$("#button_share_album").on(event_name, function(e) {
|
|
|
|
if ($("#button_share_album a.active").length) contextMenu.share_album(lychee.content.attr("data-id"), e.pageX, e.pageY);
|
|
|
|
else albums.setPublic(e);
|
|
|
|
});
|
2013-05-03 11:57:08 +00:00
|
|
|
$("#button_trash_album").on(event_name, function() { albums.deleteDialog(lychee.content.attr("data-id")) });
|
|
|
|
$("#button_move").on(event_name, function(e) { contextMenu.move(lychee.image_view.attr("data-id"), e.pageX, e.pageY) });
|
|
|
|
$("#button_trash").on(event_name, function() { photos.deleteDialog() });
|
2013-06-17 18:40:04 +00:00
|
|
|
$("#button_edit_album").on(event_name, function() { albums.setTitle() });
|
|
|
|
$("#button_edit").on(event_name, function() { photos.setTitle() });
|
2013-05-03 11:57:08 +00:00
|
|
|
$("#button_info").on(event_name, function() { photos.showInfobox() });
|
|
|
|
$("#button_archive").on(event_name, function() { albums.getArchive() });
|
|
|
|
$("#button_star").on(event_name, function() { photos.setStar() });
|
|
|
|
$(".copylink").on(event_name, function() { $(this).select() });
|
|
|
|
|
|
|
|
/* Search */
|
|
|
|
$("#search").on("keyup click", function() { search.find($(this).val()) });
|
|
|
|
|
|
|
|
/* Back Buttons */
|
|
|
|
$("#button_back_home").on(event_name, function() { lychee.goto("") });
|
|
|
|
$("#button_back").on(event_name, function() { lychee.goto("a" + lychee.content.attr("data-id")) });
|
|
|
|
|
|
|
|
/* Image View */
|
|
|
|
$("#image_view")
|
|
|
|
.on(event_name, "a#previous", photos.previous)
|
|
|
|
.on(event_name, "a#next", photos.next);
|
|
|
|
|
|
|
|
/* Infobox */
|
|
|
|
$("#infobox")
|
|
|
|
.on(event_name, ".header a", function() { photos.hideInfobox() })
|
2013-06-17 18:40:04 +00:00
|
|
|
.on(event_name, "#edit_title", function() { photos.setTitle() })
|
2013-05-03 11:57:08 +00:00
|
|
|
.on(event_name, "#edit_description", function() { photos.setDescription() });
|
|
|
|
|
|
|
|
/* Keyboard */
|
|
|
|
Mousetrap
|
|
|
|
.bind('n', function(e) { $("body").append(build.addModal) })
|
|
|
|
.bind('u', function(e) { $("#auswahl").html(""); $("#upload_files").click() })
|
|
|
|
.bind('s', function(e) { if (visible.imageview()) $("#button_star").click() })
|
|
|
|
.bind('f', function(e) { if (visible.imageview()) $("#button_download").click() })
|
|
|
|
.bind('i', function(e) { if (visible.imageview()) photos.showInfobox() })
|
|
|
|
.bind('backspace', function(e) { if (visible.imageview()) photos.deleteDialog() })
|
|
|
|
.bind('left', function(e) { if (visible.imageview()) photos.previous() })
|
|
|
|
.bind('right', function(e) { if (visible.imageview()) photos.next() });
|
|
|
|
|
|
|
|
Mousetrap.bindGlobal('enter', function(e) {
|
|
|
|
if ($(".message .button.active").length) $(".message .button.active").addClass("pressed").click()
|
2012-10-02 15:48:08 +00:00
|
|
|
});
|
2013-01-15 20:21:36 +00:00
|
|
|
|
2013-05-03 11:57:08 +00:00
|
|
|
Mousetrap.bindGlobal('esc', function(e) {
|
2012-10-02 15:48:08 +00:00
|
|
|
e.preventDefault();
|
2013-06-17 18:40:04 +00:00
|
|
|
if ($(".message").length) lychee.closeModal();
|
2013-05-03 11:57:08 +00:00
|
|
|
else if (visible.infobox()) photos.hideInfobox();
|
|
|
|
else if (visible.imageview()) lychee.goto("a" + lychee.content.attr("data-id"));
|
|
|
|
else if (visible.albums()&&$("#search").val().length!=0) search.reset();
|
2012-10-02 15:48:08 +00:00
|
|
|
});
|
|
|
|
|
2013-05-03 11:57:08 +00:00
|
|
|
/* Document */
|
|
|
|
$(document)
|
2013-01-15 20:21:36 +00:00
|
|
|
|
2013-05-03 11:57:08 +00:00
|
|
|
/* Login */
|
2013-06-17 18:40:04 +00:00
|
|
|
.on(event_name, "#button_signin", function() { lychee.showLogin() })
|
2013-05-03 11:57:08 +00:00
|
|
|
.on("keyup", "#password", function() { if ($(this).val().length>0) $(this).removeClass("error") })
|
2013-01-15 20:21:36 +00:00
|
|
|
|
2013-05-03 11:57:08 +00:00
|
|
|
/* Toolbar */
|
2013-06-17 18:40:04 +00:00
|
|
|
.on(event_name, "#title.editable", function() { if (visible.imageview()) photos.setTitle(); else albums.setTitle(); })
|
2012-10-02 15:48:08 +00:00
|
|
|
|
2013-05-03 11:57:08 +00:00
|
|
|
/* Navigation */
|
|
|
|
.on("click", ".album", function() { lychee.goto("a" + $(this).attr("data-id")) })
|
|
|
|
.on("click", ".photo", function() {
|
|
|
|
if (lychee.content.attr("data-id")!="") lychee.goto("a" + lychee.content.attr("data-id") + "p" + $(this).attr("data-id"));
|
|
|
|
else lychee.goto("a" + $(this).attr("data-album-id") + "p" + $(this).attr("data-id"));
|
|
|
|
})
|
2012-10-02 15:48:08 +00:00
|
|
|
|
2013-05-03 11:57:08 +00:00
|
|
|
/* Modal */
|
|
|
|
.on(event_name, ".message .close", lychee.closeModal)
|
2012-10-02 15:48:08 +00:00
|
|
|
|
2013-05-03 11:57:08 +00:00
|
|
|
/* Add Dialog */
|
|
|
|
.on(event_name, ".button_add", function() { $("body").append(build.addModal) })
|
|
|
|
.on(event_name, "#add_album", albums.add)
|
2013-06-17 18:40:04 +00:00
|
|
|
.on(event_name, "#add_link", lychee.importUrl)
|
2013-05-03 11:57:08 +00:00
|
|
|
.on(event_name, "#add_photo", function() { $("#auswahl").html(""); $("#upload_files").click() })
|
2012-10-02 15:48:08 +00:00
|
|
|
|
2013-05-03 11:57:08 +00:00
|
|
|
/* Upload */
|
|
|
|
.on("change", "#upload_files", function() { lychee.closeModal(); lychee.upload(this.files); })
|
2013-01-15 20:21:36 +00:00
|
|
|
|
2013-05-03 11:57:08 +00:00
|
|
|
/* Context Menu */
|
|
|
|
.on("contextmenu", ".photo", contextMenu.photo)
|
|
|
|
.on("contextmenu", ".album", contextMenu.album)
|
|
|
|
.on(event_name, ".contextmenu_bg", contextMenu.close)
|
2013-01-15 20:21:36 +00:00
|
|
|
|
2013-05-03 11:57:08 +00:00
|
|
|
/* Infobox */
|
|
|
|
.on(event_name, "#infobox_overlay", function() { photos.hideInfobox() })
|
2013-01-15 20:21:36 +00:00
|
|
|
|
2013-05-03 11:57:08 +00:00
|
|
|
/* Controls */
|
|
|
|
.bind("mouseenter", lychee.showControls)
|
2013-06-17 18:40:04 +00:00
|
|
|
.bind("mouseleave", lychee.hideControls)
|
2013-01-15 20:21:36 +00:00
|
|
|
|
2013-06-17 18:40:04 +00:00
|
|
|
/* Upload */
|
|
|
|
.on("dragover", function(e) { e.preventDefault(); }, false)
|
|
|
|
.on("drop", function(e) {
|
|
|
|
e.stopPropagation();
|
|
|
|
e.preventDefault();
|
|
|
|
lychee.upload(e.originalEvent.dataTransfer.files);
|
|
|
|
return true;
|
|
|
|
});
|
2013-01-15 20:21:36 +00:00
|
|
|
|
2013-05-03 11:57:08 +00:00
|
|
|
/* Init */
|
|
|
|
lychee.ready();
|
2013-01-15 20:21:36 +00:00
|
|
|
|
2013-06-17 18:40:04 +00:00
|
|
|
});
|