main.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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, lychee.logout);
  15. $("#button_download").on(event_name, function() {
  16. link = $("#image_view #image").css("background-image").replace(/"/g,"").replace(/url\(|\)$/ig, "");
  17. window.open(link,"_newtab");
  18. });
  19. $("#button_share").on(event_name, function(e) {
  20. if ($("#button_share a.active").length) contextMenu.share(lychee.image_view.attr("data-id"), e.pageX, e.pageY);
  21. else photos.setPublic(e);
  22. });
  23. $("#button_share_album").on(event_name, function(e) {
  24. if ($("#button_share_album a.active").length) contextMenu.share_album(lychee.content.attr("data-id"), e.pageX, e.pageY);
  25. else albums.setPublic(e);
  26. });
  27. $("#button_trash_album").on(event_name, function() { albums.deleteDialog(lychee.content.attr("data-id")) });
  28. $("#button_move").on(event_name, function(e) { contextMenu.move(lychee.image_view.attr("data-id"), e.pageX, e.pageY) });
  29. $("#button_trash").on(event_name, function() { photos.deleteDialog() });
  30. $("#button_edit_album").on(event_name, function() { albums.setTitle() });
  31. $("#button_edit").on(event_name, function() { photos.setTitle() });
  32. $("#button_info").on(event_name, function() { photos.showInfobox() });
  33. $("#button_archive").on(event_name, function() { albums.getArchive() });
  34. $("#button_star").on(event_name, function() { photos.setStar() });
  35. $(".copylink").on(event_name, function() { $(this).select() });
  36. /* Search */
  37. $("#search").on("keyup click", function() { search.find($(this).val()) });
  38. /* Back Buttons */
  39. $("#button_back_home").on(event_name, function() { lychee.goto("") });
  40. $("#button_back").on(event_name, function() { lychee.goto("a" + lychee.content.attr("data-id")) });
  41. /* Image View */
  42. $("#image_view")
  43. .on(event_name, "a#previous", photos.previous)
  44. .on(event_name, "a#next", photos.next);
  45. /* Infobox */
  46. $("#infobox")
  47. .on(event_name, ".header a", function() { photos.hideInfobox() })
  48. .on(event_name, "#edit_title", function() { photos.setTitle() })
  49. .on(event_name, "#edit_description", function() { photos.setDescription() });
  50. /* Keyboard */
  51. Mousetrap
  52. .bind('n', function(e) { $("body").append(build.addModal) })
  53. .bind('u', function(e) { $("#auswahl").html(""); $("#upload_files").click() })
  54. .bind('s', function(e) { if (visible.imageview()) $("#button_star").click() })
  55. .bind('f', function(e) { if (visible.imageview()) $("#button_download").click() })
  56. .bind('i', function(e) { if (visible.imageview()) photos.showInfobox() })
  57. .bind('backspace', function(e) { if (visible.imageview()) photos.deleteDialog() })
  58. .bind('left', function(e) { if (visible.imageview()) photos.previous() })
  59. .bind('right', function(e) { if (visible.imageview()) photos.next() });
  60. Mousetrap.bindGlobal('enter', function(e) {
  61. if ($(".message .button.active").length) $(".message .button.active").addClass("pressed").click()
  62. });
  63. Mousetrap.bindGlobal('esc', function(e) {
  64. e.preventDefault();
  65. if ($(".message").length) lychee.closeModal();
  66. else if (visible.infobox()) photos.hideInfobox();
  67. else if (visible.imageview()) lychee.goto("a" + lychee.content.attr("data-id"));
  68. else if (visible.albums()&&$("#search").val().length!=0) search.reset();
  69. });
  70. /* Document */
  71. $(document)
  72. /* Login */
  73. .on(event_name, "#button_signin", function() { lychee.showLogin() })
  74. .on("keyup", "#password", function() { if ($(this).val().length>0) $(this).removeClass("error") })
  75. /* Toolbar */
  76. .on(event_name, "#title.editable", function() { if (visible.imageview()) photos.setTitle(); else albums.setTitle(); })
  77. /* Navigation */
  78. .on("click", ".album", function() { lychee.goto("a" + $(this).attr("data-id")) })
  79. .on("click", ".photo", function() {
  80. if (lychee.content.attr("data-id")!="") lychee.goto("a" + lychee.content.attr("data-id") + "p" + $(this).attr("data-id"));
  81. else lychee.goto("a" + $(this).attr("data-album-id") + "p" + $(this).attr("data-id"));
  82. })
  83. /* Modal */
  84. .on(event_name, ".message .close", lychee.closeModal)
  85. /* Add Dialog */
  86. .on(event_name, ".button_add", function() { $("body").append(build.addModal) })
  87. .on(event_name, "#add_album", albums.add)
  88. .on(event_name, "#add_link", lychee.importUrl)
  89. .on(event_name, "#add_photo", function() { $("#auswahl").html(""); $("#upload_files").click() })
  90. /* Upload */
  91. .on("change", "#upload_files", function() { lychee.closeModal(); lychee.upload(this.files); })
  92. /* Context Menu */
  93. .on("contextmenu", ".photo", contextMenu.photo)
  94. .on("contextmenu", ".album", contextMenu.album)
  95. .on(event_name, ".contextmenu_bg", contextMenu.close)
  96. /* Infobox */
  97. .on(event_name, "#infobox_overlay", function() { photos.hideInfobox() })
  98. /* Controls */
  99. .bind("mouseenter", lychee.showControls)
  100. .bind("mouseleave", lychee.hideControls)
  101. /* Upload */
  102. .on("dragover", function(e) { e.preventDefault(); }, false)
  103. .on("drop", function(e) {
  104. e.stopPropagation();
  105. e.preventDefault();
  106. lychee.upload(e.originalEvent.dataTransfer.files);
  107. return true;
  108. });
  109. /* Init */
  110. lychee.ready();
  111. });