contextMenu.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  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, "_newtab"); },
  69. function() { window.open("plugins/check.php", "_newtab"); },
  70. function() { lychee.logout() }
  71. ];
  72. items = [
  73. ["<a class='icon-user'></a> Change Login", 0],
  74. ["<a class='icon-sort'></a> Change Sorting", 1],
  75. ["<a class='icon-folder-open'></a> Set Dropbox", 2],
  76. ["separator", -1],
  77. ["<a class='icon-info-sign'></a> About Lychee", 3],
  78. ["<a class='icon-dashboard'></a> Diagnostics", 4],
  79. ["separator", -1],
  80. ["<a class='icon-signout'></a> Sign Out", 5]
  81. ];
  82. contextMenu.show(items, mouse_x, mouse_y, "right");
  83. },
  84. album: function(albumID, e) {
  85. var mouse_x = e.pageX,
  86. mouse_y = e.pageY - $(document).scrollTop(),
  87. items;
  88. if (albumID==="0"||albumID==="f"||albumID==="s") return false;
  89. contextMenu.fns = [
  90. function() { album.setTitle([albumID]) },
  91. function() { album.delete([albumID]) }
  92. ];
  93. items = [
  94. ["<a class='icon-edit'></a> Rename", 0],
  95. ["<a class='icon-trash'></a> Delete", 1]
  96. ];
  97. contextMenu.show(items, mouse_x, mouse_y, "right");
  98. $(".album[data-id='" + albumID + "']").addClass("active");
  99. },
  100. albumMulti: function(albumIDs, e) {
  101. var mouse_x = e.pageX,
  102. mouse_y = e.pageY - $(document).scrollTop(),
  103. items;
  104. multiselect.stopResize();
  105. contextMenu.fns = [
  106. function() { album.setTitle(albumIDs) },
  107. function() { album.delete(albumIDs) },
  108. ];
  109. items = [
  110. ["<a class='icon-edit'></a> Rename All", 0],
  111. ["<a class='icon-trash'></a> Delete All", 1]
  112. ];
  113. contextMenu.show(items, mouse_x, mouse_y, "right");
  114. },
  115. photo: function(photoID, e) {
  116. var mouse_x = e.pageX,
  117. mouse_y = e.pageY - $(document).scrollTop(),
  118. items;
  119. contextMenu.fns = [
  120. function() { photo.setStar([photoID]) },
  121. function() { photo.editTags([photoID]) },
  122. function() { photo.setTitle([photoID]) },
  123. function() { contextMenu.move([photoID], e, "right") },
  124. function() { photo.delete([photoID]) }
  125. ];
  126. items = [
  127. ["<a class='icon-star'></a> Star", 0],
  128. ["<a class='icon-tags'></a> Tags", 1],
  129. ["separator", -1],
  130. ["<a class='icon-edit'></a> Rename", 2],
  131. ["<a class='icon-folder-open'></a> Move", 3],
  132. ["<a class='icon-trash'></a> Delete", 4]
  133. ];
  134. contextMenu.show(items, mouse_x, mouse_y, "right");
  135. $(".photo[data-id='" + photoID + "']").addClass("active");
  136. },
  137. photoMulti: function(photoIDs, e) {
  138. var mouse_x = e.pageX,
  139. mouse_y = e.pageY - $(document).scrollTop(),
  140. items;
  141. multiselect.stopResize();
  142. contextMenu.fns = [
  143. function() { photo.setStar(photoIDs) },
  144. function() { photo.editTags(photoIDs) },
  145. function() { photo.setTitle(photoIDs) },
  146. function() { contextMenu.move(photoIDs, e, "right") },
  147. function() { photo.delete(photoIDs) }
  148. ];
  149. items = [
  150. ["<a class='icon-star'></a> Star All", 0],
  151. ["<a class='icon-tags'></a> Tag All", 1],
  152. ["separator", -1],
  153. ["<a class='icon-edit'></a> Rename All", 2],
  154. ["<a class='icon-folder-open'></a> Move All", 3],
  155. ["<a class='icon-trash'></a> Delete All", 4]
  156. ];
  157. contextMenu.show(items, mouse_x, mouse_y, "right");
  158. },
  159. move: function(photoIDs, e, orientation) {
  160. var mouse_x = e.pageX,
  161. mouse_y = e.pageY - $(document).scrollTop(),
  162. items = [];
  163. contextMenu.close(true);
  164. if (album.getID()!=="0") {
  165. items = [
  166. ["Unsorted", 0, "photo.setAlbum([" + photoIDs + "], 0)"],
  167. ["separator", -1]
  168. ];
  169. }
  170. lychee.api("getAlbums", function(data) {
  171. if (data.num===0) {
  172. items = [["New Album", 0, "album.add()"]];
  173. } else {
  174. $.each(data.content, function(index) {
  175. if (this.id!=album.getID()) items.push([this.title, 0, "photo.setAlbum([" + photoIDs + "], " + this.id + ")"]);
  176. });
  177. }
  178. if (!visible.photo()) contextMenu.show(items, mouse_x, mouse_y, "right");
  179. else contextMenu.show(items, mouse_x, mouse_y, "left");
  180. });
  181. },
  182. sharePhoto: function(photoID, e) {
  183. var mouse_x = e.pageX,
  184. mouse_y = e.pageY,
  185. items;
  186. mouse_y -= $(document).scrollTop();
  187. contextMenu.fns = [
  188. function() { photo.setPublic(photoID) },
  189. function() { photo.share(photoID, 0) },
  190. function() { photo.share(photoID, 1) },
  191. function() { photo.share(photoID, 2) },
  192. function() { photo.share(photoID, 3) },
  193. function() { window.open(photo.getDirectLink(),"_newtab") }
  194. ];
  195. link = photo.getViewLink(photoID);
  196. if (photo.json.public==="2") link = location.href;
  197. items = [
  198. ["<input readonly id='link' value='" + link + "'>", -1],
  199. ["separator", -1],
  200. ["<a class='icon-eye-close'></a> Make Private", 0],
  201. ["separator", -1],
  202. ["<a class='icon-twitter'></a> Twitter", 1],
  203. ["<a class='icon-facebook'></a> Facebook", 2],
  204. ["<a class='icon-envelope'></a> Mail", 3],
  205. ["<a class='icon-hdd'></a> Dropbox", 4],
  206. ["<a class='icon-link'></a> Direct Link", 5]
  207. ];
  208. contextMenu.show(items, mouse_x, mouse_y, "left");
  209. $(".contextmenu input").focus().select();
  210. },
  211. shareAlbum: function(albumID, e) {
  212. var mouse_x = e.pageX,
  213. mouse_y = e.pageY,
  214. items;
  215. mouse_y -= $(document).scrollTop();
  216. contextMenu.fns = [
  217. function() { album.setPublic(albumID) },
  218. function() { password.set(albumID) },
  219. function() { album.share(0) },
  220. function() { album.share(1) },
  221. function() { album.share(2) },
  222. function() { password.remove(albumID) }
  223. ];
  224. items = [
  225. ["<input readonly id='link' value='" + location.href + "'>", -1],
  226. ["separator", -1],
  227. ["<a class='icon-eye-close'></a> Make Private", 0],
  228. ["<a class='icon-lock'></a> Set Password", 1],
  229. ["separator", -1],
  230. ["<a class='icon-twitter'></a> Twitter", 2],
  231. ["<a class='icon-facebook'></a> Facebook", 3],
  232. ["<a class='icon-envelope'></a> Mail", 4],
  233. ];
  234. if (album.json.password==true) items[3] = ["<a class='icon-unlock'></a> Remove Password", 5];
  235. contextMenu.show(items, mouse_x, mouse_y, "left");
  236. $(".contextmenu input").focus().select();
  237. },
  238. close: function(leaveSelection) {
  239. if (!visible.contextMenu()) return false;
  240. contextMenu.fns = [];
  241. $(".contextmenu_bg, .contextmenu").remove();
  242. $("body").css("overflow", "auto");
  243. if (leaveSelection!==true) {
  244. $(".photo.active, .album.active").removeClass("active");
  245. if (visible.multiselect()) multiselect.close();
  246. }
  247. }
  248. };