preview.html 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="apple-mobile-web-app-capable" content="yes" />
  6. <meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1, maximum-scale=1"/>
  7. <meta name="theme-color" content="#4b75ff">
  8. <link rel="stylesheet" href="../script/semantic/semantic.min.css">
  9. <script src="../script/jquery.min.js"></script>
  10. <script src="../script/semantic/semantic.min.js"></script>
  11. <script src="../script/ao_module.js"></script>
  12. <title>Camera</title>
  13. <style>
  14. body{
  15. background-color: black;
  16. }
  17. .topcontrol{
  18. position: fixed;
  19. top: 0px;
  20. left: 0px;
  21. width: 100%;
  22. padding: 8px;
  23. z-index: 1000;
  24. }
  25. .clickable{
  26. width: 3em;
  27. cursor: pointer;
  28. }
  29. .right-floated{
  30. position: absolute;
  31. right: 8px;
  32. top: 8px;
  33. display: inline-block;
  34. }
  35. .imgwrapper{
  36. position: fixed;
  37. top: 0px;
  38. left: 0px;
  39. width: 100%;
  40. height: 100%;
  41. z-index: 10;
  42. }
  43. .imgbox {
  44. display: grid;
  45. height: 100%;
  46. z-index: 10 !important;
  47. }
  48. .center-fit {
  49. max-width: 100%;
  50. max-height: 100vh;
  51. margin: auto;
  52. z-index: 10;
  53. }
  54. </style>
  55. </head>
  56. <body>
  57. <div class="topcontrol">
  58. <div class="clickable" onclick="backToCamera();">
  59. <img class="ui mini image" src="img/icons/back-arrow.svg"/>
  60. </div>
  61. <div class="right-floated">
  62. <div class="clickable" onclick="openInFolder();" style="display: inline-block;">
  63. <img class="ui mini image" src="img/icons/folder.svg"/>
  64. </div>
  65. <div class="clickable" onclick="deleteThis();" style="display: inline-block;">
  66. <img class="ui mini image" src="img/icons/delete.svg"/>
  67. </div>
  68. </div>
  69. </div>
  70. <div class="imgwrapper">
  71. <div class="imgbox">
  72. <img id="viewpoint" class="center-fit" src='img/place-holder.png'>
  73. </div>
  74. </div>
  75. <script>
  76. let photoList = [];
  77. let currentViewingPhoto = 0; //The index of current viewing photo
  78. let saveTarget = "user:/Photo/DCIM/";
  79. function backToCamera(){
  80. window.location.href = "index.html";
  81. }
  82. $(document).ready(function(){
  83. //Load the latest image
  84. ao_module_agirun("Camera/backend/listPhoto.js",{
  85. savetarget: saveTarget,
  86. }, function(data){
  87. if (data.error !== undefined || data == ""){
  88. //No photo
  89. }else{
  90. //Load it
  91. currentViewingPhoto = 0;
  92. photoList = data;
  93. $("#viewpoint").attr('src', '../media/?file=' + data[0]);
  94. }
  95. });
  96. });
  97. function openInFolder(){
  98. if (currentViewingPhoto == ""){
  99. //Unknown error. open the DCIM folder
  100. ao_module_openPath(saveTarget);
  101. }else{
  102. //Open the folder and highlight the picture
  103. var filedata = currentViewingPhoto.split("/");
  104. var filename = filedata.pop();
  105. var fileRoot = filedata.join("/");
  106. ao_module_openPath(fileRoot, filename);
  107. }
  108. }
  109. function nextPhoto(){
  110. if (currentViewingPhoto == currentViewingPhoto.length - 1){
  111. //Already the last photo
  112. }else{
  113. renderPhotoByPath(currentViewingPhoto + 1);
  114. }
  115. }
  116. function previousPhoto(){
  117. if (currentViewingPhoto == 0){
  118. //Already the firs photo
  119. }else{
  120. renderPhotoByPath(currentViewingPhoto - 1);
  121. }
  122. }
  123. function renderPhotoByPath(index){
  124. if (photoList[index] != undefined){
  125. currentViewingPhoto = index;
  126. $("#viewpoint").attr('src', '../media/?file=' + photoList[index]);
  127. }
  128. }
  129. /*
  130. Special code to handle swipe left and right
  131. */
  132. document.addEventListener('touchstart', handleTouchStart, false);
  133. document.addEventListener('touchmove', handleTouchMove, false);
  134. var xDown = null;
  135. var yDown = null;
  136. function getTouches(evt) {
  137. return evt.touches || // browser API
  138. evt.originalEvent.touches; // jQuery
  139. }
  140. function handleTouchStart(evt) {
  141. const firstTouch = getTouches(evt)[0];
  142. xDown = firstTouch.clientX;
  143. yDown = firstTouch.clientY;
  144. };
  145. function handleTouchMove(evt) {
  146. if ( ! xDown || ! yDown ) {
  147. return;
  148. }
  149. var xUp = evt.touches[0].clientX;
  150. var yUp = evt.touches[0].clientY;
  151. var xDiff = xDown - xUp;
  152. var yDiff = yDown - yUp;
  153. if ( Math.abs( xDiff ) > Math.abs( yDiff ) ) {/*most significant*/
  154. if ( xDiff > 0 ) {
  155. /* left swipe */
  156. nextPhoto();
  157. } else {
  158. /* right swipe */
  159. previousPhoto();
  160. }
  161. } else {
  162. if ( yDiff > 0 ) {
  163. /* up swipe */
  164. } else {
  165. /* down swipe */
  166. }
  167. }
  168. /* reset values */
  169. xDown = null;
  170. yDown = null;
  171. };
  172. </script>
  173. </body>
  174. </html>