preview.html 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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="confirmDelete();" 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. <div id="confirmDelete" class="ui basic modal">
  96. <div class="ui icon header">
  97. <i class="red remove icon"></i>
  98. <span id="confirmmsg"></span>
  99. </div>
  100. <div class="content" align="center">
  101. <p>This operation is not reversible. Are you sure you want to delete this photo?</p>
  102. </div>
  103. <div class="actions">
  104. <div class="ui red basic cancel inverted button">
  105. <i class="remove icon"></i>
  106. No
  107. </div>
  108. <div class="ui red ok button" onclick="deleteThis();">
  109. <i class="trash icon"></i>
  110. Yes
  111. </div>
  112. </div>
  113. </div>
  114. <script>
  115. let photoList = [];
  116. let currentViewingPhoto = 0; //The index of current viewing photo
  117. let saveTarget = "user:/Photo/DCIM/";
  118. function backToCamera(){
  119. window.location.href = "index.html";
  120. }
  121. $(document).on("keydown", function(e){
  122. if (e.keyCode == 39){
  123. nextPhoto();
  124. }else if (e.keyCode == 37){
  125. previousPhoto();
  126. }
  127. });
  128. $(document).ready(function(){
  129. //Load the latest image
  130. initPhotoList();
  131. });
  132. function initPhotoList(overrideIndex = 0){
  133. ao_module_agirun("Camera/backend/listPhoto.js",{
  134. savetarget: saveTarget,
  135. }, function(data){
  136. if (data.error !== undefined || data == ""){
  137. //No photo
  138. }else{
  139. //Load it
  140. currentViewingPhoto = overrideIndex;
  141. photoList = data;
  142. if (overrideIndex > photoList.length - 1){
  143. overrideIndex = photoList.length - 1;
  144. }
  145. $("#viewpoint").attr('src', '../media/?file=' + data[overrideIndex]);
  146. }
  147. });
  148. }
  149. function confirmDelete(){
  150. //Generate a confirm message
  151. var filedata = photoList[currentViewingPhoto].split("/");
  152. var filename = filedata.pop();
  153. $("#confirmmsg").text("Confirm Delete " + filename + "?")
  154. $("#confirmDelete").modal('show');
  155. }
  156. function deleteThis(){
  157. var filedata = photoList[currentViewingPhoto].split("/");
  158. var filename = filedata.pop();
  159. ao_module_agirun("Camera/backend/delPhoto.js", {
  160. savetarget: saveTarget,
  161. filename: filename
  162. }, function(data){
  163. if (data.error !== undefined){
  164. alert(data.error);
  165. }else{
  166. //OK. Reload the list
  167. initPhotoList(currentViewingPhoto);
  168. }
  169. })
  170. }
  171. function openInFolder(){
  172. if (currentViewingPhoto == ""){
  173. //Unknown error. open the DCIM folder
  174. ao_module_openPath(saveTarget);
  175. }else{
  176. //Open the folder and highlight the picture
  177. var filedata = photoList[currentViewingPhoto].split("/");
  178. var filename = filedata.pop();
  179. var fileRoot = filedata.join("/");
  180. ao_module_openPath(fileRoot, filename);
  181. }
  182. }
  183. function nextPhoto(){
  184. if (currentViewingPhoto == photoList.length - 1){
  185. //Already the last photo
  186. }else{
  187. renderPhotoByPath(currentViewingPhoto + 1);
  188. }
  189. }
  190. function previousPhoto(){
  191. if (currentViewingPhoto == 0){
  192. //Already the firs photo
  193. }else{
  194. renderPhotoByPath(currentViewingPhoto - 1);
  195. }
  196. }
  197. function renderPhotoByPath(index){
  198. if (photoList[index] != undefined){
  199. currentViewingPhoto = index;
  200. $("#viewpoint").attr('src', '../media/?file=' + photoList[index]);
  201. }
  202. }
  203. /*
  204. Special code to handle swipe left and right
  205. */
  206. document.addEventListener('touchstart', handleTouchStart, false);
  207. document.addEventListener('touchmove', handleTouchMove, false);
  208. var xDown = null;
  209. var yDown = null;
  210. function getTouches(evt) {
  211. return evt.touches || // browser API
  212. evt.originalEvent.touches; // jQuery
  213. }
  214. function handleTouchStart(evt) {
  215. const firstTouch = getTouches(evt)[0];
  216. xDown = firstTouch.clientX;
  217. yDown = firstTouch.clientY;
  218. };
  219. function handleTouchMove(evt) {
  220. if ( ! xDown || ! yDown ) {
  221. return;
  222. }
  223. var xUp = evt.touches[0].clientX;
  224. var yUp = evt.touches[0].clientY;
  225. var xDiff = xDown - xUp;
  226. var yDiff = yDown - yUp;
  227. if ( Math.abs( xDiff ) > Math.abs( yDiff ) ) {/*most significant*/
  228. if ( xDiff > 0 ) {
  229. /* left swipe */
  230. nextPhoto();
  231. } else {
  232. /* right swipe */
  233. previousPhoto();
  234. }
  235. } else {
  236. if ( yDiff > 0 ) {
  237. /* up swipe */
  238. } else {
  239. /* down swipe */
  240. }
  241. }
  242. /* reset values */
  243. xDown = null;
  244. yDown = null;
  245. };
  246. </script>
  247. </body>
  248. </html>