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 */
|
|
|
|
$("#button_signout").on(event_name, function() {
|
|
|
|
modal = build.modal("Sign Out", "Are you sure you want to leave and log out?", ["Sign out", "Stay here"], ["lychee.logout();", ""]);
|
2012-10-02 15:48:08 +00:00
|
|
|
$("body").append(modal);
|
|
|
|
});
|
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-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() });
|
|
|
|
$("#button_edit_album").on(event_name, function() { albums.rename() });
|
|
|
|
$("#button_edit").on(event_name, function() { photos.rename() });
|
|
|
|
$("#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() })
|
|
|
|
.on(event_name, "#edit_title", function() { photos.rename() })
|
|
|
|
.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-05-03 11:57:08 +00:00
|
|
|
if ($(".message").length&&$(".sign_in").length==0) lychee.closeModal();
|
|
|
|
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 */
|
|
|
|
.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 */
|
|
|
|
.on(event_name, "#title.editable", function() { if (visible.imageview()) photos.rename(); else albums.rename(); })
|
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)
|
|
|
|
.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)
|
|
|
|
.bind("mouseleave", lychee.hideControls);
|
2013-01-15 20:21:36 +00:00
|
|
|
|
2013-05-03 11:57:08 +00:00
|
|
|
/* Upload */
|
2013-05-24 11:43:46 +00:00
|
|
|
$(document.documentElement)
|
2013-05-24 12:27:23 +00:00
|
|
|
.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-05-24 11:43:46 +00:00
|
|
|
});
|