init.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /**
  2. * @name Init Module
  3. * @author Tobias Reich
  4. * @copyright 2014 by Tobias Reich
  5. */
  6. $(document).ready(function(){
  7. /* Event Name */
  8. var event_name = (mobileBrowser()) ? "touchend" : "click";
  9. /* Disable ContextMenu */
  10. $(document).bind("contextmenu", function(e) { e.preventDefault() });
  11. /* Tooltips */
  12. if (!mobileBrowser()) $(".tools").tipsy({gravity: 'n', fade: false, delayIn: 0, opacity: 1});
  13. /* Multiselect */
  14. $("#content").on("mousedown", multiselect.show);
  15. $(document).on("mouseup", multiselect.getSelection);
  16. /* Header */
  17. $("#hostedwith").on(event_name, function() { window.open(lychee.website,"_newtab") });
  18. $("#button_signin").on(event_name, lychee.loginDialog);
  19. $("#button_settings").on("click", contextMenu.settings);
  20. $("#button_share").on(event_name, function(e) {
  21. if (photo.json.public==1||photo.json.public==2) contextMenu.sharePhoto(photo.getID(), e);
  22. else photo.setPublic(photo.getID(), e);
  23. });
  24. $("#button_share_album").on(event_name, function(e) {
  25. if (album.json.public==1) contextMenu.shareAlbum(album.getID(), e);
  26. else album.setPublic(album.getID(), e);
  27. });
  28. $("#button_more").on(event_name, function(e) { contextMenu.photoMore(photo.getID(), e) });
  29. $("#button_trash_album").on(event_name, function() { album.delete([album.getID()]) });
  30. $("#button_move").on(event_name, function(e) { contextMenu.move([photo.getID()], e) });
  31. $("#button_trash").on(event_name, function() { photo.delete([photo.getID()]) });
  32. $("#button_info_album").on(event_name, function() { view.infobox.show() });
  33. $("#button_info").on(event_name, function() { view.infobox.show() });
  34. $("#button_archive").on(event_name, function() { album.getArchive(album.getID()) });
  35. $("#button_star").on(event_name, function() { photo.setStar([photo.getID()]) });
  36. /* Search */
  37. $("#search").on("keyup click", function() { search.find($(this).val()) });
  38. /* Clear Search */
  39. $("#clearSearch").on(event_name, function () {
  40. $("#search").focus();
  41. search.reset();
  42. });
  43. /* Back Buttons */
  44. $("#button_back_home").on(event_name, function() { lychee.goto("") });
  45. $("#button_back").on(event_name, function() { lychee.goto(album.getID()) });
  46. /* Image View */
  47. lychee.imageview
  48. .on(event_name, ".arrow_wrapper.previous", photo.previous)
  49. .on(event_name, ".arrow_wrapper.next", photo.next);
  50. /* Infobox */
  51. $("#infobox")
  52. .on(event_name, ".header a", function() { view.infobox.hide() })
  53. .on(event_name, "#edit_title_album", function() { album.setTitle([album.getID()]) })
  54. .on(event_name, "#edit_description_album", function() { album.setDescription(album.getID()) })
  55. .on(event_name, "#edit_title", function() { photo.setTitle([photo.getID()]) })
  56. .on(event_name, "#edit_description", function() { photo.setDescription(photo.getID()) })
  57. .on(event_name, "#edit_tags", function() { photo.editTags([photo.getID()]) })
  58. .on(event_name, "#tags .tag span", function() { photo.deleteTag(photo.getID(), $(this).data('index')) });
  59. /* Keyboard */
  60. Mousetrap
  61. .bind('left', function() { if (visible.photo()) $("#imageview a#previous").click() })
  62. .bind('right', function() { if (visible.photo()) $("#imageview a#next").click() })
  63. .bind(['u', 'ctrl+u'], function() { $("#upload_files").click() })
  64. .bind(['s', 'ctrl+s', 'f', 'ctrl+f'], function(e) {
  65. if (visible.photo()) {
  66. $("#button_star").click();
  67. } else if (visible.albums()) {
  68. e.preventDefault();
  69. $("#search").focus();
  70. }
  71. })
  72. .bind(['r', 'ctrl+r'], function(e) {
  73. e.preventDefault();
  74. if (visible.album()) album.setTitle(album.getID());
  75. else if (visible.photo()) photo.setTitle([photo.getID()]);
  76. })
  77. .bind(['d', 'ctrl+d'], function(e) {
  78. e.preventDefault();
  79. if (visible.photo()) photo.setDescription(photo.getID());
  80. else if (visible.album()) album.setDescription(album.getID());
  81. })
  82. .bind(['t', 'ctrl+t'], function(e) {
  83. if (visible.photo()) {
  84. e.preventDefault();
  85. photo.editTags([photo.getID()]);
  86. }
  87. })
  88. .bind(['i', 'ctrl+i'], function() {
  89. if (visible.infobox()) view.infobox.hide();
  90. else if (!visible.albums()) view.infobox.show();
  91. })
  92. .bind(['command+backspace', 'ctrl+backspace'], function() {
  93. if (visible.photo()&&!visible.message()) photo.delete([photo.getID()]);
  94. else if (visible.album()&&!visible.message()) album.delete([album.getID()]);
  95. });
  96. Mousetrap.bindGlobal('enter', function() {
  97. if ($(".message .button.active").length) $(".message .button.active").addClass("pressed").click()
  98. });
  99. Mousetrap.bindGlobal(['esc', 'command+up'], function(e) {
  100. e.preventDefault();
  101. if (visible.message()&&$(".message .close").length>0) modal.close();
  102. else if (visible.contextMenu()) contextMenu.close();
  103. else if (visible.infobox()) view.infobox.hide();
  104. else if (visible.photo()) lychee.goto(album.getID());
  105. else if (visible.album()) lychee.goto("");
  106. else if (visible.albums()&&$("#search").val().length!==0) search.reset();
  107. });
  108. if (mobileBrowser()) {
  109. $(document)
  110. /* Fullscreen on mobile */
  111. .on('touchend', '#image', function(e) {
  112. if (swipe.obj===null||(swipe.offset>=-5&&swipe.offset<=5)) {
  113. if (visible.controls()) view.header.hide(e, 0);
  114. else view.header.show();
  115. }
  116. })
  117. /* Swipe on mobile */
  118. .swipe().on('swipeStart', function() { if (visible.photo()) swipe.start($("#image")) })
  119. .swipe().on('swipeMove', function(e) { if (visible.photo()) swipe.move(e.swipe) })
  120. .swipe().on('swipeEnd', function(e) { if (visible.photo()) swipe.stop(e.swipe, photo.previous, photo.next) });
  121. }
  122. /* Document */
  123. $(document)
  124. /* Login */
  125. .on("keyup", "#password", function() { if ($(this).val().length>0) $(this).removeClass("error") })
  126. /* Header */
  127. .on(event_name, "#title.editable", function() {
  128. if (visible.photo()) photo.setTitle([photo.getID()]);
  129. else album.setTitle([album.getID()]);
  130. })
  131. /* Navigation */
  132. .on("click", ".album", function() { lychee.goto($(this).attr("data-id")) })
  133. .on("click", ".photo", function() { lychee.goto(album.getID() + "/" + $(this).attr("data-id")) })
  134. /* Modal */
  135. .on(event_name, ".message .close", modal.close)
  136. .on(event_name, ".message .button:first", function() { if (modal.fns!==null) modal.fns[0](); if (!visible.signin()) modal.close() })
  137. .on(event_name, ".message .button:last", function() { if (modal.fns!==null) modal.fns[1](); if (!visible.signin()) modal.close() })
  138. /* Add Dialog */
  139. .on(event_name, ".button_add", function(e) { contextMenu.add(e) })
  140. /* Upload */
  141. .on("change", "#upload_files", function() { modal.close(); upload.start.local(this.files) })
  142. /* Context Menu */
  143. .on("contextmenu", ".photo", function(e) { contextMenu.photo(photo.getID(), e) })
  144. .on("contextmenu", ".album", function(e) { contextMenu.album(album.getID(), e) })
  145. .on(event_name, ".contextmenu_bg", contextMenu.close)
  146. .on("contextmenu", ".contextmenu_bg", contextMenu.close)
  147. /* Infobox */
  148. .on(event_name, "#infobox_overlay", view.infobox.hide)
  149. /* Upload */
  150. .on("dragover", function(e) { e.preventDefault(); }, false)
  151. .on("drop", function(e) {
  152. e.stopPropagation();
  153. e.preventDefault();
  154. if (e.originalEvent.dataTransfer.files.length>0) upload.start.local(e.originalEvent.dataTransfer.files);
  155. else if (e.originalEvent.dataTransfer.getData('Text').length>3) upload.start.url(e.originalEvent.dataTransfer.getData('Text'));
  156. return true;
  157. });
  158. /* Init */
  159. lychee.init();
  160. });