contextMenu.js 7.8 KB

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