not really known
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

98 lines
3.6 KiB

  1. /* Start of the app, we require everything that is needed */
  2. define(["sugar-web/activity/activity"], function (activity) {
  3. requirejs(['domReady!', 'sugar-web/datastore'], function (doc, datastore) {
  4. activity.setup();
  5. if (!(window.top && window.top.sugar && window.top.sugar.environment && window.top.sugar.environment.objectId)) {
  6. return;
  7. }
  8. var loadingSvg = document.getElementById("loading-svg");
  9. loadingSvg.style.width = document.body.clientWidth + "px";
  10. loadingSvg.style.height = document.body.clientHeight + "px";
  11. loadingSvg.style.display = "block";
  12. var timeout = 0;
  13. if (typeof chrome != 'undefined' && chrome.app && chrome.app.runtime) {
  14. chrome.storage.local.get('sugar_settings', function (values) {
  15. timeout = 500;
  16. });
  17. } else {
  18. timeout = 200;
  19. }
  20. setTimeout(function () {
  21. activity.getDatastoreObject().loadAsText(function (error, metadata, data) {
  22. loadingSvg.style.display = "none";
  23. if (data == null || !metadata || !metadata.mimetype) {
  24. return;
  25. }
  26. var mimetype = metadata.mimetype;
  27. var type = mimetype.split("/")[0];
  28. if (type.indexOf("audio") == 0) {
  29. displayAudio(data);
  30. }
  31. if (type.indexOf("image") == 0) {
  32. displayImage(data);
  33. }
  34. if (type.indexOf("video") == 0) {
  35. displayVideo(data);
  36. }
  37. });
  38. }, 1000);
  39. });
  40. });
  41. function displayAudio(data) {
  42. var audio = document.createElement("audio");
  43. audio.src = data;
  44. audio.setAttribute("controls", "");
  45. audio.style.maxWidth = document.body.clientWidth - 55 + "px";
  46. audio.style.width = document.body.clientWidth - 60 + "px";
  47. audio.style.marginTop = (document.body.clientHeight - 55 - audio.getBoundingClientRect().height) / 2 + "px"
  48. document.getElementById("media").appendChild(audio);
  49. }
  50. function displayVideo(data) {
  51. var video = document.createElement("video");
  52. video.src = data;
  53. video.setAttribute("controls", "");
  54. if (document.body.clientWidth > document.body.clientHeight) {
  55. video.style.marginTop = "3px";
  56. video.style.width = "auto";
  57. video.style.maxHeight = document.body.clientHeight - 55 + "px";
  58. video.style.height = document.body.clientHeight - 60 + "px";
  59. } else {
  60. video.style.height = "auto";
  61. video.style.maxWidth = document.body.clientWidth - 55 + "px";
  62. video.style.width = document.body.clientWidth - 60 + "px";
  63. video.style.marginTop = (document.body.clientHeight - 55 - video.getBoundingClientRect().height) / 4 + "px"
  64. }
  65. document.getElementById("media").appendChild(video);
  66. }
  67. function displayImage(data) {
  68. var img = document.createElement("img");
  69. img.src = data;
  70. if (document.body.clientWidth > document.body.clientHeight) {
  71. img.style.marginTop = "3px";
  72. img.style.width = "auto";
  73. img.style.maxHeight = document.body.clientHeight - 55 + "px";
  74. img.style.height = document.body.clientHeight - 60 + "px";
  75. } else {
  76. img.style.height = "auto";
  77. img.style.maxWidth = document.body.clientWidth - 55 + "px";
  78. img.style.width = document.body.clientWidth - 60 + "px";
  79. img.style.marginTop = (document.body.clientHeight - 55 - img.getBoundingClientRect().height) / 4 + "px"
  80. }
  81. document.getElementById("media").appendChild(img);
  82. }