contextMenu.js 8.5 KB

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