main.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /**
  2. * @description Used to view single photos with view.php
  3. * @copyright 2014 by Tobias Reich
  4. */
  5. var header = $('header'),
  6. headerTitle = $('#title'),
  7. imageview = $('#imageview'),
  8. api_path = 'php/api.php',
  9. infobox = $('#infobox');
  10. $(document).ready(function(){
  11. /* Event Name */
  12. if (mobileBrowser()) event_name = 'touchend';
  13. else event_name = 'click';
  14. /* Window */
  15. $(window).keydown(key);
  16. /* Infobox */
  17. $(document).on(event_name, '#infobox .header a', function() { hideInfobox() });
  18. $(document).on(event_name, '#infobox_overlay', function() { hideInfobox() });
  19. $('#button_info').on(event_name, function() { showInfobox() });
  20. /* Direct Link */
  21. $('#button_direct').on(event_name, function() {
  22. link = $('#imageview #image').css('background-image').replace(/"/g,'').replace(/url\(|\)$/ig, '');
  23. window.open(link,'_newtab');
  24. });
  25. loadPhotoInfo(gup('p'));
  26. });
  27. key = function(e) {
  28. code = (e.keyCode ? e.keyCode : e.which);
  29. if (code===27&&visibleInfobox()) { hideInfobox(); e.preventDefault(); }
  30. }
  31. visibleInfobox = function() {
  32. if (parseInt(infobox.css('right').replace('px', ''))<0) return false;
  33. else return true;
  34. }
  35. isPhotoSmall = function(photo) {
  36. size = {
  37. width: false,
  38. height: false
  39. };
  40. if (photo.width<$(window).width()-60) size.width = true;
  41. if (photo.height<$(window).height()-100) size.height = true;
  42. if (size.width&&size.height) return true;
  43. else return false;
  44. }
  45. showInfobox = function() {
  46. $('body').append("<div id='infobox_overlay' class='fadeIn'></div>");
  47. infobox.addClass('active');
  48. }
  49. hideInfobox = function() {
  50. $('#infobox_overlay').removeClass('fadeIn').addClass('fadeOut');
  51. setTimeout(function() { $('#infobox_overlay').remove() }, 300);
  52. infobox.removeClass('active');
  53. }
  54. loadPhotoInfo = function(photoID) {
  55. params = 'function=getPhoto&photoID=' + photoID + '&albumID=0&password=""';
  56. $.ajax({type: 'POST', url: api_path, data: params, dataType: 'json', success: function(data) {
  57. if (!data.title) data.title = 'Untitled';
  58. document.title = 'Lychee - ' + data.title;
  59. headerTitle.html(data.title);
  60. imageview.attr('data-id', photoID);
  61. 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>");
  62. else imageview.html("<div id='image' style='background-image: url(" + data.url + ");'></div>");
  63. imageview.removeClass('fadeOut').addClass('fadeIn').show();
  64. infobox.html(build.infoboxPhoto(data, true)).show();
  65. }, error: ajaxError });
  66. }
  67. ajaxError = function(jqXHR, textStatus, errorThrown) {
  68. console.log(jqXHR);
  69. console.log(textStatus);
  70. console.log(errorThrown);
  71. }