desktop.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. function initDesktop() {
  2. $(".modal").hide();
  3. g_DesktopDB.forEach(function (desktopDBItem) {
  4. /* Clone the main figure */
  5. let $desktopFigureClone = populateClone($("figure.cloneable").clone(), desktopDBItem);
  6. /* Insert the clone */
  7. if (desktopDBItem.id === "trash") {
  8. $desktopFigureClone.insertAfter("#trash-spacer");
  9. } else {
  10. if (desktopDBItem.position) {
  11. $desktopFigureClone.appendTo(".desktop .desktop-" + desktopDBItem.position);
  12. } else {
  13. $desktopFigureClone.insertBefore("#trash-spacer");
  14. }
  15. }
  16. });
  17. /* Remove the original figure */
  18. $("figure.cloneable").remove();
  19. initFigures($(".desktop"));
  20. }
  21. function populateClone($clone, desktopDBItem) {
  22. let icon = desktopDBItem.icon ? desktopDBItem.icon : desktopDBItem.kind;
  23. /* Update the cloned figure */
  24. $clone.removeClass("cloneable");
  25. $clone.addClass(desktopDBItem.kind);
  26. $clone.attr("data-id", desktopDBItem.id);
  27. $clone.attr("data-action", desktopDBItem.action);
  28. $clone.find(".label").html(desktopDBItem.name);
  29. $clone.attr("data-icon", icon);
  30. if (desktopDBItem.alias) {
  31. $clone.find(".label").addClass("alias");
  32. }
  33. if (desktopDBItem.kind === "link")
  34. $clone.find("a").attr("href", desktopDBItem.url);
  35. return $clone;
  36. }
  37. function initFigures($parent) {
  38. /* Initialize icons */
  39. $parent.find("figure").each(function () {
  40. let $this = $(this);
  41. let icon = $(this).attr("data-icon");
  42. $this.children("a").append("<img src=\"" + SETTINGS_ICONS_LARGE_PATH + icon + ".png\" />");
  43. });
  44. $parent.find("figure a").on("focus", function () {
  45. let $this = $(this);
  46. $this.parents("figure").first().addClass("focus");
  47. });
  48. $parent.find("figure a").on("blur", function () {
  49. let $this = $(this);
  50. $this.parents("figure").first().removeClass("focus");
  51. });
  52. $parent.find("figure a").on("dblclick", function (e) {
  53. let $this = $(this);
  54. let action = $this.parent("figure").attr("data-action");
  55. if (action) {
  56. e.stopImmediatePropagation();
  57. Actions.parseFunction(action);
  58. }
  59. });
  60. /* Folders */
  61. $parent.find("figure.folder > a, figure.trash > a").on("dblclick", function () {
  62. let $this = $(this);
  63. let wrapperID = $this.parent("figure").attr("data-id");
  64. let $iconImg = $this.children("img");
  65. let icon = $this.parent("figure").attr("data-icon");
  66. Actions.openWindow(wrapperID, "folder", true);
  67. /* Mask the icon */
  68. $iconImg.attr("src", SETTINGS_ICONS_LARGE_PATH + icon + "-mask.png");
  69. });
  70. /* Links */
  71. $parent.find("figure.link a").on("click", function () {
  72. return false;
  73. }).on("dblclick", function () {
  74. /* Open link in a new tab */
  75. window.open(this.href, "_blank").focus();
  76. return false;
  77. });
  78. /* Downloads */
  79. $parent.find("figure.download > a").on("click", function () {
  80. return false;
  81. }).on("dblclick", function () {
  82. let $this = $(this);
  83. let wrapperID = $this.parent("figure").attr("data-id");
  84. let desktopDBItem = findDesktopDBItem(g_DesktopDB, "id", wrapperID);
  85. Actions.downloadFile(desktopDBItem);
  86. });
  87. /* Applications */
  88. $parent.find("figure.application > a").on("click", function () {
  89. return false;
  90. }).on("dblclick", function () {
  91. let $this = $(this);
  92. let wrapperID = $this.parent("figure").attr("data-id");
  93. let $iconImg = $this.children("img");
  94. let icon = $this.parent("figure").attr("data-icon");
  95. Actions.openWindow(wrapperID, wrapperID, true);
  96. $iconImg.attr("src", SETTINGS_ICONS_LARGE_PATH + icon + "-mask.png");
  97. });
  98. /* Documents */
  99. $parent.find("figure.document > a").on("click", function () {
  100. return false;
  101. }).on("dblclick", function () {
  102. let $this = $(this);
  103. let wrapperID = $this.parents("figure").first().attr("data-id");
  104. let desktopDBItem = findDesktopDBItem(g_DesktopDB, "id", wrapperID);
  105. let $simpleTextFigure = $("figure[data-id=\"simpletext\"]");
  106. let $simpleTextIconImg = $simpleTextFigure.find("img");
  107. let simpleTextIcon = $simpleTextFigure.attr("data-icon");
  108. $simpleTextIconImg.attr("src", SETTINGS_ICONS_LARGE_PATH + simpleTextIcon + "-mask.png");
  109. /* Open a SimpleText window */
  110. Actions.openWindow("simpletext", "simpletext", false, function ($wrapper) {
  111. let $simpleTextText = $wrapper.find(".simpletext-text");
  112. /* Text data requires special formatting */
  113. if (desktopDBItem.url.split(".").pop() === "txt") {
  114. $simpleTextText.addClass("text-data");
  115. } else {
  116. $simpleTextText.removeClass("text-data");
  117. }
  118. $simpleTextText.load(desktopDBItem.url, function () {
  119. /* Initialize jScrollPane */
  120. let jsp = $wrapper.find(".body").jScrollPane(g_jScrollPaneSettings);
  121. jsp.data("jsp").reinitialise();
  122. });
  123. /* Set the SimpleText window title to the document name */
  124. $wrapper.find(".title").html(desktopDBItem.name)
  125. });
  126. });
  127. /* Pictures */
  128. $parent.find("figure.picture > a").on("click", function () {
  129. return false;
  130. }).on("dblclick", function () {
  131. let $this = $(this);
  132. let wrapperID = $this.parents("figure").first().attr("data-id");
  133. let $existingWrapper = $(".window-wrapper[data-id=\"pictureviewer\"]");
  134. let desktopDBItem = findDesktopDBItem(g_DesktopDB, "id", wrapperID);
  135. let $pictureViewerFigure = $("figure[data-id=\"pictureviewer\"]");
  136. let $pictureViewerIconImg = $pictureViewerFigure.find("img");
  137. let pictureViewerIcon = $pictureViewerFigure.attr("data-icon");
  138. $pictureViewerIconImg.attr("src", SETTINGS_ICONS_LARGE_PATH + pictureViewerIcon + "-mask.png");
  139. /* Quick hack to automatically resize the window (close it first!) */
  140. if ($existingWrapper.length) {
  141. Actions.closeWindow($existingWrapper, false);
  142. }
  143. /* Open a PictureViewer window */
  144. Actions.openWindow("pictureviewer", "pictureviewer", false, function ($wrapper) {
  145. /* Load in the image from the DesktopDBItem URL */
  146. let $pictureViewerImage = $wrapper.find(".pictureviewer-image");
  147. let image = new Image();
  148. image.src = desktopDBItem.url;
  149. image.onload = function () {
  150. $pictureViewerImage.html(image);
  151. /* Initialize jScrollPane */
  152. let jsp = $wrapper.find(".body").jScrollPane(g_jScrollPaneSettings);
  153. jsp.data("jsp").reinitialise();
  154. };
  155. /* Set the PictureViewer window title to the document name */
  156. $wrapper.find(".title").html(desktopDBItem.name)
  157. });
  158. });
  159. /* Movies */
  160. $parent.find("figure.movie > a").on("click", function () {
  161. return false;
  162. }).on("dblclick", function () {
  163. let $this = $(this);
  164. let wrapperID = $this.parents("figure").first().attr("data-id");
  165. let $existingWrapper = $(".window-wrapper[data-id=\"pictureviewer\"]");
  166. let desktopDBItem = findDesktopDBItem(g_DesktopDB, "id", wrapperID);
  167. let $pictureViewerFigure = $("figure[data-id=\"pictureviewer\"]");
  168. let $pictureViewerIconImg = $pictureViewerFigure.find("img");
  169. let pictureViewerIcon = $pictureViewerFigure.attr("data-icon");
  170. $pictureViewerIconImg.attr("src", SETTINGS_ICONS_LARGE_PATH + pictureViewerIcon + "-mask.png");
  171. /* Quick hack to automatically resize the window (close it first!) */
  172. if ($existingWrapper.length) {
  173. Actions.closeWindow($existingWrapper, false);
  174. }
  175. /* Open a PictureViewer window */
  176. Actions.openWindow("pictureviewer", "pictureviewer", false, function ($wrapper) {
  177. /* Load in the image from the DesktopDBItem URL */
  178. let $pictureViewerImage = $wrapper.find(".pictureviewer-image");
  179. $pictureViewerImage.html("<video autoplay><source src=\"" + desktopDBItem.url + "\" type=\"video/mp4\"></video>");
  180. let $video = $pictureViewerImage.find("video");
  181. $video.onload = function () {
  182. /* Initialize jScrollPane */
  183. let jsp = $wrapper.find(".body").jScrollPane(g_jScrollPaneSettings);
  184. jsp.data("jsp").reinitialise();
  185. };
  186. /* Set the PictureViewer window title to the document name */
  187. $wrapper.find(".title").html(desktopDBItem.name)
  188. });
  189. });
  190. /* The label will also open the figure */
  191. $parent.find("figure figcaption").on("dblclick", function () {
  192. let $this = $(this);
  193. $this.siblings("a").first().trigger("dblclick");
  194. });
  195. }