view.js 2.7 KB

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