main.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /**
  2. * @name main.js
  3. * @author Philipp Maurer
  4. * @author Tobias Reich
  5. * @copyright 2013 by Philipp Maurer, Tobias Reich
  6. */
  7. /* Modules */
  8. lychee.init("php/api.php", "");
  9. $(document).ready(function(){
  10. /* Event Name */
  11. if (mobileBrowser()) event_name = "touchend";
  12. else event_name = "click";
  13. /* Toolbar */
  14. $("#button_signout").on(event_name, function() {
  15. modal = build.modal("Sign Out", "Are you sure you want to leave and log out?", ["Sign out", "Stay here"], ["lychee.logout();", ""]);
  16. $("body").append(modal);
  17. });
  18. $("#button_download").on(event_name, function() {
  19. link = $("#image_view #image").css("background-image").replace(/"/g,"").replace(/url\(|\)$/ig, "");
  20. window.open(link,"_newtab");
  21. });
  22. $("#button_share").on(event_name, function(e) {
  23. if ($("#button_share a.active").length) contextMenu.share(lychee.image_view.attr("data-id"), e.pageX, e.pageY);
  24. else photos.setPublic(e);
  25. });
  26. $("#button_trash_album").on(event_name, function() { albums.deleteDialog(lychee.content.attr("data-id")) });
  27. $("#button_move").on(event_name, function(e) { contextMenu.move(lychee.image_view.attr("data-id"), e.pageX, e.pageY) });
  28. $("#button_trash").on(event_name, function() { photos.deleteDialog() });
  29. $("#button_edit_album").on(event_name, function() { albums.rename() });
  30. $("#button_edit").on(event_name, function() { photos.rename() });
  31. $("#button_info").on(event_name, function() { photos.showInfobox() });
  32. $("#button_archive").on(event_name, function() { albums.getArchive() });
  33. $("#button_star").on(event_name, function() { photos.setStar() });
  34. $(".copylink").on(event_name, function() { $(this).select() });
  35. /* Search */
  36. $("#search").on("keyup click", function() { search.find($(this).val()) });
  37. /* Back Buttons */
  38. $("#button_back_home").on(event_name, function() { lychee.goto("") });
  39. $("#button_back").on(event_name, function() { lychee.goto("a" + lychee.content.attr("data-id")) });
  40. /* Image View */
  41. $("#image_view")
  42. .on(event_name, "a#previous", photos.previous)
  43. .on(event_name, "a#next", photos.next);
  44. /* Infobox */
  45. $("#infobox")
  46. .on(event_name, ".header a", function() { photos.hideInfobox() })
  47. .on(event_name, "#edit_title", function() { photos.rename() })
  48. .on(event_name, "#edit_description", function() { photos.setDescription() });
  49. /* Keyboard */
  50. Mousetrap
  51. .bind('n', function(e) { $("body").append(build.addModal) })
  52. .bind('u', function(e) { $("#auswahl").html(""); $("#upload_files").click() })
  53. .bind('s', function(e) { if (visible.imageview()) $("#button_star").click() })
  54. .bind('f', function(e) { if (visible.imageview()) $("#button_download").click() })
  55. .bind('i', function(e) { if (visible.imageview()) photos.showInfobox() })
  56. .bind('backspace', function(e) { if (visible.imageview()) photos.deleteDialog() })
  57. .bind('left', function(e) { if (visible.imageview()) photos.previous() })
  58. .bind('right', function(e) { if (visible.imageview()) photos.next() });
  59. Mousetrap.bindGlobal('enter', function(e) {
  60. if ($(".message .button.active").length) $(".message .button.active").addClass("pressed").click()
  61. });
  62. Mousetrap.bindGlobal('esc', function(e) {
  63. e.preventDefault();
  64. if ($(".message").length&&$(".sign_in").length==0) lychee.closeModal();
  65. else if (visible.infobox()) photos.hideInfobox();
  66. else if (visible.imageview()) lychee.goto("a" + lychee.content.attr("data-id"));
  67. else if (visible.albums()&&$("#search").val().length!=0) search.reset();
  68. });
  69. /* Document */
  70. $(document)
  71. /* Login */
  72. .on("keyup", "#password", function() { if ($(this).val().length>0) $(this).removeClass("error") })
  73. /* Toolbar */
  74. .on(event_name, "#title.editable", function() { if (visible.imageview()) photos.rename(); else albums.rename(); })
  75. /* Navigation */
  76. .on("click", ".album", function() { lychee.goto("a" + $(this).attr("data-id")) })
  77. .on("click", ".photo", function() {
  78. if (lychee.content.attr("data-id")!="") lychee.goto("a" + lychee.content.attr("data-id") + "p" + $(this).attr("data-id"));
  79. else lychee.goto("a" + $(this).attr("data-album-id") + "p" + $(this).attr("data-id"));
  80. })
  81. /* Modal */
  82. .on(event_name, ".message .close", lychee.closeModal)
  83. /* Add Dialog */
  84. .on(event_name, ".button_add", function() { $("body").append(build.addModal) })
  85. .on(event_name, "#add_album", albums.add)
  86. .on(event_name, "#add_photo", function() { $("#auswahl").html(""); $("#upload_files").click() })
  87. /* Upload */
  88. .on("change", "#upload_files", function() { lychee.closeModal(); lychee.upload(this.files); })
  89. /* Context Menu */
  90. .on("contextmenu", ".photo", contextMenu.photo)
  91. .on("contextmenu", ".album", contextMenu.album)
  92. .on(event_name, ".contextmenu_bg", contextMenu.close)
  93. /* Infobox */
  94. .on(event_name, "#infobox_overlay", function() { photos.hideInfobox() })
  95. /* Controls */
  96. .bind("mouseenter", lychee.showControls)
  97. .bind("mouseleave", lychee.hideControls);
  98. /* Upload */
  99. document.documentElement.ondrop = function (e) {
  100. e.stopPropagation();
  101. e.preventDefault();
  102. lychee.upload(event.dataTransfer.files);
  103. return true;
  104. }
  105. /* Init */
  106. lychee.ready();
  107. });