interaction-code.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522
  1. /**
  2. * Copyright 2021, 2024 5 Mode
  3. *
  4. * This file is part of 5 Cube.
  5. *
  6. * 5 Cube is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * 5 Cube is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with 5 Cube. If not, see <https://www.gnu.org/licenses/>.
  18. *
  19. * interaction-code.js
  20. *
  21. * Interaction Code for home.php.
  22. *
  23. * @author Daniele Bonini <my25mb@aol.com>
  24. * @copyrights (c) 2021, 2024, 5 Mode
  25. */
  26. timeoutId=0;
  27. var oldtthis; // Old cube
  28. var lineOldVal = ""; // Old value for a detail line
  29. var lineNewVal = ""; // New value for a detail line
  30. var dataChanged = false;
  31. /*
  32. function zoominCube_old(tthis) {
  33. $(tthis).css("width","396px");
  34. $(tthis).css("height","477px");
  35. $(tthis).css("margin","0px");
  36. }
  37. function zoomoffCube_old(tthis) {
  38. $(tthis).css("width","130px");
  39. $(tthis).css("height","159px");
  40. $(tthis).css("margin","50px");
  41. }
  42. /*
  43. /*
  44. * Select the given cube
  45. *
  46. * @param <interfaceEl> selected cube
  47. * @returns void
  48. */
  49. function selCube(tthis) {
  50. if (password === 1) {
  51. _selCube(tthis);
  52. // Clean the old selected..
  53. $(oldtthis).css("color","#d4b0dc");
  54. $(oldtthis).css("text-decoration","none");
  55. oldtthis = tthis;
  56. // Decore the selected one..
  57. $(tthis).css("color","#bd006e");
  58. $(tthis).css("text-decoration","underline");
  59. $("#cubezvname").html(curcube.getname());
  60. // Reset the detail view
  61. $("#detailtitle").html("");
  62. $("#detaildata").html("");
  63. $("#datadetail").hide();
  64. // Update ZOOMED VIEW interface..
  65. $("#face1").html("<span id='facelet1'>" + curcube.getFace('h0') + "</span> &horbar;&horbar;&horbar;&horbar;&horbar;&xodot; ");
  66. $("#face2").html("<span id='facelet2'>" + curcube.getFace('v1') + "</span>");
  67. $("#face3").html("&xodot;&horbar;&horbar;&horbar;&horbar; <span id='facelet3'>" + curcube.getFace('h1') + "</span>");
  68. $("#face1").attr("target", curcube.getFace('h0'));
  69. $("#face2").attr("target", curcube.getFace('v1'));
  70. $("#face3").attr("target", curcube.getFace('h1'));
  71. clearTimeout(timeoutId);
  72. // Update body background..
  73. $(document.body).css("background","url('../res/bg.jpg')");
  74. $(document.body).css("background-size","cover");
  75. // Display ZOOMED VIEW interface and controls
  76. $("#cubeList").css("width", "700px");
  77. $("#cubectrls").show();
  78. $("#zoomedview").show();
  79. $("#cubelinks").show();
  80. }
  81. }
  82. /*
  83. * Turn the current cube to the left
  84. *
  85. * @returns void
  86. */
  87. function turnLeft() {
  88. curcube.turnLeft();
  89. // Update ZOOMED VIEW interface..
  90. $("#face1").html("<span id='facelet1'>" + curcube.getFace('h0') + "</span> &horbar;&horbar;&horbar;&horbar;&horbar;&xodot; ");
  91. $("#face2").html("<span id='facelet2'>" + curcube.getFace('v1') + "</span>");
  92. $("#face3").html("&xodot;&horbar;&horbar;&horbar;&horbar; <span id='facelet3'>" + curcube.getFace('h1') + "</span>");
  93. $("#face1").attr("target", curcube.getFace('h0'));
  94. $("#face2").attr("target", curcube.getFace('v1'));
  95. $("#face3").attr("target", curcube.getFace('h1'));
  96. // Display the debug info..
  97. visInfo();
  98. }
  99. /*
  100. * Turn the current cube to the right
  101. *
  102. * @returns void
  103. */
  104. function turnRight() {
  105. curcube.turnRight();
  106. // Update ZOOMED VIEW interface..
  107. $("#face1").html("<span id='facelet1'>" + curcube.getFace('h0') + "</span> &horbar;&horbar;&horbar;&horbar;&horbar;&xodot; ");
  108. $("#face2").html("<span id='facelet2'>" + curcube.getFace('v1') + "</span>");
  109. $("#face3").html("&xodot;&horbar;&horbar;&horbar;&horbar; <span id='facelet3'>" + curcube.getFace('h1') + "</span>");
  110. $("#face1").attr("target", curcube.getFace('h0'));
  111. $("#face2").attr("target", curcube.getFace('v1'));
  112. $("#face3").attr("target", curcube.getFace('h1'));
  113. // Display the debug info..
  114. visInfo();
  115. }
  116. /*
  117. * Turn the current cube to upward
  118. *
  119. * @returns void
  120. */
  121. function turnUp() {
  122. curcube.turnUp();
  123. // Update ZOOMED VIEW interface..
  124. $("#face1").html("<span id='facelet1'>" + curcube.getFace('h0') + "</span> &horbar;&horbar;&horbar;&horbar;&horbar;&xodot; ");
  125. $("#face2").html("<span id='facelet2'>" + curcube.getFace('v1') + "</span>");
  126. $("#face3").html("&xodot;&horbar;&horbar;&horbar;&horbar; <span id='facelet3'>" + curcube.getFace('h1') + "</span>");
  127. $("#face1").attr("target", curcube.getFace('h0'));
  128. $("#face2").attr("target", curcube.getFace('v1'));
  129. $("#face3").attr("target", curcube.getFace('h1'));
  130. // Display the debug info..
  131. visInfo();
  132. }
  133. /*
  134. * Turn the current cube to downward
  135. *
  136. * @returns void
  137. */
  138. function turnDown() {
  139. curcube.turnDown();
  140. // Update ZOOMED VIEW interface..
  141. $("#face1").html("<span id='facelet1'>" + curcube.getFace('h0') + "</span> &horbar;&horbar;&horbar;&horbar;&horbar;&xodot; ");
  142. $("#face2").html("<span id='facelet2'>" + curcube.getFace('v1') + "</span>");
  143. $("#face3").html("&xodot;&horbar;&horbar;&horbar;&horbar; <span id='facelet3'>" + curcube.getFace('h1') + "</span>");
  144. $("#face1").attr("target", curcube.getFace('h0'));
  145. $("#face2").attr("target", curcube.getFace('v1'));
  146. $("#face3").attr("target", curcube.getFace('h1'));
  147. // Display the debug info..
  148. visInfo();
  149. }
  150. /*
  151. * Hide the ZOOMED VIEW
  152. *
  153. * @returns void
  154. */
  155. function hideZoomedview() {
  156. // Clean the old selected..
  157. $(oldtthis).css("color","#d4b0dc");
  158. $(oldtthis).css("text-decoration","none");
  159. oldtthis = null;
  160. // Reset the detail view
  161. $("#detailtitle").html("");
  162. $("#detaildata").html("");
  163. $("#datadetail").hide();
  164. // Hide ZOOMED VIEW interface and controls
  165. $("#cubeList").css("width", "100%");
  166. $("#cubelinks").hide();
  167. $("#zoomedview").hide();
  168. $("#cubectrls").hide();
  169. // Reset body background..
  170. $(document.body).css("background","#0d0d0d");
  171. }
  172. /*
  173. * Mouse over handle for ZOOMED VIEW
  174. *
  175. * @returns void
  176. */
  177. function zoomviewOver() {
  178. clearTimeout(timeoutId);
  179. }
  180. /*
  181. * Mouse out handle for ZOOMED VIEW
  182. *
  183. * @returns void
  184. */
  185. function zoomviewOut() {
  186. timeoutId = setTimeout(hideZoomedview,1500);
  187. }
  188. /*
  189. * Display the debug info
  190. *
  191. * @returns void
  192. */
  193. function visInfo() {
  194. $("#hcube").val(curcube.gethcube());
  195. $("#vcube").val(curcube.getvcube());
  196. $("#hcur").val(curcube.gethcur());
  197. $("#vcur").val(curcube.getvcur());
  198. $("#curcube").val(curcube.getname());
  199. }
  200. /*
  201. function eachNode(rootNode, callback) {
  202. if (!callback) {
  203. const nodes = []
  204. eachNode(rootNode, function(node) {
  205. nodes.push(node.nodeName)
  206. //nodes.push(node)
  207. })
  208. return nodes
  209. }
  210. if (false === callback(rootNode)) {
  211. return false
  212. }
  213. if (rootNode.hasChildNodes()) {
  214. const nodes = rootNode.childNodes
  215. for (let i = 0, l = nodes.length; i < l; ++i) {
  216. if (false === eachNode(nodes[i], callback)) {
  217. return
  218. }
  219. }
  220. }
  221. }
  222. */
  223. /*
  224. * Get the data for the given detail / face
  225. *
  226. * @param string xmlStr, the current cube xml data
  227. * @param string detail, the requested detail
  228. * @returns string, the detail data
  229. */
  230. function getDetailData(xmlStr, detail) {
  231. var ret = "";
  232. var re;
  233. detail = detail.toLowerCase();
  234. xmlStr = xmlStr.replace('<?xml version="1.0" encoding="UTF-8"?>',"");
  235. xmlStr = xmlStr.replace('<details>',"");
  236. xmlStr = xmlStr.replace('</details>',"");
  237. xmlStr = xmlStr.replaceAll('\n',"");
  238. xmlStr = xmlStr.replaceAll(String.fromCharCode(9), "");
  239. xmlStr = xmlStr.replaceAll(String.fromCharCode(10), "");
  240. xmlStr = xmlStr.replaceAll(String.fromCharCode(13), "");
  241. xmlStr = xmlStr.replaceAll(" ", "");
  242. xmlStr = xmlStr.replaceAll(" ", "");
  243. xmlStr = escape(xmlStr);
  244. xmlStr = xmlStr.replaceAll("%0A", "");
  245. xmlStr = xmlStr.replaceAll("%20%20%20%20%20", "");
  246. xmlStr = xmlStr.replaceAll("%20%20%20%20%", "");
  247. xmlStr = xmlStr.replaceAll("%20%20%", "");
  248. //xmlStr = unescape(xmlStr);
  249. //alert(xmlStr);
  250. switch (detail) {
  251. case "address":
  252. re = new RegExp("detail%20face%3D%22address%22.+/country", "igsu");
  253. break;
  254. case "contacts":
  255. re = new RegExp("detail%20face%3D%22contacts%22.+/cell", "igsu");
  256. break;
  257. case "other info":
  258. re = new RegExp("detail%20face%3D%22other%20info%22.+/description", "igsu");
  259. break;
  260. case "menu":
  261. re = new RegExp("detail%20face%3D%22menu%22.+/menu3", "igsu");
  262. break;
  263. case "pictures":
  264. re = new RegExp("detail%20face%3D%22pictures%22.+/pic5", "igsu");
  265. break;
  266. case "password":
  267. re = new RegExp("detail%20face%3D%22password%22.+/password", "igsu");
  268. break;
  269. }
  270. s = re.exec(xmlStr);
  271. if (!s || s.length===0) {
  272. ret = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Error! #1";
  273. return ret;
  274. }
  275. xmlStr = s[0];
  276. xmlStr = "<"+xmlStr+"></detail>";
  277. xmlStr = unescape(xmlStr);
  278. //alert(xmlStr);
  279. const parser = new DOMParser();
  280. const doc = parser.parseFromString(xmlStr, "text/xml");
  281. x = doc.getElementsByTagName("detail");
  282. if (x.length===0) {
  283. ret = "Error! #2";
  284. return ret;
  285. }
  286. ret += "<div style='padding:10px'>";
  287. for (i = 0; i < x[0].childNodes.length; i++) {
  288. if (x[0].childNodes[i].nodeType === 1) {
  289. if (x[0].childNodes[i].getAttributeNode("type")) {
  290. mytype = x[0].childNodes[i].getAttributeNode("type");
  291. if (mytype.value==="pic") {
  292. ret += "<div style='float:left;width:35%;text-align:right;height:32px;vertical-align:middle;padding-top:3px;font-weight:900;white-space:nowrap;'>" + x[0].childNodes[i].nodeName + "&nbsp;&nbsp;</div><div style='float:right;width:65%;height:32px;'>" + "<input type='text' id='cube-detail-" + x[0].childNodes[i].nodeName + "' value='" + x[0].childNodes[i].textContent + "' placeholder='https://' onkeyup='storePicData(this)'></div>";
  293. } else {
  294. ret += "<div style='float:left;width:35%;text-align:right;height:32px;vertical-align:middle;padding-top:3px;font-weight:900;white-space:nowrap;'>" + x[0].childNodes[i].nodeName + "&nbsp;&nbsp;</div><div style='float:right;width:65%;height:32px;'>" + "<input type='text' id='cube-detail-" + x[0].childNodes[i].nodeName + "' value='" + x[0].childNodes[i].textContent + "' onkeyup='storeData(this)'></div>";
  295. }
  296. } else {
  297. if (x[0].childNodes[i].nodeName === "business-type") {
  298. ret += "<div style='float:left;width:35%;text-align:right;height:32px;vertical-align:middle;padding-top:3px;font-weight:900;white-space:nowrap;'>" + x[0].childNodes[i].nodeName + "&nbsp;&nbsp;</div><div style='float:right;width:65%;height:32px;'>" + "<input type='text' id='cube-detail-" + x[0].childNodes[i].nodeName + "' value='" + x[0].childNodes[i].textContent + "' onkeyup='storeData(this)' style='color:green' readonly></div>";
  299. } else if (x[0].childNodes[i].nodeName === "guid") {
  300. ret += "<div style='float:left;width:35%;text-align:right;height:32px;vertical-align:middle;padding-top:3px;font-weight:900;white-space:nowrap;'>" + x[0].childNodes[i].nodeName + "&nbsp;&nbsp;</div><div style='float:right;width:65%;height:32px;'>" + "<input type='text' id='cube-detail-" + x[0].childNodes[i].nodeName + "' value='" + x[0].childNodes[i].textContent + "' onkeyup='storeData(this)' style='color:green' readonly></div>";
  301. } else if (x[0].childNodes[i].nodeName === "password") {
  302. if (password===1) {
  303. ret += "<div style='float:left;width:35%;text-align:right;height:32px;vertical-align:middle;padding-top:3px;font-weight:900;white-space:nowrap;'>" + x[0].childNodes[i].nodeName + "&nbsp;&nbsp;</div><div style='float:right;width:65%;height:32px;'>" + "<input type='text' id='cube-detail-" + x[0].childNodes[i].nodeName + "' value='" + x[0].childNodes[i].textContent + "' onkeyup='storeData(this)' style='color:green' readonly></div>";
  304. }
  305. } else if (x[0].childNodes[i].nodeName === "city-zip-prov") {
  306. ret += "<div style='float:left;width:35%;text-align:right;height:32px;vertical-align:middle;padding-top:3px;font-weight:900;white-space:nowrap;'>" + x[0].childNodes[i].nodeName + "&nbsp;&nbsp;</div><div style='float:right;width:65%;height:32px;'>" + "<input type='text' id='cube-detail-" + x[0].childNodes[i].nodeName + "' value='" + x[0].childNodes[i].textContent + "' onkeyup='storeData(this)' style='color:green' readonly></div>";
  307. } else if (x[0].childNodes[i].nodeName === "country") {
  308. ret += "<div style='float:left;width:35%;text-align:right;height:32px;vertical-align:middle;padding-top:3px;font-weight:900;white-space:nowrap;'>" + x[0].childNodes[i].nodeName + "&nbsp;&nbsp;</div><div style='float:right;width:65%;height:32px;'>" + "<input type='text' id='cube-detail-" + x[0].childNodes[i].nodeName + "' value='" + x[0].childNodes[i].textContent + "' onkeyup='storeData(this)' style='color:green' readonly></div>";
  309. } else {
  310. ret += "<div style='float:left;width:35%;text-align:right;height:32px;vertical-align:middle;padding-top:3px;font-weight:900;white-space:nowrap;'>" + x[0].childNodes[i].nodeName + "&nbsp;&nbsp;</div><div style='float:right;width:65%;height:32px;'>" + "<input type='text' id='cube-detail-" + x[0].childNodes[i].nodeName + "' value='" + x[0].childNodes[i].textContent + "' onkeyup='storeData(this)'></div>";
  311. }
  312. }
  313. }
  314. }
  315. if ((detail==="pictures") || (detail==="menu")) {
  316. ret += "<div style='padding-left:80px;clear:both;'><br>you can use eg. Goolge Drive or Microsoft OneDrive to host your pictures.</div>"
  317. }
  318. ret += "</div>";
  319. return ret;
  320. }
  321. /*
  322. * Store the old data of the text control
  323. *
  324. * @param {InterfaceEl} tthis, the text control under editing
  325. * @returns void
  326. */
  327. /*function storeOldData(tthis) {
  328. //alert("keypress");
  329. lineOldVal = $(tthis).val();
  330. }*/
  331. /*
  332. * Store in the cube object the new data of the text control
  333. *
  334. * @param {InterfaceEl} tthis, the text control under editing
  335. * @returns void
  336. */
  337. function storeData(tthis) {
  338. //alert("keyup");
  339. lineNewVal = $(tthis).val();
  340. //alert(lineNewVal);
  341. nodeName = tthis.id;
  342. nodeName = nodeName.replace("cube-detail-","");
  343. //alert(nodeName);
  344. xmlStr = curcube.getxml();
  345. //$("#log").html($("#log").html() + "old=" + "/(\<" + nodeName + "\>).*(\<\/" + nodeName + "\>)/gs" + "\n");
  346. //$("#log").html($("#log").html() + "new=" + lineNewVal + "\n");
  347. //alert("<" + nodeName + ">" + lineNewVal + "</" + nodeName + ">");
  348. //re = "/(\<" + nodeName + "\>).*(\<\/" + nodeName + "\>)/gs";
  349. switch (nodeName) {
  350. case "name":
  351. re = /(\<name>).*(\<\/name>)/gs;
  352. break;
  353. case "address-line1":
  354. re = /(\<address-line1>).*(\<\/address-line1>)/gs;
  355. break;
  356. case "address-line2":
  357. re = /(\<address-line2>).*(\<\/address-line2>)/gs;
  358. break;
  359. case "address-line3":
  360. re = /(\<address-line3>).*(\<\/address-line3>)/gs;
  361. break;
  362. case "city-zip-prov":
  363. re = /(\<city-zip-prov>).*(\<\/city-zip-prov>)/gs;
  364. break;
  365. case "country":
  366. re = /(\<country>).*(\<\/country>)/gs;
  367. break;
  368. case "tel":
  369. re = /(\<tel>).*(\<\/tel>)/gs;
  370. break;
  371. case "fax":
  372. re = /(\<fax>).*(\<\/fax>)/gs;
  373. break;
  374. case "cell":
  375. re = /(\<cell>).*(\<\/cell>)/gs;
  376. break;
  377. case "description":
  378. re = /(\<description>).*(\<\/description>)/gs;
  379. break;
  380. }
  381. xmlStr = xmlStr.replace(re, "$1" + lineNewVal + "$2");
  382. //xmlStr = xmlStr.replace("<" + nodeName + ">" + lineOldVal + "</" + nodeName + ">", "<" + nodeName + ">" + lineNewVal + "</" + nodeName + ">");
  383. //alert(xmlStr);
  384. curcube.xml = xmlStr;
  385. dataChanged = true;
  386. }
  387. /*
  388. * Store in the cube object the new pic data
  389. *
  390. * @param {InterfaceEl} tthis, the text control under editing
  391. * @returns void
  392. */
  393. function storePicData(tthis) {
  394. //alert("keyup");
  395. lineNewVal = $(tthis).val();
  396. nodeName = tthis.id;
  397. nodeName = nodeName.replace("cube-detail-","");
  398. //alert(nodeName);
  399. xmlStr = curcube.getxml();
  400. switch (nodeName) {
  401. case "menu1":
  402. re = /(\<menu1\stype\=\"pic\">).*(\<\/menu1>)/gs;
  403. break;
  404. case "menu2":
  405. re = /(\<menu2\stype\=\"pic\">).*(\<\/menu2>)/gs;
  406. break;
  407. case "menu3":
  408. re = /(\<menu3\stype\=\"pic\">).*(\<\/menu3>)/gs;
  409. break;
  410. case "pic1":
  411. re = /(\<pic1\stype\=\"pic\">).*(\<\/pic1>)/gs;
  412. break;
  413. case "pic2":
  414. re = /(\<pic2\stype\=\"pic\">).*(\<\/pic2>)/gs;
  415. break;
  416. case "pic3":
  417. re = /(\<pic3\stype\=\"pic\">).*(\<\/pic3>)/gs;
  418. break;
  419. case "pic4":
  420. re = /(\<pic4\stype\=\"pic\">).*(\<\/pic4>)/gs;
  421. break;
  422. case "pic5":
  423. re = /(\<pic5\stype\=\"pic\">).*(\<\/pic5>)/gs;
  424. break;
  425. }
  426. xmlStr = xmlStr.replace(re, "$1" + lineNewVal + "$2")
  427. //xmlStr = xmlStr.replace("<" + nodeName + " type=\"pic\">" + lineOldVal + "</" + nodeName + ">", "<" + nodeName + " type=\"pic\">" + lineNewVal + "</" + nodeName + ">");
  428. //alert(xmlStr);
  429. curcube.xml = xmlStr;
  430. dataChanged = true;
  431. }
  432. function _saveData() {
  433. if (dataChanged) {
  434. curcube.savedata();
  435. //saveData();
  436. dataChanged = false;
  437. }
  438. }
  439. setInterval("_saveData()", 1500);
  440. /*
  441. * Display the given data detail
  442. *
  443. * @param <interfaceEl> selected cube
  444. * @returns void
  445. */
  446. function openDetail(tthis) {
  447. myhtml = getDetailData(curcube.getxml(), $(tthis).attr("target"));
  448. $("#detailtitle").html("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + $(tthis).attr("target") + ":");
  449. $("#detaildata").html(myhtml);
  450. $("#datadetail").show();
  451. //alert(curcube.getxml());
  452. }