lychee/js/main.js

119 lines
4.3 KiB
JavaScript
Raw Normal View History

2012-10-02 15:48:08 +00:00
/**
* @name main.js
* @author Philipp Maurer
* @author Tobias Reich
* @copyright 2012 by Philipp Maurer, Tobias Reich
*/
var header = $("header"),
headerTitle = $("#title"),
content = $("#content"),
image_view = $("#image_view"),
loading = $("#loading"),
infobox = $("#infobox"),
api_path = "php/api.php",
version = "1.0.2";
2012-10-02 15:48:08 +00:00
$(document).ready(function(){
/* Event Name */
if (mobileBrowser()) event_name = "touchend";
else event_name = "click";
2012-10-02 15:48:08 +00:00
/* Login */
$("#password").live("keyup", function() {
if ($(this).val().length>0) $(this).removeClass("error");
});
/* Add Dialog */
$(".button_add").live(event_name, function() { $("body").append(buildAddModal) });
$("#add_album").live(event_name, addAlbum);
$("#add_photo").live(event_name, function() { $("#auswahl").html(""); $("#upload_files").click() });
2012-10-02 15:48:08 +00:00
/* Toolbar Buttons */
$("#button_signout").live(event_name, function() {
2012-10-02 15:48:08 +00:00
modal = buildModal("Sign Out", "Are you sure you want to leave and log out?", ["Sign out", "Stay here"], ["logout();", ""]);
$("body").append(modal);
});
$("#button_download").live(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");
});
$("#button_move").live(event_name, function(e) {
2012-10-02 15:48:08 +00:00
showContextMenuMove(image_view.attr("data-id"), e.pageX, e.pageY);
});
$("#button_trash_album").live(event_name, function() {
2012-10-02 15:48:08 +00:00
if (content.attr("data-id")=="0") deleteUnsorted();
else deleteAlbum();
});
$("#button_trash").live(event_name, function() { deletePhoto() });
$("#button_edit_album").live(event_name, function() { renameAlbum() });
$("#button_edit").live(event_name, function() { renamePhoto() });
$("#button_info").live(event_name, function() { showInfobox() });
$("#button_archive").live(event_name, function() { getAlbumArchive() });
$("#button_sync").live(event_name, function() { syncFolder() });
2012-10-02 15:48:08 +00:00
/* Rename Album/Photo via Titlebar */
$("#title.editable").live(event_name, function() {
2012-10-02 15:48:08 +00:00
if (visibleImageview()) renamePhoto(); else renameAlbum();
});
2012-10-02 15:48:08 +00:00
/* Context Menu */
$(".photo").live("contextmenu", function(e) {
e.preventDefault();
showContextMenuPhoto($(this).attr("data-id"), e.pageX, e.pageY);
});
$(".contextmenu_bg").live(event_name, closeContextMenu);
2012-10-02 15:48:08 +00:00
/* Star/Share Photo */
$("#button_star").live(event_name, setPhotoStar);
$("#button_share").live(event_name, function(e) {
2012-10-02 15:48:08 +00:00
if ($("#button_share a.active").length) showContextMenuShare(image_view.attr("data-id"), e.pageX, e.pageY);
else setPhotoPublic(e);
});
$(".copylink").live(event_name, function() { $(this).select() });
2012-10-02 15:48:08 +00:00
/* Upload */
$("#upload_files").live("change", function() {
closeModal();
handleFiles(this.files);
$("#upload_button").click();
});
2012-10-02 15:48:08 +00:00
/* Search */
$("#search").live("keyup", function() { search($(this).val()) });
/* Nav Forward */
$(".album").live("click", function() { setURL("a" + $(this).attr("data-id")) });
$(".photo").live("click", function() { setURL("a" + content.attr("data-id") + "p" + $(this).attr("data-id")) });
/* Nav Back */
$("#button_back_home").live(event_name, function() { setURL("") });
$("#button_back").live(event_name, function() { setURL("a" + content.attr("data-id")) });
2012-10-02 15:48:08 +00:00
/* Close Modal */
$(".message a.close").live(event_name, closeModal);
2012-10-02 15:48:08 +00:00
/* Image View */
$("#image_view a#previous").live(event_name, loadPreviousPhoto);
$("#image_view a#next").live(event_name, loadNextPhoto);
2012-10-02 15:48:08 +00:00
/* Infobox */
$("#infobox_overlay, #infobox .header a").live(event_name, function() { hideInfobox() });
$("#edit_description").live(event_name, function() { setPhotoDescription() });
2012-10-02 15:48:08 +00:00
/* Window */
$(window).keydown(key);
$(window).bind("popstate", getURL);
$(window).bind("mouseleave", hideControls);
$(window).bind("mouseenter", showControls);
2012-10-02 15:48:08 +00:00
/* Init */
if ((BrowserDetect.browser=="Explorer")||(BrowserDetect.browser=="Safari"&&BrowserDetect.version<5)||(BrowserDetect.browser=="Chrome"&&BrowserDetect.version<18)||(BrowserDetect.browser=="Firefox"&&BrowserDetect.version<15)) {
2012-10-02 15:48:08 +00:00
modal = buildModal("Browser not supported", "You are currently using an outdated or unsupported Browser. This site might not work properly. Please consider to update your Browser!", ["Leave"], ["location.href = 'http://browsehappy.com';"]);
$("body").append(modal);
2012-10-02 15:48:08 +00:00
} else init();
2012-10-02 15:48:08 +00:00
});