embedded.html 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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 Viewer</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. body{
  14. margin: 0px !important;
  15. background:rgba(34,34,34,1);
  16. overflow: hidden;
  17. }
  18. .arrow{
  19. width: 2em;
  20. opacity: 0.5;
  21. position: fixed;
  22. top: calc(50% - 1em);
  23. cursor: pointer;
  24. }
  25. .left.arrow{
  26. left: 2em;
  27. }
  28. .right.arrow{
  29. right: 2em;
  30. }
  31. </style>
  32. </head>
  33. <body>
  34. <img id="img" style="max-height: 100vh;max-width: 100%;">
  35. <img class="left arrow" onclick="previousImage();" src="embedded/arrow-left.svg">
  36. <img class="right arrow" onclick="nextImage();" src="embedded/arrow-right.svg">
  37. <script>
  38. //Get file playback info from hash
  39. var playbackFile = ao_module_loadInputFiles();
  40. var nearbyFileList = [];
  41. var currentViewingIndex = 0;
  42. //Only handle one file
  43. playbackFile = playbackFile[0];
  44. loadImage(playbackFile.filename, playbackFile.filepath);
  45. $(window).on("resize ", function() {
  46. updateImgSize();
  47. });
  48. //Load the nearby image files and allow swapping using <- and -> key
  49. function loadNearbyFiles(filepath){
  50. ao_module_agirun("Photo/embedded/listNearbyImage.js", {
  51. path: filepath
  52. }, function(data){
  53. if (data.error != undefined){
  54. alert(data.error);
  55. }else{
  56. nearbyFileList = data;
  57. //Track which index currently the user is viewing
  58. for (var i = 0; i < nearbyFileList.length; i++){
  59. var thisPath = nearbyFileList[i];
  60. if (thisPath == filepath.split("\\").join("/")){
  61. currentViewingIndex = i;
  62. }
  63. }
  64. }
  65. })
  66. }
  67. function nextImage(){
  68. nextPhoto = currentViewingIndex + 1;
  69. if (nextPhoto > nearbyFileList.length - 1){
  70. nextPhoto = nearbyFileList.length - 1;
  71. }
  72. var filepath = nearbyFileList[nextPhoto];
  73. var filename = filepath.split('/').pop();
  74. if (nextPhoto != currentViewingIndex){
  75. //Change in photo index
  76. loadImage(filename, filepath);
  77. currentViewingIndex = nextPhoto;
  78. }
  79. }
  80. function previousImage(){
  81. nextPhoto = currentViewingIndex - 1;
  82. if (nextPhoto < 0){
  83. nextPhoto = 0;
  84. }
  85. var filepath = nearbyFileList[nextPhoto];
  86. var filename = filepath.split('/').pop();
  87. if (nextPhoto != currentViewingIndex){
  88. //Change in photo index
  89. loadImage(filename, filepath);
  90. currentViewingIndex = nextPhoto;
  91. }
  92. }
  93. //Bind arrow key events
  94. $("body").on("keydown", function(e){
  95. var nextPhoto = currentViewingIndex;
  96. if (e.keyCode == 37){
  97. //<-
  98. previousImage();
  99. }else if (e.keyCode == 39){
  100. //->
  101. nextImage();
  102. }else{
  103. //Invalid keycode to operate
  104. return;
  105. }
  106. })
  107. loadNearbyFiles(playbackFile.filepath);
  108. function loadImage(filename, filepath){
  109. $("#img").hide();
  110. ao_module_setWindowTitle("Photo - " + filename);
  111. $("#img").attr("src", '../media?file=' + encodeURIComponent(filepath))
  112. //realigin to center
  113. $('#img').on('load', function() {
  114. updateImgSize();
  115. $("#img").show();
  116. });
  117. }
  118. function updateImgSize() {
  119. $('#img').css("margin-top", (window.innerHeight - $("#img").height()) / 2);
  120. $('#img').css("margin-left", (window.innerWidth - $("#img").width()) / 2);
  121. }
  122. //Touch gesture detections
  123. document.addEventListener('touchstart', handleTouchStart, false);
  124. document.addEventListener('touchmove', handleTouchMove, false);
  125. var xDown = null;
  126. var yDown = null;
  127. function getTouches(evt) {
  128. return evt.touches || // browser API
  129. evt.originalEvent.touches; // jQuery
  130. }
  131. function handleTouchStart(evt) {
  132. const firstTouch = getTouches(evt)[0];
  133. xDown = firstTouch.clientX;
  134. yDown = firstTouch.clientY;
  135. };
  136. function handleTouchMove(evt) {
  137. if ( ! xDown || ! yDown ) {
  138. return;
  139. }
  140. var xUp = evt.touches[0].clientX;
  141. var yUp = evt.touches[0].clientY;
  142. var xDiff = xDown - xUp;
  143. var yDiff = yDown - yUp;
  144. if ( Math.abs( xDiff ) > Math.abs( yDiff ) ) {/*most significant*/
  145. if ( xDiff > 0 ) {
  146. /* right swipe */
  147. nextImage();
  148. } else {
  149. /* left swipe */
  150. previousImage();
  151. }
  152. } else {
  153. if ( yDiff > 0 ) {
  154. /* down swipe */
  155. } else {
  156. /* up swipe */
  157. }
  158. }
  159. /* reset values */
  160. xDown = null;
  161. yDown = null;
  162. };
  163. function isZoomed(){
  164. return window.matchMedia('(max--moz-device-pixel-ratio:0.99), (min--moz-device-pixel-ratio:1.01)').matches;
  165. }
  166. </script>
  167. </body>
  168. </html>