You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
lychee/src/scripts/view/main.js

119 lines
2.7 KiB

10 years ago
/**
* @description Used to view single photos with view.php
10 years ago
* @copyright 2014 by Tobias Reich
10 years ago
*/
var header = $('header'),
headerTitle = $('#title'),
imageview = $('#imageview'),
api_path = 'php/api.php',
infobox = $('#infobox');
10 years ago
$(document).ready(function(){
/* Event Name */
if (mobileBrowser()) event_name = 'touchend';
else event_name = 'click';
10 years ago
/* Window */
$(window).keydown(key);
/* Infobox */
$(document) .on(event_name, '#infobox .header a', hideInfobox);
$(document) .on(event_name, '#infobox_overlay', hideInfobox);
$('#button_info') .on(event_name, showInfobox);
10 years ago
/* Direct Link */
10 years ago
$('#button_direct').on(event_name, function() {
10 years ago
var link = $('#imageview #image').css('background-image').replace(/"/g,'').replace(/url\(|\)$/ig, '');
window.open(link, '_newtab');
10 years ago
});
10 years ago
loadPhotoInfo(gup('p'));
10 years ago
});
10 years ago
key = function(e) {
10 years ago
var code = (e.keyCode ? e.keyCode : e.which);
if (code===27&&visibleInfobox()) {
hideInfobox();
e.preventDefault();
}
10 years ago
}
10 years ago
visibleInfobox = function() {
10 years ago
if (parseInt(infobox.css('right').replace('px', ''))<0) return false;
else return true;
10 years ago
}
10 years ago
isPhotoSmall = function(photo) {
10 years ago
var size = {
width: false,
height: false
10 years ago
};
10 years ago
if (photo.width<$(window).width()-60) size.width = true;
if (photo.height<$(window).height()-100) size.height = true;
10 years ago
if (size.width&&size.height) return true;
else return false;
10 years ago
}
10 years ago
showInfobox = function() {
10 years ago
10 years ago
$('body').append("<div id='infobox_overlay' class='fadeIn'></div>");
infobox.addClass('active');
10 years ago
}
10 years ago
hideInfobox = function() {
10 years ago
10 years ago
$('#infobox_overlay').removeClass('fadeIn').addClass('fadeOut');
setTimeout(function() { $('#infobox_overlay').remove() }, 300);
infobox.removeClass('active');
10 years ago
}
10 years ago
loadPhotoInfo = function(photoID) {
10 years ago
var params = 'function=getPhoto&photoID=' + photoID + '&albumID=0&password=""';
10 years ago
$.ajax({type: 'POST', url: api_path, data: params, dataType: 'json', success: function(data) {
10 years ago
10 years ago
if (!data.title) data.title = 'Untitled';
document.title = 'Lychee - ' + data.title;
10 years ago
headerTitle.html(data.title);
10 years ago
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 + ");'></div>");
10 years ago
imageview
.removeClass('fadeOut')
.addClass('fadeIn')
.show();
10 years ago
infobox.html(build.infoboxPhoto(data, true)).show();
}, error: ajaxError });
}
ajaxError = function(errorThrown, params, data) {
10 years ago
console.error({
description: errorThrown,
params: params,
response: data
});
10 years ago
}