2012-10-02 15:48:08 +00:00
|
|
|
/**
|
|
|
|
* @name view.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
|
|
|
*/
|
|
|
|
|
|
|
|
var header = $("header"),
|
|
|
|
headerTitle = $("#title"),
|
2013-09-03 09:59:30 +00:00
|
|
|
imageview = $("#imageview"),
|
2012-10-02 15:48:08 +00:00
|
|
|
api_path = "php/api.php",
|
|
|
|
infobox = $("#infobox");
|
2013-01-15 20:21:36 +00:00
|
|
|
|
2012-10-02 15:48:08 +00:00
|
|
|
$(document).ready(function(){
|
|
|
|
|
2013-05-03 11:57:08 +00:00
|
|
|
/* Event Name */
|
|
|
|
if (mobileBrowser()) event_name = "touchend";
|
|
|
|
else event_name = "click";
|
|
|
|
|
2012-10-25 10:22:04 +00:00
|
|
|
/* Window */
|
|
|
|
$(window).keydown(key);
|
|
|
|
|
2012-10-02 15:48:08 +00:00
|
|
|
/* Infobox */
|
2013-05-03 11:57:08 +00:00
|
|
|
$(document).on(event_name, "#infobox .header a", function() { hideInfobox() });
|
|
|
|
$(document).on(event_name, "#infobox_overlay", function() { hideInfobox() });
|
|
|
|
$("#button_info").on(event_name, function() { showInfobox() });
|
2012-10-02 15:48:08 +00:00
|
|
|
|
|
|
|
/* Download */
|
2013-05-03 11:57:08 +00:00
|
|
|
$("#button_download").on(event_name, function() {
|
2013-09-03 09:59:30 +00:00
|
|
|
link = $("#imageview #image").css("background-image").replace(/"/g,"").replace(/url\(|\)$/ig, "");
|
2012-10-02 15:48:08 +00:00
|
|
|
window.open(link,"_newtab");
|
|
|
|
});
|
2013-01-15 20:21:36 +00:00
|
|
|
|
2012-10-02 15:48:08 +00:00
|
|
|
loadPhotoInfo(gup("p"));
|
2013-01-15 20:21:36 +00:00
|
|
|
|
2012-10-02 15:48:08 +00:00
|
|
|
});
|
|
|
|
|
2012-10-25 10:22:04 +00:00
|
|
|
function key(e) {
|
|
|
|
|
|
|
|
code = (e.keyCode ? e.keyCode : e.which);
|
|
|
|
if (code==27&&visibleInfobox()) { hideInfobox(); e.preventDefault(); }
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function visibleInfobox() {
|
|
|
|
|
|
|
|
if (parseInt(infobox.css("right").replace("px", ""))<0) return false;
|
|
|
|
else return true;
|
2013-01-15 20:21:36 +00:00
|
|
|
|
2012-10-25 10:22:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function isPhotoSmall(photo) {
|
|
|
|
|
|
|
|
size = [
|
|
|
|
["width", false],
|
|
|
|
["height", false]
|
|
|
|
];
|
|
|
|
|
|
|
|
if (photo.width<$(window).width()-60) size["width"] = true;
|
|
|
|
if (photo.height<$(window).height()-100) size["height"] = true;
|
2013-01-15 20:21:36 +00:00
|
|
|
|
2012-10-25 10:22:04 +00:00
|
|
|
if (size["width"]&&size["height"]) return true;
|
|
|
|
else return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-10-02 15:48:08 +00:00
|
|
|
function showInfobox() {
|
|
|
|
|
|
|
|
$("body").append("<div id='infobox_overlay'></div>");
|
|
|
|
infobox.css("right", "0px");
|
2013-01-15 20:21:36 +00:00
|
|
|
|
2012-10-02 15:48:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function hideInfobox() {
|
|
|
|
|
|
|
|
$("#infobox_overlay").remove();
|
|
|
|
infobox.css("right", "-320px");
|
2013-01-15 20:21:36 +00:00
|
|
|
|
2012-10-02 15:48:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function loadPhotoInfo(photoID) {
|
|
|
|
|
2013-09-03 09:59:30 +00:00
|
|
|
params = "function=getPhoto&photoID=" + photoID + "&albumID=0&password=''";
|
2012-10-02 15:48:08 +00:00
|
|
|
$.ajax({type: "POST", url: api_path, data: params, dataType: "json", success: function(data) {
|
|
|
|
|
|
|
|
if (!data.title) data.title = "Untitled";
|
|
|
|
document.title = "Lychee - " + data.title;
|
|
|
|
headerTitle.html(data.title);
|
|
|
|
|
2013-09-03 09:59:30 +00:00
|
|
|
data.url = "uploads/big/" + data.url;
|
|
|
|
|
|
|
|
imageview.attr("data-id", photoID);
|
|
|
|
if (isPhotoSmall(data)) imageview.html("<div id='image' class='small' style='background-image: url(" + data.url + "); width: " + data.width + "px; height: " + data.height + "px; margin-top: -" + parseInt((data.height/2)-20) + "px; margin-left: -" + data.width/2 + "px;'></div>");
|
|
|
|
else imageview.html("<div id='image' style='background-image: url(" + data.url + "); top: 70px; right: 30px; bottom: 30px; left: 30px;'></div>");
|
|
|
|
imageview.removeClass("fadeOut").addClass("fadeIn").show();
|
2013-01-15 20:21:36 +00:00
|
|
|
|
2013-05-03 11:57:08 +00:00
|
|
|
infobox.html(build.infobox(data, true)).show();
|
2012-10-02 15:48:08 +00:00
|
|
|
|
|
|
|
}, error: ajaxError });
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function ajaxError(jqXHR, textStatus, errorThrown) {
|
|
|
|
|
|
|
|
console.log(jqXHR);
|
|
|
|
console.log(textStatus);
|
|
|
|
console.log(errorThrown);
|
2013-01-15 20:21:36 +00:00
|
|
|
|
2012-10-02 15:48:08 +00:00
|
|
|
}
|