contextMenu.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. /**
  2. * @name ContextMenu Module
  3. * @description This module is used for the context menu.
  4. * @author Tobias Reich
  5. * @copyright 2014 by Tobias Reich
  6. */
  7. contextMenu = {
  8. fns: null,
  9. show: function(items, mouse_x, mouse_y, orientation) {
  10. if (visible.contextMenu()) contextMenu.close();
  11. $("body")
  12. .css("overflow", "hidden")
  13. .append(build.contextMenu(items));
  14. if ((mouse_x+$(".contextmenu").outerWidth(true))>$("html").width()) orientation = "left";
  15. if ((mouse_y+$(".contextmenu").outerHeight(true))>$("html").height()) mouse_y -= (mouse_y+$(".contextmenu").outerHeight(true)-$("html").height())
  16. if (orientation==="left") mouse_x -= $(".contextmenu").outerWidth(true);
  17. if (!mouse_x||!mouse_y) {
  18. mouse_x = "10px";
  19. mouse_y = "10px";
  20. }
  21. $(".contextmenu").css({
  22. "top": mouse_y,
  23. "left": mouse_x,
  24. "opacity": .98
  25. });
  26. },
  27. add: function(e) {
  28. var mouse_x = e.pageX,
  29. mouse_y = e.pageY,
  30. items;
  31. mouse_y -= $(document).scrollTop();
  32. upload.notify();
  33. contextMenu.fns = [
  34. function() { $("#upload_files").click() },
  35. function() { upload.start.url() },
  36. function() { upload.start.dropbox() },
  37. function() { upload.start.server() },
  38. function() { album.add() }
  39. ];
  40. items = [
  41. ["<a class='icon-picture'></a> Upload Photo", 0],
  42. ["separator", -1],
  43. ["<a class='icon-link'></a> Import from Link", 1],
  44. ["<a class='icon-folder-open'></a> Import from Dropbox", 2],
  45. ["<a class='icon-hdd'></a> Import from Server", 3],
  46. ["separator", -1],
  47. ["<a class='icon-folder-close'></a> New Album", 4]
  48. ];
  49. contextMenu.show(items, mouse_x, mouse_y, "left");
  50. },
  51. settings: function(e) {
  52. var mouse_x = e.pageX,
  53. mouse_y = e.pageY,
  54. items;
  55. mouse_y -= $(document).scrollTop();
  56. contextMenu.fns = [
  57. function() { settings.setLogin() },
  58. function() { settings.setSorting() },
  59. function() { window.open(lychee.website,"_newtab"); },
  60. function() { lychee.logout() }
  61. ];
  62. items = [
  63. ["<a class='icon-user'></a> Change Login", 0],
  64. ["<a class='icon-sort'></a> Change Sorting", 1],
  65. ["<a class='icon-info-sign'></a> About Lychee", 2],
  66. ["separator", -1],
  67. ["<a class='icon-signout'></a> Sign Out", 3]
  68. ];
  69. contextMenu.show(items, mouse_x, mouse_y, "right");
  70. },
  71. album: function(albumID, e) {
  72. var mouse_x = e.pageX,
  73. mouse_y = e.pageY,
  74. items;
  75. if (albumID==="0"||albumID==="f"||albumID==="s") return false;
  76. mouse_y -= $(document).scrollTop();
  77. contextMenu.fns = [
  78. function() { album.setTitle(albumID) },
  79. function() { album.delete(albumID) }
  80. ];
  81. items = [
  82. ["<a class='icon-edit'></a> Rename", 0],
  83. ["<a class='icon-trash'></a> Delete", 1]
  84. ];
  85. contextMenu.show(items, mouse_x, mouse_y, "right");
  86. $(".album[data-id='" + albumID + "']").addClass("active");
  87. },
  88. photo: function(photoID, e) {
  89. var mouse_x = e.pageX,
  90. mouse_y = e.pageY,
  91. items;
  92. mouse_y -= $(document).scrollTop();
  93. contextMenu.fns = [
  94. function() { photo.setStar(photoID) },
  95. function() { photo.setTitle(photoID) },
  96. function() { contextMenu.move(photoID, e, "right") },
  97. function() { photo.delete(photoID) }
  98. ];
  99. items = [
  100. ["<a class='icon-star'></a> Star", 0],
  101. ["separator", -1],
  102. ["<a class='icon-edit'></a> Rename", 1],
  103. ["<a class='icon-folder-open'></a> Move", 2],
  104. ["<a class='icon-trash'></a> Delete", 3]
  105. ];
  106. contextMenu.show(items, mouse_x, mouse_y, "right");
  107. $(".photo[data-id='" + photoID + "']").addClass("active");
  108. },
  109. move: function(photoID, e, orientation) {
  110. var mouse_x = e.pageX,
  111. mouse_y = e.pageY,
  112. items = [];
  113. contextMenu.fns = [];
  114. if (album.getID()!=="0") {
  115. items = [
  116. ["Unsorted", 0, "photo.setAlbum(0, " + photoID + ")"],
  117. ["separator", -1]
  118. ];
  119. }
  120. lychee.api("getAlbums", function(data) {
  121. if (!data.albums) {
  122. items = [["New Album", 0, "album.add()"]];
  123. } else {
  124. $.each(data.content, function(index) {
  125. if (this.id!=album.getID()) items.push([this.title, 0, "photo.setAlbum(" + this.id + ", " + photoID + ")"]);
  126. });
  127. }
  128. contextMenu.close();
  129. $(".photo[data-id='" + photoID + "']").addClass("active");
  130. if (!visible.photo()) contextMenu.show(items, mouse_x, mouse_y, "right");
  131. else contextMenu.show(items, mouse_x, mouse_y, "left");
  132. });
  133. },
  134. sharePhoto: function(photoID, e) {
  135. var mouse_x = e.pageX,
  136. mouse_y = e.pageY,
  137. items;
  138. mouse_y -= $(document).scrollTop();
  139. contextMenu.fns = [
  140. function() { photo.setPublic(photoID) },
  141. function() { photo.share(photoID, 0) },
  142. function() { photo.share(photoID, 1) },
  143. function() { photo.share(photoID, 2) },
  144. function() { photo.share(photoID, 3) },
  145. function() { window.open(photo.getDirectLink(),"_newtab") }
  146. ];
  147. link = photo.getViewLink(photoID);
  148. if (photo.json.public==="2") link = location.href;
  149. items = [
  150. ["<input readonly id='link' value='" + link + "'>", -1],
  151. ["separator", -1],
  152. ["<a class='icon-eye-close'></a> Make Private", 0],
  153. ["separator", -1],
  154. ["<a class='icon-twitter'></a> Twitter", 1],
  155. ["<a class='icon-facebook'></a> Facebook", 2],
  156. ["<a class='icon-envelope'></a> Mail", 3],
  157. ["<a class='icon-hdd'></a> Dropbox", 4],
  158. ["<a class='icon-link'></a> Direct Link", 5]
  159. ];
  160. contextMenu.show(items, mouse_x, mouse_y, "left");
  161. $(".contextmenu input").focus();
  162. },
  163. shareAlbum: function(albumID, e) {
  164. var mouse_x = e.pageX,
  165. mouse_y = e.pageY,
  166. items;
  167. mouse_y -= $(document).scrollTop();
  168. contextMenu.fns = [
  169. function() { album.setPublic(albumID) },
  170. function() { password.set(albumID) },
  171. function() { album.share(0) },
  172. function() { album.share(1) },
  173. function() { album.share(2) },
  174. function() { password.remove(albumID) }
  175. ];
  176. items = [
  177. ["<input readonly id='link' value='" + location.href + "'>", -1],
  178. ["separator", -1],
  179. ["<a class='icon-eye-close'></a> Make Private", 0],
  180. ["<a class='icon-lock'></a> Set Password", 1],
  181. ["separator", -1],
  182. ["<a class='icon-twitter'></a> Twitter", 2],
  183. ["<a class='icon-facebook'></a> Facebook", 3],
  184. ["<a class='icon-envelope'></a> Mail", 4],
  185. ];
  186. if (album.json.password==true) items[3] = ["<a class='icon-unlock'></a> Remove Password", 5];
  187. contextMenu.show(items, mouse_x, mouse_y, "left");
  188. $(".contextmenu input").focus();
  189. },
  190. close: function() {
  191. contextMenu.js = null;
  192. $(".contextmenu_bg, .contextmenu").remove();
  193. $(".photo.active, .album.active").removeClass("active");
  194. $("body").css("overflow", "auto");
  195. }
  196. }