init.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. /* Tooltips */
  12. if (!mobileBrowser()) $(".tools").tipsy({gravity: 'n', fade: false, delayIn: 0, opacity: 1});
  13. /* Header */
  14. $("#hostedwith").on(event_name, function() { window.open(lychee.website,"_newtab") });
  15. $("#button_signin").on(event_name, lychee.loginDialog);
  16. $("#button_settings").on(event_name, contextMenu.settings);
  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='text' type='password' placeholder='password (optional)' value=''>", [["Share Album", function() { album.setPublic(album.getID(), e) }], ["Cancel", function() {}]]);
  24. });
  25. $("#button_download").on(event_name, function() { window.open(photo.getDirectLink(),"_newtab") });
  26. $("#button_trash_album").on(event_name, function() { album.delete(album.getID()) });
  27. $("#button_move").on(event_name, function(e) { contextMenu.move(photo.getID(), e) });
  28. $("#button_trash").on(event_name, function() { photo.delete(photo.getID()) });
  29. $("#button_info_album").on(event_name, function() { view.infobox.show() });
  30. $("#button_info").on(event_name, function() { view.infobox.show() });
  31. $("#button_archive").on(event_name, function() { album.getArchive(album.getID()) });
  32. $("#button_star").on(event_name, function() { photo.setStar(photo.getID()) });
  33. /* Search */
  34. $("#search").on("keyup click", function() { search.find($(this).val()) });
  35. /* Back Buttons */
  36. $("#button_back_home").on(event_name, function() { lychee.goto("") });
  37. $("#button_back").on(event_name, function() { lychee.goto(album.getID()) });
  38. /* Image View */
  39. lychee.imageview
  40. .on(event_name, ".arrow_wrapper.previous", function() {
  41. if (album.json&&album.json.content[photo.getID()]&&album.json.content[photo.getID()].previousPhoto!=="") lychee.goto(album.getID() + "/" + album.json.content[photo.getID()].previousPhoto)
  42. })
  43. .on(event_name, ".arrow_wrapper.next", function() {
  44. if (album.json&&album.json.content[photo.getID()]&&album.json.content[photo.getID()].nextPhoto!=="") lychee.goto(album.getID() + "/" + album.json.content[photo.getID()].nextPhoto)
  45. });
  46. /* Infobox */
  47. $("#infobox")
  48. .on(event_name, ".header a", function() { view.infobox.hide() })
  49. .on(event_name, "#edit_title_album", function() { album.setTitle(album.getID()) })
  50. .on(event_name, "#edit_description_album", function() { album.setDescription(album.getID()) })
  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('u', function() { $("#upload_files").click() })
  56. .bind('s', function() { if (visible.photo()) $("#button_star").click() })
  57. .bind('f', function() { if (visible.photo()) $("#button_download").click() })
  58. .bind('command+backspace', function() { if (visible.photo()&&!visible.message()) photo.delete(photo.getID()) })
  59. .bind('left', function() { if (visible.photo()) $("#imageview a#previous").click() })
  60. .bind('right', function() { if (visible.photo()) $("#imageview a#next").click() })
  61. .bind('i', function() {
  62. if (visible.infobox()) view.infobox.hide();
  63. else if (!visible.albums()) view.infobox.show();
  64. });
  65. Mousetrap.bindGlobal('enter', function() {
  66. if ($(".message .button.active").length) $(".message .button.active").addClass("pressed").click()
  67. });
  68. Mousetrap.bindGlobal(['esc', 'command+up'], function(e) {
  69. e.preventDefault();
  70. if (visible.message()&&$(".message .close").length>0) modal.close();
  71. else if (visible.contextMenu()) contextMenu.close();
  72. else if (visible.infobox()) view.infobox.hide();
  73. else if (visible.photo()) lychee.goto(album.getID());
  74. else if (visible.album()) lychee.goto("");
  75. else if (visible.albums()&&$("#search").val().length!==0) search.reset();
  76. });
  77. /* Document */
  78. $(document)
  79. /* Login */
  80. .on("keyup", "#password", function() { if ($(this).val().length>0) $(this).removeClass("error") })
  81. /* Header */
  82. .on(event_name, "#title.editable", function() {
  83. if (visible.photo()) photo.setTitle(photo.getID());
  84. else album.setTitle(album.getID());
  85. })
  86. /* Navigation */
  87. .on("click", ".album", function() { lychee.goto($(this).attr("data-id")) })
  88. .on("click", ".photo", function() { lychee.goto(album.getID() + "/" + $(this).attr("data-id")) })
  89. /* Modal */
  90. .on(event_name, ".message .close", modal.close)
  91. .on(event_name, ".message .button:first", function() { if (modal.fns!=null) modal.fns[0](); if (!visible.signin()) modal.close() })
  92. .on(event_name, ".message .button:last", function() { if (modal.fns!=null) modal.fns[1](); if (!visible.signin()) modal.close() })
  93. /* Add Dialog */
  94. .on(event_name, ".button_add", function(e) { contextMenu.add(e) })
  95. /* Upload */
  96. .on("change", "#upload_files", function() { modal.close(); upload.start.local(this.files) })
  97. /* Context Menu */
  98. .on("contextmenu", ".photo", function(e) { contextMenu.photo(photo.getID(), e) })
  99. .on("contextmenu", ".album", function(e) { contextMenu.album(album.getID(), e) })
  100. .on(event_name, ".contextmenu_bg", contextMenu.close)
  101. /* Infobox */
  102. .on(event_name, "#infobox_overlay", view.infobox.hide)
  103. /* Upload */
  104. .on("dragover", function(e) { e.preventDefault(); }, false)
  105. .on("drop", function(e) {
  106. e.stopPropagation();
  107. e.preventDefault();
  108. if (e.originalEvent.dataTransfer.files.length>0) upload.start.local(e.originalEvent.dataTransfer.files);
  109. else if (e.originalEvent.dataTransfer.getData('Text').length>3) upload.start.url(e.originalEvent.dataTransfer.getData('Text'));
  110. return true;
  111. });
  112. /* Init */
  113. lychee.init();
  114. });