script2.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498
  1. var glob_width;
  2. var glob_height;
  3. var glob_elem;
  4. var glob_id;
  5. if (document.addEventListener)
  6. {
  7. document.addEventListener('webkitfullscreenchange', exitHandler, false);
  8. document.addEventListener('mozfullscreenchange', exitHandler, false);
  9. document.addEventListener('fullscreenchange', exitHandler, false);
  10. document.addEventListener('MSFullscreenChange', exitHandler, false);
  11. }
  12. function exitHandler() {
  13. if (document.webkitIsFullScreen || document.mozFullScreen || document.msFullscreenElement !== null) {
  14. if (!document.fullscreenElement && !document.mozFullScreenElement &&
  15. !document.webkitFullscreenElement && !document.msFullscreenElement) {
  16. $(glob_elem).css("width", "100%");
  17. $(glob_elem).css("height", "100%");
  18. $(glob_elem).css("background-color", "white");
  19. $(glob_elem).css("color", "#000");
  20. $("#front-quality-text").text("Size: 25%");
  21. $("#top-quality-text").text("Size: 25%");
  22. $("#left-quality-text").text("Size: 25%");
  23. $("#"+glob_id).width('100%');
  24. $("#"+glob_id).height("100%");
  25. } else {
  26. $("#front-quality-text").text("Size: 100%");
  27. $("#top-quality-text").text("Size: 100%");
  28. $("#left-quality-text").text("Size: 100%");
  29. }
  30. }
  31. }
  32. function toggleFullscreen(elem, _id) {
  33. elem = elem || document.documentElement;
  34. console.log("ID: "+_id);
  35. var ori_width = glob_width
  36. var ori_height = glob_height;
  37. var fs_scale;
  38. var myRatio;
  39. if (window.devicePixelRatio < 1) {
  40. myRatio = 1.0;
  41. } else {
  42. myRatio = 2.0;
  43. }
  44. $("#"+_id).css('width', 'auto')
  45. $("#"+_id).css('height', 'auto')
  46. if (!document.fullscreenElement && !document.mozFullScreenElement &&
  47. !document.webkitFullscreenElement && !document.msFullscreenElement) {
  48. if ((ori_height*1.2) > ori_width) {
  49. //newWidth = screen.width * (1/Math.ceil(window.devicePixelRatio));
  50. //newHeight = screen.width * (ori_height/ori_width) * (1/Math.ceil(window.devicePixelRatio));
  51. newWidth = screen.width * (1/ myRatio);
  52. newHeight = screen.width * (ori_height/ori_width) * (1/ myRatio);
  53. $("#"+_id).removeAttr('width');
  54. $("#"+_id).height("80%");
  55. } else {
  56. newHeight = screen.height * (1/myRatio);
  57. newWidth = screen.height * (ori_width/ori_height) * (1/myRatio);
  58. $("#"+_id).removeAttr('height');
  59. $("#"+_id).width("100%");
  60. //newHeight = screen.height * (1/Math.ceil(window.devicePixelRatio));
  61. //newWidth = screen.height * (ori_width/ori_height) * (1/Math.ceil(window.devicePixelRatio));
  62. }
  63. $(elem).css("height", (newHeight)+"px");
  64. $(elem).css("width", (newWidth)+"px");
  65. //$("#"+_id).removeAttr('width');
  66. //$("#"+_id).height("80%");
  67. //$(elem).css("width", "200px");
  68. $(elem).css("background-color", "black");
  69. $(elem).css("color", "#ccc");
  70. if (elem.requestFullscreen) {
  71. elem.requestFullscreen();
  72. } else if (elem.msRequestFullscreen) {
  73. elem.msRequestFullscreen();
  74. } else if (elem.mozRequestFullScreen) {
  75. elem.mozRequestFullScreen();
  76. } else if (elem.webkitRequestFullscreen) {
  77. elem.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT);
  78. }
  79. } else {
  80. $("#"+_id).width('100%');
  81. $("#"+_id).height("100%");
  82. //$(elem).css("width", "100%");
  83. $(elem).css("background-color", "white");
  84. $(elem).css("color", "#000");
  85. if (document.exitFullscreen) {
  86. document.exitFullscreen();
  87. } else if (document.msExitFullscreen) {
  88. document.msExitFullscreen();
  89. } else if (document.mozCancelFullScreen) {
  90. document.mozCancelFullScreen();
  91. } else if (document.webkitExitFullscreen) {
  92. document.webkitExitFullscreen();
  93. }
  94. }
  95. }
  96. $(function() {
  97. $(window).resize(function() {
  98. $("#front-quality-text").text("Magnification: " + ($("#img-front").width() / parseInt($("#front-count").text())).toFixed(2).toString() + "%");
  99. $("#top-quality-text").text("Magnification: " + ($("#img-top").height() / parseInt($("#top-count").text())).toFixed(2).toString() + "%");
  100. $("#left-quality-text").text("Magnification: " + ($("#placeholder-left").height() / parseInt($("#left-count").text())).toFixed(2).toString() + "%");
  101. });
  102. $( "#slider-left" ).slider({
  103. range: "max",
  104. min: 1,
  105. max: parseInt($("#left-count").text()),
  106. value: 1,
  107. slide: function( event, ui ) {
  108. //console.log(ui.value);
  109. var name = $( "select option:selected" ).text();
  110. var id = $( "select option:selected" ).val();
  111. $("#left-text").text(ui.value);
  112. // update image src
  113. // data-zoom-image
  114. //$("#placeholder-left").attr("data-zoom-image", "img?id="+id+"&name="+name+"&type=left-resized&counter="+(ui.value-1));
  115. var imageUrl = "img?id="+id+"&name="+name+"&type=left&counter="+(ui.value-1);
  116. $("#placeholder-left-zoomContainer > .zoomWindowContainer > div").css('background-image', 'url("' + imageUrl + '")');
  117. //$("#placeholder-left-zoomContainer > .zoomLens").css('background-image', 'url("' + imageUrl + '")');
  118. if (document.webkitIsFullScreen || document.mozFullScreen || document.msFullscreenElement !== null) {
  119. if (!document.fullscreenElement && !document.mozFullScreenElement &&
  120. !document.webkitFullscreenElement && !document.msFullscreenElement) {
  121. $("#placeholder-left").attr("src", "img?id="+id+"&name="+name+"&type=left-resized&counter="+(ui.value-1));
  122. } else {
  123. $("#placeholder-left").attr("src", "img?id="+id+"&name="+name+"&type=left&counter="+(ui.value-1));
  124. }
  125. } else {
  126. $("#placeholder-left").attr("src", "img?id="+id+"&name="+name+"&type=left-resized&counter="+(ui.value-1));
  127. }
  128. }
  129. });
  130. $( "#slider-right" ).slider({
  131. range: "max",
  132. min: 1,
  133. max: parseInt($("#front-count").text()),
  134. value: 1,
  135. slide: function( event, ui ) {
  136. //console.log(ui.value);
  137. var name = $( "select option:selected" ).text();
  138. var id = $( "select option:selected" ).val();
  139. $("#front-text").text(ui.value);
  140. // update image src
  141. var imageUrl = "img?id="+id+"&name="+name+"&type=front&counter="+(ui.value-1);
  142. $("#img-front-zoomContainer > .zoomWindowContainer > div").css('background-image', 'url("' + imageUrl + '")');
  143. //$("#img-front-zoomContainer > .zoomLens").css('background-image', 'url("' + imageUrl + '")');
  144. //$("#img-front").attr("data-zoom-image", "img?id="+id+"&name="+name+"&type=left-resized&counter="+(ui.value-1));
  145. if (document.webkitIsFullScreen || document.mozFullScreen || document.msFullscreenElement !== null) {
  146. if (!document.fullscreenElement && !document.mozFullScreenElement &&
  147. !document.webkitFullscreenElement && !document.msFullscreenElement) {
  148. $("#img-front").attr("src", "img?id="+id+"&name="+name+"&type=front-resized&counter="+(ui.value-1));
  149. } else {
  150. $("#img-front").attr("src", "img?id="+id+"&name="+name+"&type=front&counter="+(ui.value-1));
  151. }
  152. } else {
  153. $("#img-front").attr("src", "img?id="+id+"&name="+name+"&type=front-resized&counter="+(ui.value-1));
  154. }
  155. }
  156. });
  157. $( "#slider-center" ).slider({
  158. range: "max",
  159. min: 1,
  160. max: parseInt($("#top-count").text()),
  161. value: 1,
  162. slide: function( event, ui ) {
  163. //console.log(ui.value);
  164. var name = $( "select option:selected" ).text();
  165. var id = $( "select option:selected" ).val();
  166. $("#top-text").text(ui.value);
  167. // update image src
  168. var imageUrl = "img?id="+id+"&name="+name+"&type=top&counter="+(ui.value-1);
  169. $("#img-top-zoomContainer > .zoomWindowContainer > div").css('background-image', 'url("' + imageUrl + '")');
  170. //$("#img-top-zoomContainer > .zoomLens").css('background-image', 'url("' + imageUrl + '")');
  171. if (document.webkitIsFullScreen || document.mozFullScreen || document.msFullscreenElement !== null) {
  172. if (!document.fullscreenElement && !document.mozFullScreenElement &&
  173. !document.webkitFullscreenElement && !document.msFullscreenElement) {
  174. $("#img-top").attr("src", "img?id="+id+"&name="+name+"&type=top-resized&counter="+(ui.value-1));
  175. } else {
  176. $("#img-top").attr("src", "img?id="+id+"&name="+name+"&type=top&counter="+(ui.value-1));
  177. }
  178. } else {
  179. $("#img-top").attr("src", "img?id="+id+"&name="+name+"&type=top-resized&counter="+(ui.value-1));
  180. }
  181. }
  182. });
  183. $( "#download" ).click(function(e) {
  184. var did = $( "select option:selected" ).text();
  185. e.preventDefault(); //stop the browser from following
  186. window.location.href = 'download?did=' + did;
  187. });
  188. $('.target').change(function() {
  189. var name = $(this).find("option:selected").text();
  190. var index = $(this).find("option:selected").val();
  191. $.ajax({
  192. url: 'update?index=' + index + '&name=' + name,
  193. type: 'GET',
  194. success: function (response) {
  195. console.log("Success.");
  196. console.log(response);
  197. $("#size").text("("+response.data_size+" GB)");
  198. var html = "<span>Description</span>";
  199. for (i = 0; i < response["desc"].length; i++) {
  200. if (response["desc"][i]["type"] == "i") {
  201. tmp = "<i>" + response["desc"][i]["text"] + "</i>";
  202. } else if (response["desc"][i]["type"] == "p") {
  203. tmp = response["desc"][i]["text"];
  204. }
  205. html += tmp;
  206. }
  207. $("#description").empty().append(html);
  208. $("#front-count-text").text(" (max: " + response.front_count + ")");
  209. $("#left-count-text").text(" (max: " + response.left_count + ")");
  210. $("#top-count-text").text(" (max: " + response.top_count + ")");
  211. $("#front-count").text(response.front_count);
  212. $("#left-count").text(response.left_count);
  213. $("#top-count").text(response.top_count);
  214. $("#slider-right").slider("option", "max" , response.front_count );
  215. $("#slider-left").slider("option", "max" , response.left_count );
  216. $("#slider-center").slider("option", "max" , response.top_count );
  217. var left_index = $( "#slider-left" ).slider( "option", "value" );
  218. var top_index = $( "#slider-center" ).slider( "option", "value" );
  219. var front_index = $( "#slider-right" ).slider( "option", "value" );
  220. // update images
  221. $("#placeholder-left").attr("src", "img?id="+index+"&name="+name+"&type=left-resized&counter="+(left_index-1));
  222. $("#img-top").attr("src", "img?id="+index+"&name="+name+"&type=top-resized&counter="+(top_index-1));
  223. $("#img-front").attr("src", "img?id="+index+"&name="+name+"&type=front-resized&counter="+(front_index-1));
  224. var imageUrlLeft = "img?id="+index+"&name="+name+"&type=left&counter="+(left_index-1);
  225. var imageUrlTop ="img?id="+index+"&name="+name+"&type=top&counter="+(top_index-1);
  226. var imageUrlFront = "img?id="+index+"&name="+name+"&type=front&counter="+(front_index-1);
  227. $("#placeholder-left-zoomContainer > .zoomWindowContainer > div").css('background-image', 'url("' + imageUrlLeft + '")');
  228. $("#img-top-zoomContainer > .zoomWindowContainer > div").css('background-image', 'url("' + imageUrlTop + '")');
  229. $("#img-front-zoomContainer > .zoomWindowContainer > div").css('background-image', 'url("' + imageUrlFront + '")');
  230. $("#front-quality-text").text("Magnification: " + ($("#img-front").width() / parseInt($("#front-count").text())).toFixed(2).toString());
  231. $("#top-quality-text").text("Magnification: " + ($("#img-top").height() / parseInt($("#top-count").text())).toFixed(2).toString());
  232. $("#left-quality-text").text("Magnification: " + ($("#placeholder-left").height() / parseInt($("#left-count").text())).toFixed(2).toString());
  233. },
  234. error: function () {
  235. console.log("Error.")
  236. }
  237. });
  238. $("#img-preview").attr("src", "img?id="+index+"&name="+name+"&type=preview&counter=0");
  239. });
  240. $("#front-left").click( function() {
  241. var index = parseInt($("#front-text").text());
  242. var name = $( "select option:selected" ).text();
  243. var id = $( "select option:selected" ).val();
  244. index -= 1;
  245. if (index < 1) {
  246. index = 1;
  247. }
  248. $("#front-text").text(index);
  249. if (document.webkitIsFullScreen || document.mozFullScreen || document.msFullscreenElement !== null) {
  250. if (!document.fullscreenElement && !document.mozFullScreenElement &&
  251. !document.webkitFullscreenElement && !document.msFullscreenElement) {
  252. $("#img-front").attr("src", "img?id="+id+"&name="+name+"&type=front-resized&counter="+index.toString());
  253. } else {
  254. $("#img-front").attr("src", "img?id="+id+"&name="+name+"&type=front&counter="+index.toString());
  255. }
  256. } else {
  257. $("#img-front").attr("src", "img?id="+id+"&name="+name+"&type=front-resized&counter="+index.toString());
  258. }
  259. });
  260. $("#front-right").click( function() {
  261. var index = parseInt($("#front-text").text());
  262. var max_count = parseInt($("#front-count").text());
  263. var name = $( "select option:selected" ).text();
  264. var id = $( "select option:selected" ).val();
  265. //console.log(index, max_count);
  266. index += 1;
  267. if (index > max_count) {
  268. index = max_count;
  269. }
  270. $("#front-text").text(index);
  271. // update image src
  272. if (document.webkitIsFullScreen || document.mozFullScreen || document.msFullscreenElement !== null) {
  273. if (!document.fullscreenElement && !document.mozFullScreenElement &&
  274. !document.webkitFullscreenElement && !document.msFullscreenElement) {
  275. $("#img-front").attr("src", "img?id="+id+"&name="+name+"&type=front-resized&counter="+index.toString());
  276. } else {
  277. $("#img-front").attr("src", "img?id="+id+"&name="+name+"&type=front&counter="+index.toString());
  278. }
  279. } else {
  280. $("#img-front").attr("src", "img?id="+id+"&name="+name+"&type=front-resized&counter="+index.toString());
  281. }
  282. });
  283. $("#top-left").click( function() {
  284. var index = parseInt($("#top-text").text());
  285. var name = $( "select option:selected" ).text();
  286. var id = $( "select option:selected" ).val();
  287. index -= 1;
  288. if (index < 1) {
  289. index = 1;
  290. }
  291. $("#top-text").text(index);
  292. if (document.webkitIsFullScreen || document.mozFullScreen || document.msFullscreenElement !== null) {
  293. if (!document.fullscreenElement && !document.mozFullScreenElement &&
  294. !document.webkitFullscreenElement && !document.msFullscreenElement) {
  295. $("#img-top").attr("src", "img?id="+id+"&name="+name+"&type=top-resized&counter="+index.toString());
  296. } else {
  297. $("#img-top").attr("src", "img?id="+id+"&name="+name+"&type=top&counter="+index.toString());
  298. }
  299. } else {
  300. $("#img-top").attr("src", "img?id="+id+"&name="+name+"&type=top-resized&counter="+index.toString());
  301. }
  302. });
  303. $("#top-right").click( function() {
  304. var index = parseInt($("#top-text").text());
  305. var max_count = parseInt($("#top-count").text());
  306. var name = $( "select option:selected" ).text();
  307. var id = $( "select option:selected" ).val();
  308. //console.log(index, max_count);
  309. index += 1;
  310. if (index > max_count) {
  311. index = max_count;
  312. }
  313. $("#top-text").text(index);
  314. // update image src
  315. if (document.webkitIsFullScreen || document.mozFullScreen || document.msFullscreenElement !== null) {
  316. if (!document.fullscreenElement && !document.mozFullScreenElement &&
  317. !document.webkitFullscreenElement && !document.msFullscreenElement) {
  318. $("#img-top").attr("src", "img?id="+id+"&name="+name+"&type=top-resized&counter="+index.toString());
  319. } else {
  320. $("#img-top").attr("src", "img?id="+id+"&name="+name+"&type=top&counter="+index.toString());
  321. }
  322. } else {
  323. $("#img-top").attr("src", "img?id="+id+"&name="+name+"&type=top-resized&counter="+index.toString());
  324. }
  325. });
  326. $("#left-left").click( function() {
  327. var index = parseInt($("#left-text").text());
  328. var name = $( "select option:selected" ).text();
  329. var id = $( "select option:selected" ).val();
  330. index -= 1;
  331. if (index < 1) {
  332. index = 1;
  333. }
  334. $("#left-text").text(index);
  335. if (document.webkitIsFullScreen || document.mozFullScreen || document.msFullscreenElement !== null) {
  336. $("#placeholder-left").attr("src", "img?id="+id+"&name="+name+"&type=left&counter="+index.toString());
  337. } else {
  338. $("#placeholder-left").attr("src", "img?id="+id+"&name="+name+"&type=left-resized&counter="+index.toString());
  339. }
  340. if (document.webkitIsFullScreen || document.mozFullScreen || document.msFullscreenElement !== null) {
  341. if (!document.fullscreenElement && !document.mozFullScreenElement &&
  342. !document.webkitFullscreenElement && !document.msFullscreenElement) {
  343. $("#placeholder-left").attr("src", "img?id="+id+"&name="+name+"&type=left-resized&counter="+index.toString());
  344. } else {
  345. $("#placeholder-left").attr("src", "img?id="+id+"&name="+name+"&type=left&counter="+index.toString());
  346. }
  347. } else {
  348. $("#placeholder-left").attr("src", "img?id="+id+"&name="+name+"&type=left-resized&counter="+index.toString());
  349. }
  350. });
  351. $("#left-right").click( function() {
  352. var index = parseInt($("#left-text").text());
  353. var max_count = parseInt($("#left-count").text());
  354. var name = $( "select option:selected" ).text();
  355. var id = $( "select option:selected" ).val();
  356. //console.log(index, max_count);
  357. index += 1;
  358. if (index > max_count) {
  359. index = max_count;
  360. }
  361. $("#left-text").text(index);
  362. // update image src
  363. if (document.webkitIsFullScreen || document.mozFullScreen || document.msFullscreenElement !== null) {
  364. if (!document.fullscreenElement && !document.mozFullScreenElement &&
  365. !document.webkitFullscreenElement && !document.msFullscreenElement) {
  366. $("#placeholder-left").attr("src", "img?id="+id+"&name="+name+"&type=left-resized&counter="+index.toString());
  367. } else {
  368. $("#placeholder-left").attr("src", "img?id="+id+"&name="+name+"&type=left&counter="+index.toString());
  369. }
  370. } else {
  371. $("#placeholder-left").attr("src", "img?id="+id+"&name="+name+"&type=left-resized&counter="+index.toString());
  372. }
  373. });
  374. document.getElementById("img-front").addEventListener("click", function() {
  375. var container = $("#photowrapper-front");
  376. if (!document.fullscreenElement && !document.mozFullScreenElement &&
  377. !document.webkitFullscreenElement && !document.msFullscreenElement) {
  378. glob_id = this.id;
  379. glob_width = $("#photowrapper-front > img").width();
  380. glob_height = $("#photowrapper-front > img").height();
  381. glob_elem = $("#photowrapper-front")[0];
  382. }
  383. toggleFullscreen(container[0], this.id);
  384. });
  385. document.getElementById('img-top').addEventListener('click', function() {
  386. var container = $("#photowrapper-top");
  387. if (!document.fullscreenElement && !document.mozFullScreenElement &&
  388. !document.webkitFullscreenElement && !document.msFullscreenElement) {
  389. glob_id = this.id;
  390. glob_width = $("#photowrapper-top > img").width();
  391. glob_height = $("#photowrapper-top > img").height();
  392. glob_elem = $("#photowrapper-top")[0];
  393. }
  394. toggleFullscreen(container[0], this.id);
  395. });
  396. document.getElementById('placeholder-left').addEventListener('click', function() {
  397. var container = $("#photowrapper-left");
  398. if (!document.fullscreenElement && !document.mozFullScreenElement &&
  399. !document.webkitFullscreenElement && !document.msFullscreenElement) {
  400. glob_id = this.id;
  401. glob_width = $("#photowrapper-left > img").width();
  402. glob_height = $("#photowrapper-left > img").height();
  403. glob_elem = $("#photowrapper-left")[0];
  404. }
  405. toggleFullscreen(container[0], this.id);
  406. });
  407. $("#img-top").ezPlus({
  408. zoomWindowPosition: 1,
  409. scrollZoom: true,
  410. zoomLevel: 0.1,
  411. minZoomLevel: 0.1,
  412. zoomWindowWidth: 300,
  413. zoomWindowHeight: 300
  414. });
  415. $("#placeholder-left").ezPlus({
  416. zoomWindowPosition: 9,
  417. scrollZoom: true,
  418. zoomLevel: 0.1,
  419. minZoomLevel: 0.1,
  420. zoomWindowWidth: 300,
  421. zoomWindowHeight: 300
  422. });
  423. $("#img-front").ezPlus({
  424. zoomWindowPosition: 11,
  425. scrollZoom: true,
  426. zoomLevel: 0.1,
  427. minZoomLevel: 0.1,
  428. zoomWindowWidth: 300,
  429. zoomWindowHeight: 300
  430. });
  431. /*
  432. * print folder, imLeft.size, imTop.size, imFront.size
  433. * NRM-PZ Ar65771 (1174, 2929) (1173, 2929) (1173, 1174)
  434. * NRM-PZ Ar65772 (1122, 3200) (1173, 3200) (1173, 1122)
  435. * NRM-PZ Ar65794 (1118, 3113) (1133, 3113) (1133, 1118)
  436. * NRM-PZ Ar65793 (1294, 3431) (1240, 3431) (1240, 1294)
  437. * NRM-PZ Ar65720 (1223, 3311) (1267, 3311) (1267, 1223)
  438. * NRM-PZ Ar65767 (1302, 2936) (1284, 2936) (1284, 1302)
  439. */
  440. $("#front-quality-text").text("Magnification: 0.34");
  441. $("#top-quality-text").text("Magnification: 0.13");
  442. $("#left-quality-text").text("Magnification: 0.13");
  443. /*
  444. console.log("FRONT QUALITY: " + $("#img-front").width() + " / " + $("#front-count").text() );
  445. console.log("TOP QUALITY: " + $("#img-top").height() + " / " + $("#top-count").text() );
  446. console.log("LEFT QUALITY: " + $("#placeholder-left").height() + " / " + $("#left-count").text() );
  447. */
  448. });