contextMenu.js 7.0 KB

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