preview.html 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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. .rightarrow{
  55. position: fixed;
  56. top: calc(50% - 1.5em);
  57. right: 1em;
  58. z-index: 1000;
  59. }
  60. .leftarrow{
  61. position: fixed;
  62. top: calc(50% - 1.5em);
  63. left: 1em;
  64. z-index: 1000;
  65. }
  66. </style>
  67. </head>
  68. <body>
  69. <div class="topcontrol">
  70. <div class="clickable" onclick="backToCamera();">
  71. <img class="ui mini image" src="img/icons/back-arrow.svg"/>
  72. </div>
  73. <div class="right-floated">
  74. <div class="clickable" onclick="openInFolder();" style="display: inline-block;">
  75. <img class="ui mini image" src="img/icons/folder.svg"/>
  76. </div>
  77. <div class="clickable" onclick="deleteThis();" style="display: inline-block;">
  78. <img class="ui mini image" src="img/icons/delete.svg"/>
  79. </div>
  80. </div>
  81. </div>
  82. <div class="desktopcontrols">
  83. <div class="rightarrow">
  84. <img onclick="nextPhoto();" style="width: 3em; cursor: pointer;" src="img/icons/right.svg">
  85. </div>
  86. <div class="leftarrow">
  87. <img onclick="previousPhoto();" style="width: 3em; cursor: pointer;" src="img/icons/left.svg">
  88. </div>
  89. </div>
  90. <div class="imgwrapper">
  91. <div class="imgbox">
  92. <img id="viewpoint" class="center-fit" src='img/place-holder.png'>
  93. </div>
  94. </div>
  95. <script>
  96. let photoList = [];
  97. let currentViewingPhoto = 0; //The index of current viewing photo
  98. let saveTarget = "user:/Photo/DCIM/";
  99. function backToCamera(){
  100. window.location.href = "index.html";
  101. }
  102. $(document).on("keydown", function(e){
  103. if (e.keyCode == 39){
  104. nextPhoto();
  105. }else if (e.keyCode == 37){
  106. previousPhoto();
  107. }
  108. });
  109. $(document).ready(function(){
  110. //Load the latest image
  111. ao_module_agirun("Camera/backend/listPhoto.js",{
  112. savetarget: saveTarget,
  113. }, function(data){
  114. if (data.error !== undefined || data == ""){
  115. //No photo
  116. }else{
  117. //Load it
  118. currentViewingPhoto = 0;
  119. photoList = data;
  120. $("#viewpoint").attr('src', '../media/?file=' + data[0]);
  121. }
  122. });
  123. });
  124. function openInFolder(){
  125. if (currentViewingPhoto == ""){
  126. //Unknown error. open the DCIM folder
  127. ao_module_openPath(saveTarget);
  128. }else{
  129. //Open the folder and highlight the picture
  130. var filedata = currentViewingPhoto.split("/");
  131. var filename = filedata.pop();
  132. var fileRoot = filedata.join("/");
  133. ao_module_openPath(fileRoot, filename);
  134. }
  135. }
  136. function nextPhoto(){
  137. if (currentViewingPhoto == currentViewingPhoto.length - 1){
  138. //Already the last photo
  139. }else{
  140. renderPhotoByPath(currentViewingPhoto + 1);
  141. }
  142. }
  143. function previousPhoto(){
  144. if (currentViewingPhoto == 0){
  145. //Already the firs photo
  146. }else{
  147. renderPhotoByPath(currentViewingPhoto - 1);
  148. }
  149. }
  150. function renderPhotoByPath(index){
  151. if (photoList[index] != undefined){
  152. currentViewingPhoto = index;
  153. $("#viewpoint").attr('src', '../media/?file=' + photoList[index]);
  154. }
  155. }
  156. /*
  157. Special code to handle swipe left and right
  158. */
  159. document.addEventListener('touchstart', handleTouchStart, false);
  160. document.addEventListener('touchmove', handleTouchMove, false);
  161. var xDown = null;
  162. var yDown = null;
  163. function getTouches(evt) {
  164. return evt.touches || // browser API
  165. evt.originalEvent.touches; // jQuery
  166. }
  167. function handleTouchStart(evt) {
  168. const firstTouch = getTouches(evt)[0];
  169. xDown = firstTouch.clientX;
  170. yDown = firstTouch.clientY;
  171. };
  172. function handleTouchMove(evt) {
  173. if ( ! xDown || ! yDown ) {
  174. return;
  175. }
  176. var xUp = evt.touches[0].clientX;
  177. var yUp = evt.touches[0].clientY;
  178. var xDiff = xDown - xUp;
  179. var yDiff = yDown - yUp;
  180. if ( Math.abs( xDiff ) > Math.abs( yDiff ) ) {/*most significant*/
  181. if ( xDiff > 0 ) {
  182. /* left swipe */
  183. nextPhoto();
  184. } else {
  185. /* right swipe */
  186. previousPhoto();
  187. }
  188. } else {
  189. if ( yDiff > 0 ) {
  190. /* up swipe */
  191. } else {
  192. /* down swipe */
  193. }
  194. }
  195. /* reset values */
  196. xDown = null;
  197. yDown = null;
  198. };
  199. </script>
  200. </body>
  201. </html>