contextMenu.js 5.8 KB

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