photo.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /*
  2. Photo.js
  3. Author: tobychui
  4. This is a complete rewrite of the legacy Photo module for ArozOS
  5. */
  6. let photoList = [];
  7. function scrollbarVisable(){
  8. return $("body")[0].scrollHeight > $("body").height();
  9. }
  10. function getImageWidth(){
  11. let boxCount = 4;
  12. if (window.innerWidth < 500) {
  13. boxCount = 3;
  14. } else if (window.innerWidth < 800) {
  15. boxCount = 4;
  16. } else if (window.innerWidth < 1200) {
  17. boxCount = 6;
  18. }else if (window.innerWidth < 1600){
  19. boxCount = 8;
  20. } else {
  21. boxCount = 10;
  22. }
  23. let offsets = 1;
  24. if (scrollbarVisable()){
  25. offsets = 3;
  26. }
  27. return $("#viewbox").width() / boxCount - offsets;
  28. }
  29. function updateImageSizes(){
  30. let newImageWidth = getImageWidth();
  31. //Updates all the size of the images
  32. $(".imagecard").css({
  33. width: newImageWidth,
  34. height: newImageWidth
  35. });
  36. }
  37. function closeSideMenu(){
  38. $('#menu').toggle('fast', function(){
  39. updateImageSizes();
  40. });
  41. }
  42. function extractFolderName(folderpath){
  43. return folderpath.split("/").pop();
  44. }
  45. function photoListObject() {
  46. return {
  47. // data
  48. pathWildcard: "user:/Photo/*",
  49. currentPath: "user:/Photo",
  50. renderSize: 200,
  51. vroots: [],
  52. images: [],
  53. folders: [],
  54. // init
  55. init() {
  56. this.getFolderInfo();
  57. this.getRootInfo();
  58. this.renderSize = getImageWidth();
  59. updateImageSizes();
  60. },
  61. updateRenderingPath(newPath){
  62. this.currentPath = JSON.parse(JSON.stringify(newPath));
  63. this.pathWildcard = newPath + '/*';
  64. if (this.pathWildcard.split("/").length == 3){
  65. //Root path already
  66. $("#parentFolderButton").hide();
  67. }else{
  68. $("#parentFolderButton").show();
  69. }
  70. this.getFolderInfo();
  71. },
  72. parentFolder(){
  73. var parentPath = JSON.parse(JSON.stringify(this.currentPath));
  74. parentPath = parentPath.split("/");
  75. parentPath.pop();
  76. this.currentPath = parentPath.join("/");
  77. this.updateRenderingPath( this.currentPath);
  78. },
  79. getFolderInfo() {
  80. fetch(ao_root + "system/ajgi/interface?script=Photo/backend/listFolder.js", {
  81. method: 'POST',
  82. cache: 'no-cache',
  83. headers: {
  84. 'Content-Type': 'application/json'
  85. },
  86. body: JSON.stringify({
  87. "folder": this.pathWildcard
  88. })
  89. }).then(resp => {
  90. resp.json().then(data => {
  91. console.log(data);
  92. this.folders = data[0];
  93. this.images = data[1];
  94. if (this.images.length == 0){
  95. $("#noimg").show();
  96. }else{
  97. $("#noimg").hide();
  98. }
  99. if (this.folders.length == 0){
  100. $("#nosubfolder").show();
  101. }else{
  102. $("#nosubfolder").hide();
  103. }
  104. console.log(this.folders);
  105. });
  106. });
  107. },
  108. getRootInfo() {
  109. fetch(ao_root + "system/ajgi/interface?script=Photo/backend/listRoots.js", {
  110. method: 'POST',
  111. cache: 'no-cache',
  112. headers: {
  113. 'Content-Type': 'application/json'
  114. },
  115. body: JSON.stringify({})
  116. }).then(resp => {
  117. resp.json().then(data => {
  118. this.vroots = data;
  119. });
  120. })
  121. }
  122. }
  123. }
  124. function ShowModal(){
  125. $('.ui.modal').modal('show');
  126. }
  127. function showImage(object){
  128. var fd = JSON.parse(decodeURIComponent($(object).attr("filedata")));
  129. console.log(fd);
  130. $("#fullImage").attr('src', "../media?file=" + fd.filepath);
  131. var nextCard = $(object).next(".imagecard");
  132. var prevCard = $(object).prev(".imagecard");
  133. if (nextCard.length > 0){
  134. }
  135. if (prevCard.length > 0){
  136. }
  137. console.log(nextCard, prevCard);
  138. }