init.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. /* Notifications */
  10. if (window.webkitNotifications) window.webkitNotifications.requestPermission();
  11. /* Disable ContextMenu */
  12. $(document).bind("contextmenu", function(e) { e.preventDefault() });
  13. /* Tooltips */
  14. if (!mobileBrowser()) $(".tools").tipsy({gravity: 'n', fade: false, delayIn: 0, opacity: 1});
  15. /* Header */
  16. $("#hostedwith").on(event_name, function() { window.open(lychee.website,"_newtab") });
  17. $("#button_signin").on(event_name, lychee.loginDialog);
  18. $("#button_settings").on(event_name, contextMenu.settings);
  19. $("#button_share").on(event_name, function(e) {
  20. if (photo.json.public==1||photo.json.public==2) contextMenu.sharePhoto(photo.getID(), e);
  21. else photo.setPublic(photo.getID(), e);
  22. });
  23. $("#button_share_album").on(event_name, function(e) {
  24. if (album.json.public==1) contextMenu.shareAlbum(album.getID(), e);
  25. 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='text' type='password' placeholder='password (optional)' value=''>", [["Share Album", function() { album.setPublic(album.getID(), e) }], ["Cancel", function() {}]]);
  26. });
  27. $("#button_download").on(event_name, function() { photo.getArchive(photo.getID()) });
  28. $("#button_trash_album").on(event_name, function() { album.delete(album.getID()) });
  29. $("#button_move").on(event_name, function(e) { contextMenu.move(photo.getID(), e) });
  30. $("#button_trash").on(event_name, function() { photo.delete(photo.getID()) });
  31. $("#button_info_album").on(event_name, function() { view.infobox.show() });
  32. $("#button_info").on(event_name, function() { view.infobox.show() });
  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(album.getID()) });
  40. /* Image View */
  41. lychee.imageview
  42. .on(event_name, ".arrow_wrapper.previous", function() {
  43. if (album.json&&album.json.content[photo.getID()]&&album.json.content[photo.getID()].previousPhoto!=="") lychee.goto(album.getID() + "/" + album.json.content[photo.getID()].previousPhoto)
  44. })
  45. .on(event_name, ".arrow_wrapper.next", function() {
  46. if (album.json&&album.json.content[photo.getID()]&&album.json.content[photo.getID()].nextPhoto!=="") lychee.goto(album.getID() + "/" + album.json.content[photo.getID()].nextPhoto)
  47. });
  48. /* Infobox */
  49. $("#infobox")
  50. .on(event_name, ".header a", function() { view.infobox.hide() })
  51. .on(event_name, "#edit_title_album", function() { album.setTitle(album.getID()) })
  52. .on(event_name, "#edit_description_album", function() { album.setDescription(album.getID()) })
  53. .on(event_name, "#edit_title", function() { photo.setTitle(photo.getID()) })
  54. .on(event_name, "#edit_description", function() { photo.setDescription(photo.getID()) });
  55. /* Keyboard */
  56. Mousetrap
  57. .bind('u', function() { $("#upload_files").click() })
  58. .bind('s', function() { if (visible.photo()) $("#button_star").click() })
  59. .bind('command+backspace', function() { if (visible.photo()&&!visible.message()) photo.delete(photo.getID()) })
  60. .bind('left', function() { if (visible.photo()) $("#imageview a#previous").click() })
  61. .bind('right', function() { if (visible.photo()) $("#imageview a#next").click() })
  62. .bind('i', function() {
  63. if (visible.infobox()) view.infobox.hide();
  64. else if (!visible.albums()) view.infobox.show();
  65. });
  66. Mousetrap.bindGlobal('enter', function() {
  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()&&$(".message .close").length>0) modal.close();
  72. else if (visible.contextMenu()) contextMenu.close();
  73. else if (visible.infobox()) view.infobox.hide();
  74. else if (visible.photo()) lychee.goto(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("keyup", "#password", function() { if ($(this).val().length>0) $(this).removeClass("error") })
  82. /* Header */
  83. .on(event_name, "#title.editable", function() {
  84. if (visible.photo()) photo.setTitle(photo.getID());
  85. else album.setTitle(album.getID());
  86. })
  87. /* Clear Search */
  88. .on(event_name, "#clearSearch", function (e) {
  89. e.preventDefault();
  90. $("#search").val("");
  91. $("#search").focus();
  92. })
  93. /* Navigation */
  94. .on("click", ".album", function() { lychee.goto($(this).attr("data-id")) })
  95. .on("click", ".photo", function() { lychee.goto(album.getID() + "/" + $(this).attr("data-id")) })
  96. /* Modal */
  97. .on(event_name, ".message .close", modal.close)
  98. .on(event_name, ".message .button:first", function() { if (modal.fns!=null) modal.fns[0](); if (!visible.signin()) modal.close() })
  99. .on(event_name, ".message .button:last", function() { if (modal.fns!=null) modal.fns[1](); if (!visible.signin()) modal.close() })
  100. /* Add Dialog */
  101. .on(event_name, ".button_add", function(e) { contextMenu.add(e) })
  102. /* Upload */
  103. .on("change", "#upload_files", function() { modal.close(); upload.start.local(this.files) })
  104. /* Context Menu */
  105. .on("contextmenu", ".photo", function(e) { contextMenu.photo(photo.getID(), e) })
  106. .on("contextmenu", ".album", function(e) { contextMenu.album(album.getID(), e) })
  107. .on(event_name, ".contextmenu_bg", contextMenu.close)
  108. .on("contextmenu", ".contextmenu_bg", contextMenu.close)
  109. /* Infobox */
  110. .on(event_name, "#infobox_overlay", view.infobox.hide)
  111. /* Upload */
  112. .on("dragover", function(e) { e.preventDefault(); }, false)
  113. .on("drop", function(e) {
  114. e.stopPropagation();
  115. e.preventDefault();
  116. if (e.originalEvent.dataTransfer.files.length>0) upload.start.local(e.originalEvent.dataTransfer.files);
  117. else if (e.originalEvent.dataTransfer.getData('Text').length>3) upload.start.url(e.originalEvent.dataTransfer.getData('Text'));
  118. return true;
  119. });
  120. /* Init */
  121. lychee.init();
  122. });