script.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. var glob_width;
  2. var glob_height;
  3. var glob_elem;
  4. if (document.addEventListener)
  5. {
  6. document.addEventListener('webkitfullscreenchange', exitHandler, false);
  7. document.addEventListener('mozfullscreenchange', exitHandler, false);
  8. document.addEventListener('fullscreenchange', exitHandler, false);
  9. document.addEventListener('MSFullscreenChange', exitHandler, false);
  10. }
  11. function exitHandler() {
  12. if (document.webkitIsFullScreen || document.mozFullScreen || document.msFullscreenElement !== null) {
  13. if (!document.fullscreenElement && !document.mozFullScreenElement &&
  14. !document.webkitFullscreenElement && !document.msFullscreenElement) {
  15. console.log("Exit FS");
  16. //$(glob_elem).css("width", glob_width+"px");
  17. //$(glob_elem).css("height", glob_height+"px");
  18. $(glob_elem).css("width", "100%");
  19. $(glob_elem).css("height", "100%");
  20. $(glob_elem).css("background-color", "white");
  21. $(glob_elem).css("color", "#000");
  22. $("#front-quality-text").text("Size: 25%");
  23. $("#top-quality-text").text("Size: 25%");
  24. $("#left-quality-text").text("Size: 25%");
  25. } else {
  26. console.log("Enter FS");
  27. $("#front-quality-text").text("Size: 100%");
  28. $("#top-quality-text").text("Size: 100%");
  29. $("#left-quality-text").text("Size: 100%");
  30. }
  31. }
  32. }
  33. function toggleFullscreen(elem) {
  34. elem = elem || document.documentElement;
  35. var ori_width = glob_width
  36. var ori_height = glob_height;
  37. console.log("DEBUG");
  38. console.log(screen.width, screen.height, glob_width, glob_height)
  39. var fs_scale;
  40. if (!document.fullscreenElement && !document.mozFullScreenElement &&
  41. !document.webkitFullscreenElement && !document.msFullscreenElement) {
  42. if ((ori_height*1.2) > ori_width) {
  43. newWidth = screen.width * 0.5;
  44. newHeight = screen.width * (ori_height/ori_width) * 0.5;
  45. } else {
  46. newHeight = screen.height * 0.6;
  47. newWidth = screen.height * (ori_width/ori_height) * 0.6;
  48. }
  49. //$(elem, "img").css("height", (screen.height*0.8)+"px");
  50. //$(elem, "img").css("width", (screen.width*0.8)+"px");
  51. $(elem, "img").css("height", (newHeight)+"px");
  52. $(elem, "img").css("width", (newWidth)+"px");
  53. //$(elem).css("width", Math.max(screen.width, screen.height)+"px");
  54. //$(elem).css("width", "90%");
  55. $(elem).css("background-color", "black");
  56. $(elem).css("color", "#ccc");
  57. if (elem.requestFullscreen) {
  58. elem.requestFullscreen();
  59. } else if (elem.msRequestFullscreen) {
  60. elem.msRequestFullscreen();
  61. } else if (elem.mozRequestFullScreen) {
  62. elem.mozRequestFullScreen();
  63. } else if (elem.webkitRequestFullscreen) {
  64. elem.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT);
  65. }
  66. } else {
  67. console.log("Set width height");
  68. console.log(ori_width);
  69. console.log(ori_height);
  70. $(elem).css("width", "100%");
  71. //$(elem).css("height", "100%");
  72. //$(elem).css("width", ori_width+"px");
  73. //$(elem).css("height", ori_height+"px");
  74. $(elem).css("background-color", "white");
  75. $(elem).css("color", "#000");
  76. //img_fullscreen = $(elem).attr("src").split("&");
  77. //img_fullscreen = img_fullscreen[0] + "&" + img_fullscreen[1] + "&" + img_fullscreen[2] + "-resized&" + img_fullscreen[3];
  78. //$(elem).attr("src", img_fullscreen);
  79. if (document.exitFullscreen) {
  80. document.exitFullscreen();
  81. } else if (document.msExitFullscreen) {
  82. document.msExitFullscreen();
  83. } else if (document.mozCancelFullScreen) {
  84. document.mozCancelFullScreen();
  85. } else if (document.webkitExitFullscreen) {
  86. document.webkitExitFullscreen();
  87. }
  88. }
  89. }
  90. $(function() {
  91. //$("#front-quality-text").text( ($("#img-front").width() / parseInt($("#top-count").text())).toFixed(2).toString() + "%");
  92. //$("#top-quality-text").text( ($("#img-top").width() / parseInt($("#front-count").text())).toFixed(2).toString() + "%");
  93. //$("#left-quality-text").text( ($("#placeholder-left").width() / parseInt($("#front-count").text())).toFixed(2).toString() + "%");
  94. $("#front-quality-text").text("Size: 25%");
  95. $("#top-quality-text").text("Size: 25%");
  96. $("#left-quality-text").text("Size: 25%");
  97. $( "#slider-left" ).slider({
  98. range: "max",
  99. min: 1,
  100. max: parseInt($("#left-count").text()),
  101. value: 1,
  102. slide: function( event, ui ) {
  103. //console.log(ui.value);
  104. var name = $( "select option:selected" ).text();
  105. var id = $( "select option:selected" ).val();
  106. $("#left-text").text(ui.value);
  107. // update image src
  108. // data-zoom-image
  109. //$("#placeholder-left").attr("data-zoom-image", "img?id="+id+"&name="+name+"&type=left-resized&counter="+(ui.value-1));
  110. var imageUrl = "img?id="+id+"&name="+name+"&type=left&counter="+(ui.value-1);
  111. $("#placeholder-left-zoomContainer > .zoomWindowContainer > div").css('background-image', 'url("' + imageUrl + '")');
  112. //$("#placeholder-left-zoomContainer > .zoomLens").css('background-image', 'url("' + imageUrl + '")');
  113. $("#placeholder-left").attr("src", "img?id="+id+"&name="+name+"&type=left-resized&counter="+(ui.value-1));
  114. }
  115. });
  116. $( "#slider-right" ).slider({
  117. range: "max",
  118. min: 1,
  119. max: parseInt($("#front-count").text()),
  120. value: 1,
  121. slide: function( event, ui ) {
  122. //console.log(ui.value);
  123. var name = $( "select option:selected" ).text();
  124. var id = $( "select option:selected" ).val();
  125. $("#front-text").text(ui.value);
  126. // update image src
  127. var imageUrl = "img?id="+id+"&name="+name+"&type=front&counter="+(ui.value-1);
  128. $("#img-front-zoomContainer > .zoomWindowContainer > div").css('background-image', 'url("' + imageUrl + '")');
  129. //$("#img-front-zoomContainer > .zoomLens").css('background-image', 'url("' + imageUrl + '")');
  130. //$("#img-front").attr("data-zoom-image", "img?id="+id+"&name="+name+"&type=left-resized&counter="+(ui.value-1));
  131. $("#img-front").attr("src", "img?id="+id+"&name="+name+"&type=front-resized&counter="+(ui.value-1));
  132. }
  133. });
  134. $( "#slider-center" ).slider({
  135. range: "max",
  136. min: 1,
  137. max: parseInt($("#top-count").text()),
  138. value: 1,
  139. slide: function( event, ui ) {
  140. //console.log(ui.value);
  141. var name = $( "select option:selected" ).text();
  142. var id = $( "select option:selected" ).val();
  143. $("#top-text").text(ui.value);
  144. // update image src
  145. var imageUrl = "img?id="+id+"&name="+name+"&type=top&counter="+(ui.value-1);
  146. $("#img-top-zoomContainer > .zoomWindowContainer > div").css('background-image', 'url("' + imageUrl + '")');
  147. //$("#img-top-zoomContainer > .zoomLens").css('background-image', 'url("' + imageUrl + '")');
  148. $("#img-top").attr("src", "img?id="+id+"&name="+name+"&type=top-resized&counter="+(ui.value-1));
  149. }
  150. });
  151. $( "#download" ).click(function(e) {
  152. var did = $( "select option:selected" ).text();
  153. e.preventDefault(); //stop the browser from following
  154. window.location.href = 'download?did=' + did;
  155. });
  156. $('.target').change(function() {
  157. var name = $(this).find("option:selected").text();
  158. var index = $(this).find("option:selected").val();
  159. $.ajax({
  160. url: 'update?index=' + index + '&name=' + name,
  161. type: 'GET',
  162. success: function (response) {
  163. console.log("Success.");
  164. console.log(response);
  165. $("#size").text("("+response.data_size+" GB)");
  166. var html = "<span>Description</span>";
  167. for (i = 0; i < response["desc"].length; i++) {
  168. if (response["desc"][i]["type"] == "i") {
  169. tmp = "<i>" + response["desc"][i]["text"] + "</i>";
  170. } else if (response["desc"][i]["type"] == "p") {
  171. tmp = response["desc"][i]["text"];
  172. }
  173. html += tmp;
  174. }
  175. $("#description").empty().append(html);
  176. $("#front-count-text").text(" (max: " + response.front_count + ")");
  177. $("#left-count-text").text(" (max: " + response.left_count + ")");
  178. $("#top-count-text").text(" (max: " + response.top_count + ")");
  179. $("#front-count").text(response.front_count);
  180. $("#left-count").text(response.left_count);
  181. $("#top-count").text(response.top_count);
  182. $("#slider-right").slider("option", "max" , response.front_count );
  183. $("#slider-left").slider("option", "max" , response.left_count );
  184. $("#slider-center").slider("option", "max" , response.top_count );
  185. var left_index = $( "#slider-left" ).slider( "option", "value" );
  186. var top_index = $( "#slider-center" ).slider( "option", "value" );
  187. var front_index = $( "#slider-right" ).slider( "option", "value" );
  188. $("#placeholder-left").attr("src", "img?id="+index+"&name="+name+"&type=left-resized&counter="+(left_index-1));
  189. $("#img-top").attr("src", "img?id="+index+"&name="+name+"&type=top-resized&counter="+(top_index-1));
  190. $("#img-front").attr("src", "img?id="+index+"&name="+name+"&type=front-resized&counter="+(front_index-1));
  191. //$("#front-quality-text").text( " " + ($("#img-front").width() / response.front_count).toFixed(2).toString() + "%");
  192. //$("#top-quality-text").text(" " + ($("#img-top").width() / response.top_count).toFixed(2).toString() + "%");
  193. //$("#left-quality-text").text(" " + ($("#placeholder-left").width() / response.left_count).toFixed(2).toString() + "%");
  194. },
  195. error: function () {
  196. console.log("Error.")
  197. }
  198. });
  199. $("#img-preview").attr("src", "img?id="+index+"&name="+name+"&type=preview&counter=0");
  200. });
  201. $("#front-left").click( function() {
  202. var index = parseInt($("#front-text").text());
  203. var name = $( "select option:selected" ).text();
  204. var id = $( "select option:selected" ).val();
  205. index -= 1;
  206. if (index < 1) {
  207. index = 1;
  208. }
  209. $("#front-text").text(index);
  210. $("#img-front").attr("src", "img?id="+id+"&name="+name+"&type=front-resized&counter="+index.toString());
  211. });
  212. $("#front-right").click( function() {
  213. var index = parseInt($("#front-text").text());
  214. var max_count = parseInt($("#front-count").text());
  215. var name = $( "select option:selected" ).text();
  216. var id = $( "select option:selected" ).val();
  217. //console.log(index, max_count);
  218. index += 1;
  219. if (index > max_count) {
  220. index = max_count;
  221. }
  222. $("#front-text").text(index);
  223. // update image src
  224. $("#img-front").attr("src", "img?id="+id+"&name="+name+"&type=front-resized&counter="+index.toString());
  225. });
  226. $("#top-left").click( function() {
  227. var index = parseInt($("#top-text").text());
  228. var name = $( "select option:selected" ).text();
  229. var id = $( "select option:selected" ).val();
  230. index -= 1;
  231. if (index < 1) {
  232. index = 1;
  233. }
  234. $("#top-text").text(index);
  235. $("#img-top").attr("src", "img?id="+id+"&name="+name+"&type=top-resized&counter="+index.toString());
  236. });
  237. $("#top-right").click( function() {
  238. var index = parseInt($("#top-text").text());
  239. var max_count = parseInt($("#top-count").text());
  240. var name = $( "select option:selected" ).text();
  241. var id = $( "select option:selected" ).val();
  242. //console.log(index, max_count);
  243. index += 1;
  244. if (index > max_count) {
  245. index = max_count;
  246. }
  247. $("#top-text").text(index);
  248. // update image src
  249. $("#img-top").attr("src", "img?id="+id+"&name="+name+"&type=top-resized&counter="+index.toString());
  250. });
  251. $("#left-left").click( function() {
  252. var index = parseInt($("#left-text").text());
  253. var name = $( "select option:selected" ).text();
  254. var id = $( "select option:selected" ).val();
  255. index -= 1;
  256. if (index < 1) {
  257. index = 1;
  258. }
  259. $("#left-text").text(index);
  260. $("#placeholder-left").attr("src", "img?id="+id+"&name="+name+"&type=left-resized&counter="+index.toString());
  261. });
  262. $("#left-right").click( function() {
  263. var index = parseInt($("#left-text").text());
  264. var max_count = parseInt($("#left-count").text());
  265. var name = $( "select option:selected" ).text();
  266. var id = $( "select option:selected" ).val();
  267. //console.log(index, max_count);
  268. index += 1;
  269. if (index > max_count) {
  270. index = max_count;
  271. }
  272. $("#left-text").text(index);
  273. // update image src
  274. $("#placeholder-left").attr("src", "img?id="+id+"&name="+name+"&type=left-resized&counter="+index.toString());
  275. });
  276. document.getElementById("img-front").addEventListener("click", function() {
  277. var container = $("#photowrapper-front");
  278. if (!document.fullscreenElement && !document.mozFullScreenElement &&
  279. !document.webkitFullscreenElement && !document.msFullscreenElement) {
  280. glob_width = $("#photowrapper-front > img").width();
  281. glob_height = $("#photowrapper-front > img").height();
  282. glob_elem = $("#photowrapper-front")[0];
  283. }
  284. toggleFullscreen(container[0]);
  285. });
  286. document.getElementById('img-top').addEventListener('click', function() {
  287. var container = $("#photowrapper-top");
  288. if (!document.fullscreenElement && !document.mozFullScreenElement &&
  289. !document.webkitFullscreenElement && !document.msFullscreenElement) {
  290. glob_width = $("#photowrapper-top > img").width();
  291. glob_height = $("#photowrapper-top > img").height();
  292. glob_elem = $("#photowrapper-top")[0];
  293. }
  294. toggleFullscreen(container[0]);
  295. });
  296. document.getElementById('placeholder-left').addEventListener('click', function() {
  297. var container = $("#photowrapper-left");
  298. if (!document.fullscreenElement && !document.mozFullScreenElement &&
  299. !document.webkitFullscreenElement && !document.msFullscreenElement) {
  300. glob_width = $("#photowrapper-left > img").width();
  301. glob_height = $("#photowrapper-left > img").height();
  302. glob_elem = $("#photowrapper-left")[0];
  303. }
  304. toggleFullscreen(container[0]);
  305. });
  306. $("#img-top").ezPlus({
  307. zoomWindowPosition: 1,
  308. scrollZoom: true,
  309. zoomLevel: 0.1,
  310. minZoomLevel: 0.1,
  311. zoomWindowWidth: 300,
  312. zoomWindowHeight: 300
  313. });
  314. $("#placeholder-left").ezPlus({
  315. zoomWindowPosition: 9,
  316. scrollZoom: true,
  317. zoomLevel: 0.1,
  318. minZoomLevel: 0.1,
  319. zoomWindowWidth: 300,
  320. zoomWindowHeight: 300
  321. });
  322. $("#img-front").ezPlus({
  323. zoomWindowPosition: 11,
  324. scrollZoom: true,
  325. zoomLevel: 0.1,
  326. minZoomLevel: 0.1,
  327. zoomWindowWidth: 300,
  328. zoomWindowHeight: 300
  329. });
  330. });