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

130 lines
2.9 KiB

10 years ago
/**
* @description Used to view single photos with view.php
* @copyright 2015 by Tobias Reich
10 years ago
*/
9 years ago
var lychee = { content: $('#content') },
loadingBar = { show() {}, hide() {} }
imageview = $('#imageview');
10 years ago
9 years ago
$(document).ready(function() {
10 years ago
// Event Name
var touchendSupport = (/Android|iPhone|iPad|iPod/i).test(navigator.userAgent || navigator.vendor || window.opera) && ('ontouchend' in document.documentElement),
eventName = (touchendSupport===true ? 'touchend' : 'click');
10 years ago
// Set API error handler
9 years ago
api.onError = error;
10 years ago
// Infobox
9 years ago
header.dom('#button_info').on(eventName, sidebar.toggle);
10 years ago
// Direct Link
9 years ago
header.dom('#button_direct').on(eventName, 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
});
getPhotoSize = function(photo) {
// Size can be 'big', 'medium' or 'small'
// Default is big
// Small is centered in the middle of the screen
var size = 'big',
scaled = false,
hasMedium = photo.medium!=='',
pixelRatio = window.devicePixelRatio,
view = {
width: $(window).width()-60,
height: $(window).height()-100
};
// Detect if the photo will be shown scaled,
// because the screen size is smaller than the photo
if (photo.width>view.width||
photo.width>view.height) scaled = true;
// Calculate pixel ratio of screen
if (pixelRatio!==undefined&&pixelRatio>1) {
view.width = view.width * pixelRatio;
view.height = view.height * pixelRatio;
}
10 years ago
// Medium available and
// Medium still bigger than screen
if (hasMedium===true&&
(1920>view.width&&1080>view.height)) size = 'medium';
10 years ago
// Photo not scaled
// Photo smaller then screen
if (scaled===false&&
(photo.width<view.width&&
photo.width<view.height)) size = 'small';
10 years ago
return size;
10 years ago
}
9 years ago
loadPhotoInfo = function(photoID) {
10 years ago
9 years ago
var params = {
photoID,
albumID: 0,
password: ''
}
10 years ago
9 years ago
api.post('Photo::get', params, function(data) {
10 years ago
if (data==='Warning: Photo private!'||
data==='Warning: Wrong password!') {
$('body').append(build.no_content('question-mark'));
$('body').removeClass('view');
header.dom().remove();
return false;
}
9 years ago
/* Set title */
10 years ago
9 years ago
if (!data.title) data.title = 'Untitled';
document.title = 'Lychee - ' + data.title;
header.dom('#title').html(data.title);
10 years ago
9 years ago
/* Render HTML */
10 years ago
var size = getPhotoSize(data);
9 years ago
imageview.html(build.imageview(data, size, true));
imageview.find('.arrow_wrapper').remove();
9 years ago
imageview.addClass('fadeIn').show();
10 years ago
9 years ago
/* Render Sidebar */
10 years ago
9 years ago
var structure = sidebar.createStructure.photo(data),
html = sidebar.render(structure);
10 years ago
9 years ago
sidebar.dom('.wrapper').html(html);
sidebar.bind();
10 years ago
9 years ago
});
10 years ago
}
9 years ago
error = function(errorThrown, params, data) {
10 years ago
console.error({
description: errorThrown,
params: params,
response: data
});
10 years ago
9 years ago
loadingBar.show('error', errorThrown);
10 years ago
}