embedded.html 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <!DOCTYPE html>
  2. <meta name="apple-mobile-web-app-capable" content="yes" />
  3. <meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1, maximum-scale=1" />
  4. <html>
  5. <head>
  6. <meta charset="UTF-8">
  7. <meta name="theme-color" content="#4b75ff">
  8. <title>Photo Preview</title>
  9. <script src="../script/jquery.min.js"></script>
  10. <script src="../script/ao_module.js"></script>
  11. <link rel="manifest" href="manifest.json">
  12. <style>
  13. .arrow{
  14. width: 2em;
  15. opacity: 0.5;
  16. position: fixed;
  17. top: calc(50% - 1em);
  18. cursor: pointer;
  19. }
  20. .left.arrow{
  21. left: 2em;
  22. }
  23. .right.arrow{
  24. right: 2em;
  25. }
  26. </style>
  27. </head>
  28. <body style="background:rgba(34,34,34,1);overflow:hidden;">
  29. <img id="img" style="max-height: 100vh;max-width: 100vw;">
  30. <img class="left arrow" onclick="previousImage();" src="embedded/arrow-left.svg">
  31. <img class="right arrow" onclick="nextImage();" src="embedded/arrow-right.svg">
  32. <script>
  33. //Get file playback info from hash
  34. var playbackFile = ao_module_loadInputFiles();
  35. var nearbyFileList = [];
  36. var currentViewingIndex = 0;
  37. //Only handle one file
  38. playbackFile = playbackFile[0];
  39. loadImage(playbackFile.filename, playbackFile.filepath);
  40. $(window).on("resize ", function() {
  41. updateImgSize();
  42. });
  43. //Load the nearby image files and allow swapping using <- and -> key
  44. function loadNearbyFiles(filepath){
  45. ao_module_agirun("Photo/embedded/listNearbyImage.js", {
  46. path: filepath
  47. }, function(data){
  48. if (data.error != undefined){
  49. alert(data.error);
  50. }else{
  51. nearbyFileList = data;
  52. //Track which index currently the user is viewing
  53. for (var i = 0; i < nearbyFileList.length; i++){
  54. var thisPath = nearbyFileList[i];
  55. if (thisPath == filepath.split("\\").join("/")){
  56. currentViewingIndex = i;
  57. }
  58. }
  59. }
  60. })
  61. }
  62. function nextImage(){
  63. nextPhoto = currentViewingIndex + 1;
  64. if (nextPhoto > nearbyFileList.length - 1){
  65. nextPhoto = nearbyFileList.length - 1;
  66. }
  67. var filepath = nearbyFileList[nextPhoto];
  68. var filename = filepath.split('/').pop();
  69. if (nextPhoto != currentViewingIndex){
  70. //Change in photo index
  71. loadImage(filename, filepath);
  72. currentViewingIndex = nextPhoto;
  73. }
  74. }
  75. function previousImage(){
  76. nextPhoto = currentViewingIndex - 1;
  77. if (nextPhoto < 0){
  78. nextPhoto = 0;
  79. }
  80. var filepath = nearbyFileList[nextPhoto];
  81. var filename = filepath.split('/').pop();
  82. if (nextPhoto != currentViewingIndex){
  83. //Change in photo index
  84. loadImage(filename, filepath);
  85. currentViewingIndex = nextPhoto;
  86. }
  87. }
  88. //Bind arrow key events
  89. $("body").on("keydown", function(e){
  90. var nextPhoto = currentViewingIndex;
  91. if (e.keyCode == 37){
  92. //<-
  93. previousImage();
  94. }else if (e.keyCode == 39){
  95. //->
  96. nextImage();
  97. }else{
  98. //Invalid keycode to operate
  99. return;
  100. }
  101. })
  102. loadNearbyFiles(playbackFile.filepath);
  103. function loadImage(filename, filepath){
  104. $("#img").hide();
  105. ao_module_setWindowTitle("Photo - " + filename);
  106. $("#img").attr("src", '../media?file=' + encodeURIComponent(filepath))
  107. //realigin to center
  108. $('#img').on('load', function() {
  109. updateImgSize();
  110. $("#img").show();
  111. });
  112. }
  113. function updateImgSize() {
  114. $('#img').css("margin-top", (window.innerHeight - $("#img").height()) / 2 - 6);
  115. $('#img').css("margin-left", (window.innerWidth - $("#img").width()) / 2 - 6);
  116. }
  117. </script>
  118. </body>
  119. </html>