main.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /**
  2. * @name main.js
  3. * @author Philipp Maurer
  4. * @author Tobias Reich
  5. * @copyright 2013 by Philipp Maurer, Tobias Reich
  6. */
  7. $(document).ready(function(){
  8. /* Init */
  9. lychee.init();
  10. /* Event Name */
  11. var event_name = (mobileBrowser()) ? "touchend" : "click";
  12. /* Notifications */
  13. if (window.webkitNotifications) window.webkitNotifications.requestPermission();
  14. /* Tooltips */
  15. if (!mobileBrowser()) $(".tools").tipsy({gravity: 'n'});
  16. /* Header */
  17. $("#button_share").on(event_name, function(e) {
  18. if (photo.json.public==1||photo.json.public==2) contextMenu.sharePhoto(photo.getID(), e);
  19. else photo.setPublic(photo.getID(), e);
  20. });
  21. $("#button_share_album").on(event_name, function(e) {
  22. if (album.json.public==1) contextMenu.shareAlbum(album.getID(), e);
  23. else modal.show("Share Album", "All photos inside this album will be public and visible for everyone. Existing public photos will have the same sharing permission as this album. Are your sure you want to share this album? <input class='password' type='password' placeholder='password (optional)' value=''>", [["Share Album", function() { album.setPublic(album.getID(), e) }], ["Cancel", function() {}]]);
  24. });
  25. $("#button_signout").on(event_name, lychee.logout);
  26. $("#button_download").on(event_name, function() { window.open(photo.getDirectLink(),"_newtab") });
  27. $("#button_trash_album").on(event_name, function() { album.delete(album.getID()) });
  28. $("#button_move").on(event_name, function(e) { contextMenu.move(photo.getID(), e) });
  29. $("#button_trash").on(event_name, function() { photo.delete() });
  30. $("#button_edit_album").on(event_name, function() { album.setTitle() });
  31. $("#button_edit").on(event_name, function() { photo.setTitle(photo.getID()) });
  32. $("#button_info").on(event_name, function() { view.photo.showInfobox() });
  33. $("#button_archive").on(event_name, function() { album.getArchive(album.getID()) });
  34. $("#button_star").on(event_name, function() { photo.setStar(photo.getID()) });
  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" + album.getID()) });
  40. /* Image View */
  41. lychee.imageview
  42. .on(event_name, "a#previous", function() {
  43. if (photo.json&&photo.json.previousPhoto) lychee.goto("a" + album.getID() + "p" + photo.json.previousPhoto)
  44. })
  45. .on(event_name, "a#next", function() {
  46. if (photo.json&&photo.json.nextPhoto) lychee.goto("a" + album.getID() + "p" + photo.json.nextPhoto)
  47. });
  48. /* Infobox */
  49. $("#infobox")
  50. .on(event_name, ".header a", function() { view.photo.hideInfobox() })
  51. .on(event_name, "#edit_title", function() { photo.setTitle(photo.getID()) })
  52. .on(event_name, "#edit_description", function() { photo.setDescription(photo.getID()) });
  53. /* Keyboard */
  54. Mousetrap
  55. .bind('n', function(e) { if (!visible.message()) $("body").append(build.addModal) })
  56. .bind('u', function(e) { $("#auswahl").html(""); $("#upload_files").click() })
  57. .bind('s', function(e) { if (visible.photo()) $("#button_star").click() })
  58. .bind('f', function(e) { if (visible.photo()) $("#button_download").click() })
  59. .bind('command+backspace', function(e) { if (visible.photo()&&!visible.message()) photo.delete() })
  60. .bind('left', function(e) { if (visible.photo()) $("#imageview a#previous").click() })
  61. .bind('right', function(e) { if (visible.photo()) $("#imageview a#next").click() })
  62. .bind('i', function(e) {
  63. if (visible.infobox()) view.photo.hideInfobox();
  64. else if (visible.photo()) view.photo.showInfobox();
  65. });
  66. Mousetrap.bindGlobal('enter', function(e) {
  67. if ($(".message .button.active").length) $(".message .button.active").addClass("pressed").click()
  68. });
  69. Mousetrap.bindGlobal(['esc', 'command+up'], function(e) {
  70. e.preventDefault();
  71. if (visible.message()) modal.close();
  72. else if (visible.contextMenu()) contextMenu.close();
  73. else if (visible.infobox()) view.photo.hideInfobox();
  74. else if (visible.photo()) lychee.goto("a" + album.getID());
  75. else if (visible.album()) lychee.goto("");
  76. else if (visible.albums()&&$("#search").val().length!=0) search.reset();
  77. });
  78. /* Document */
  79. $(document)
  80. /* Login */
  81. .on(event_name, "#button_signin", function() { lychee.loginDialog() })
  82. .on("keyup", "#password", function() { if ($(this).val().length>0) $(this).removeClass("error") })
  83. /* Header */
  84. .on(event_name, "#title.editable", function() {
  85. if (visible.photo()) photo.setTitle(photo.getID());
  86. else album.setTitle();
  87. })
  88. /* Navigation */
  89. .on("click", ".album", function() { lychee.goto("a" + $(this).attr("data-id")) })
  90. .on("click", ".photo", function() { lychee.goto("a" + album.getID() + "p" + $(this).attr("data-id")) })
  91. /* Modal */
  92. .on(event_name, ".message .close", modal.close)
  93. .on(event_name, ".message .button:first", function() { modal.fns[0](); modal.close(); })
  94. .on(event_name, ".message .button:last", function() { modal.fns[1](); modal.close(); })
  95. /* Add Dialog */
  96. .on(event_name, ".button_add", function() { $("body").append(build.addModal) })
  97. .on(event_name, "#add_album", album.add)
  98. .on(event_name, "#add_link", function() { photo.add.url() })
  99. .on(event_name, "#add_photo", function() { $("#auswahl").html(""); $("#upload_files").click() })
  100. /* Upload */
  101. .on("change", "#upload_files", function() { modal.close(); photo.add.files(this.files); })
  102. /* Context Menu */
  103. .on("contextmenu", ".photo", contextMenu.photo)
  104. .on("contextmenu", ".album", contextMenu.album)
  105. .on(event_name, ".contextmenu_bg", contextMenu.close)
  106. /* Infobox */
  107. .on(event_name, "#infobox_overlay", function() { view.photo.hideInfobox() })
  108. /* Controls */
  109. .bind("mouseenter", view.header.show)
  110. .bind("mouseleave", view.header.hide)
  111. /* Upload */
  112. .on("dragover", function(e) { e.preventDefault(); }, false)
  113. .on("drop", function(e) {
  114. e.stopPropagation();
  115. e.preventDefault();
  116. photo.add.files(e.originalEvent.dataTransfer.files);
  117. return true;
  118. });
  119. /* Run */
  120. lychee.run();
  121. });