squeejs.js 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663
  1. /**
  2. * Copyright (c) 2021, 2024, 5 Mode and other contributors
  3. * Released under the MIT license
  4. *
  5. * This file is part of Squeejs.
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
  8. * and associated documentation files (the "Software"), to deal in the Software
  9. * without restriction, including without limitation the rights to use, copy, modify, merge, publish,
  10. * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
  11. * Software is furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in all copies or
  14. * substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  17. * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  18. * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  19. * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  20. * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  21. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22. *
  23. * squeejs.js
  24. *
  25. * Squeejs production release.
  26. *
  27. * @version 1.0.9
  28. * @author Daniele Bonini <my25mb@aol.com>
  29. * @copyrights (c) 2016, 2024, 5 Mode
  30. * @license https://opensource.org/licenses/MIT
  31. */
  32. function SqueeJS() {
  33. const SQJS_GEOURL = "https://ss.squeejs.com/";
  34. // Highlight
  35. this.highlightOriTop=[];
  36. this.highlightOriLeft=[];
  37. this.highlightOriHeight=[];
  38. this.highlightOriWidth=[];
  39. this.highlightOriFontSize=[];
  40. this.highlightOriBorder=[];
  41. this.highlightOriPosition=[];
  42. this.highlightDiv = myhighlightDiv;
  43. this.unlightDiv = myunlightDiv;
  44. this.highlightInput = myhighlightInput;
  45. this.unlightInput = myunlightInput;
  46. this.highlightTextArea = myhighlightTextArea;
  47. this.unlightTextArea = myunlightTextArea;
  48. // Splash
  49. this.splashMainContainerId = "";
  50. this.splashMainContainerOriHeight = 0;
  51. this.splashTitle = "";
  52. this.splashLogoURI = "";
  53. this.splashBG = "";
  54. this.splashTimeout = 6000;
  55. this.createSplash = mycreateSplash;
  56. this.splashStartApp = mySplashStartApp;
  57. this.initAppWithSplash = myinitAppWithSplash;
  58. this.initAppWithoutSplash = myinitAppWithoutSplash;
  59. // Work In Progress
  60. this.wipMainContainerId = "";
  61. this.wipMainContainerOriHeight = 0;
  62. this.wipBG = "";
  63. this.wipStartApp = myWIPStartApp;
  64. this.initAppWithWIP = myinitAppWithWIP;
  65. this.initAppWithoutWIP = myinitAppWithoutWIP;
  66. //Banners
  67. this.bannerIndex = 0;
  68. this.bannerIMG = [];
  69. this.bannerURL = [];
  70. this.createBanner = mycreateBanner;
  71. this.closeBanner = mycloseBanner;
  72. //Footer
  73. this.footerHTML = "";
  74. this.footerBG = "";
  75. this.createFooter = mycreateFooter;
  76. //AppMenu
  77. this.appmenuContentContId = "";
  78. this.appmenuVisible = false;
  79. this.appmenuOnIco = false;
  80. this.appmenuPopUp = myappmenuPopUp;
  81. this.appmenuHide = myappmenuHide;
  82. this.appmenuCheckFlagIco = myappmenuCheckFlagIco;
  83. this.appmenuUnCheckFlagIco = myappmenuUnCheckFlagIco;
  84. this.appmenuBodyOnClick = myappmenuBodyOnClick;
  85. this.createAppMenu = mycreateAppMenu;
  86. //GeoLocation
  87. this.geoLocation = "";
  88. this.retrieveGeoLocation = myretrieveGeoLocation;
  89. this.hideElByGeoLocation = myhideElByGeoLocation;
  90. this.showElByGeoLocation = myshowElByGeoLocation;
  91. //UserTranslation
  92. this.usertransContentContId = "";
  93. this.usertransVisible = false;
  94. this.usertransOnIco = false;
  95. this.tranSource = [];
  96. this.tranDest = [];
  97. this.usertransPopUp=myusertransPopUp;
  98. this.usertransHide=myusertransHide;
  99. this.usertransCheckFlagIco=myusertransCheckFlagIco;
  100. this.usertransUnCheckFlagIco=myusertransUnCheckFlagIco;
  101. this.usertransBodyOnClick=myusertransBodyOnClick;
  102. this.getTranslitarates = mygetTranslitarates;
  103. this.translate = mytranslate;
  104. this.createUserTrans = mycreateUserTrans;
  105. //Sideabar
  106. this.sidebarContentContId = "";
  107. this.sidebarVisible = false;
  108. this.sidebarClose = mysidebarClose;
  109. this.sidebarShow = mysidebarShow;
  110. this.createSidebar = mycreateSidebar;
  111. /**
  112. * gfSQJZDocWidth
  113. *
  114. * Get the width of the whole document
  115. *
  116. * @returns {int} the document width
  117. *
  118. * This function is part of SqueeJS.
  119. */
  120. function gfSQJZDocWidth() {
  121. var D = document;
  122. var scrollMaxX;
  123. if (window.scrollMaxX) {
  124. scrollMaxX = window.scrollMaxX;
  125. } else {
  126. scrollMaxX = D.documentElement.scrollWidth;
  127. }
  128. return Math.max(
  129. D.body.scrollWidth, scrollMaxX,
  130. D.body.offsetWidth, D.documentElement.offsetWidth,
  131. D.body.clientWidth, D.documentElement.clientWidth
  132. );
  133. }
  134. /**
  135. * gfSQJZDocHeight
  136. *
  137. * Get the height of the whole document
  138. *
  139. * @returns {int} the document height
  140. *
  141. * This function is part of SqueeJS.
  142. */
  143. function gfSQJZDocHeight() {
  144. var D = document;
  145. var scrollMaxY;
  146. if (window.scrollMaxY) {
  147. scrollMaxY = window.scrollMaxY;
  148. } else {
  149. scrollMaxY = D.documentElement.scrollHeight;
  150. }
  151. var height = Math.max(
  152. D.body.scrollHeight, scrollMaxY,
  153. D.body.offsetHeight, D.documentElement.offsetHeight,
  154. D.body.clientHeight, D.documentElement.clientHeight
  155. );
  156. return height;
  157. }
  158. /**
  159. * gfSQJZLoad
  160. *
  161. * Load the content of <url> in the given DIV element
  162. *
  163. * @param {string} id, the DIV id to fill
  164. * @param {string} url, the url of the content to load
  165. * @returns {void}
  166. *
  167. * This function is part of SqueeJS.
  168. */
  169. function gfSQJZLoad(id, url) {
  170. try {
  171. var xhttp = new XMLHttpRequest();
  172. var xmluri = url;
  173. //alert(xmluri);
  174. xhttp.open("GET", xmluri, false);
  175. xhttp.send();
  176. document.getElementById(id).innerHTML = xhttp.responseText;
  177. } catch(e) {
  178. throw new Error("404 or CORS error: check the resource availability and Access-Control-Allow-Origin of your site.");
  179. }
  180. }
  181. /**
  182. * gfSQJZrnd
  183. *
  184. * Generate a random number between the given limits
  185. *
  186. * @param {int} min, the starting limit
  187. * @param {int} max, the max limit
  188. * @returns {int} the generated random value
  189. *
  190. * This function is part of SqueeJS.
  191. */
  192. function gfSQJZrnd(min, max) {
  193. min = Math.ceil(min);
  194. max = Math.floor(max);
  195. return Math.floor(Math.random() * (max - min +1)) + min;
  196. }
  197. /**
  198. *
  199. * Highlight
  200. *
  201. */
  202. /**
  203. * highlightDiv
  204. *
  205. * Highlight the current DIV element
  206. *
  207. * Context:
  208. * - call this function in the onmouseenter event
  209. *
  210. * @param {Element} tthis, the current DIV element (this on the function call)
  211. * @returns {void}
  212. *
  213. * This function is part of SqueeJS.
  214. */
  215. function myhighlightDiv(tthis) {
  216. if (tthis.tagName !== "DIV") {
  217. return;
  218. }
  219. // --- saving original data
  220. myR = tthis.getBoundingClientRect();
  221. highlightIndex = tthis.getAttribute("highlightIndex");
  222. this.highlightOriTop[highlightIndex] = parseInt(myR.top);
  223. this.highlightOriHeight[highlightIndex] = parseInt(myR.height);
  224. this.highlightOriWidth[highlightIndex] = parseInt(myR.width);
  225. this.highlightOriFontSize[highlightIndex] = tthis.style.fontSize;
  226. this.highlightOriBorder[highlightIndex] = tthis.style.border;
  227. this.highlightOriPosition[highlightIndex] = tthis.style.position;
  228. // ---
  229. tthis.style.position = "absolute";
  230. tthis.style.height = "480px";
  231. tthis.style.width = "650px";
  232. tthis.style.border = "3px dashed darkcyan";
  233. tthis.style.fontSize = "25px";
  234. //document.getElementById("debug1").value=tthis.id+"-100px-"+tthis.tabIndex+" Enter";
  235. }
  236. /**
  237. * unlightDiv
  238. *
  239. * Unlight the current DIV element
  240. *
  241. * Context:
  242. * - call this function in the onmouseleave event
  243. *
  244. * @param {Element} tthis, the current DIV element (this on the function call)
  245. * @returns {void}
  246. *
  247. * This function is part of SqueeJS.
  248. */
  249. function myunlightDiv(tthis) {
  250. if (tthis.tagName !== "DIV") {
  251. return;
  252. }
  253. // --- restoring original data
  254. highlightIndex = tthis.getAttribute("highlightIndex");
  255. if (this.highlightOriTop[highlightIndex]===null) {
  256. return;
  257. }
  258. tthis.style.fontSize = this.highlightOriFontSize[highlightIndex];
  259. tthis.style.border = this.highlightOriBorder[highlightIndex];
  260. tthis.style.width = (this.highlightOriWidth[highlightIndex]-6)+"px";
  261. tthis.style.height = (this.highlightOriHeight[highlightIndex]-6)+"px";
  262. tthis.style.position = this.highlightOriPosition[highlightIndex];
  263. // ---
  264. //document.getElementById("debug1").value=tthis.id+"-30-"+tthis.tabIndex+"Leave";
  265. }
  266. /**
  267. * highlightInput
  268. *
  269. * Highlight the current INPUT element
  270. *
  271. * Context:
  272. * - call this function in the onmouseenter event
  273. *
  274. * @param {Element} tthis, the current INPUT element (this on the function call)
  275. * @returns {void}
  276. *
  277. * This function is part of SqueeJS.
  278. */
  279. function myhighlightInput(tthis) {
  280. if (tthis.tagName !== "INPUT") {
  281. return;
  282. }
  283. // --- saving original data
  284. myR = tthis.getBoundingClientRect();
  285. highlightIndex = tthis.getAttribute("highlightIndex");
  286. this.highlightOriTop[highlightIndex] = parseInt(myR.top);
  287. this.highlightOriHeight[highlightIndex] = parseInt(myR.height);
  288. this.highlightOriWidth[highlightIndex] = parseInt(myR.width);
  289. this.highlightOriFontSize[highlightIndex] = tthis.style.fontSize;
  290. this.highlightOriBorder[highlightIndex] = tthis.style.border;
  291. this.highlightOriPosition[highlightIndex] = tthis.style.position;
  292. // ---
  293. tthis.style.position = "absolute";
  294. tthis.style.height = "40px";
  295. tthis.style.width = "400px";
  296. tthis.style.border = "3px solid lightblue";
  297. tthis.style.fontSize = "25px";
  298. //document.getElementById("debug1").value=tthis.id+"-100px-"+tthis.tabIndex+" Enter";
  299. }
  300. /**
  301. * unlightInput
  302. *
  303. * Unlight the current INPUT element
  304. *
  305. * Context:
  306. * - call this function in the onmouseleave event
  307. *
  308. * @param {Element} tthis, the current INPUT element (this on the function call)
  309. * @returns {void}
  310. *
  311. * This function is part of SqueeJS.
  312. */
  313. function myunlightInput(tthis) {
  314. if (tthis.tagName !== "INPUT") {
  315. return;
  316. }
  317. // --- restoring original data
  318. highlightIndex = tthis.getAttribute("highlightIndex");
  319. if (this.highlightOriTop[highlightIndex]===null) {
  320. return;
  321. }
  322. tthis.style.fontSize = this.highlightOriFontSize[highlightIndex];
  323. tthis.style.border = this.highlightOriBorder[highlightIndex];
  324. tthis.style.width = (this.highlightOriWidth[highlightIndex]-6)+"px";
  325. tthis.style.height = (this.highlightOriHeight[highlightIndex]-6)+"px";
  326. tthis.style.position = this.highlightOriPosition[highlightIndex];
  327. // ---
  328. //document.getElementById("debug1").value=tthis.id+"-30-"+tthis.tabIndex+"Leave";
  329. }
  330. /**
  331. * highlightTextArea
  332. *
  333. * Highlight the current TEXTAREA element
  334. *
  335. * Context:
  336. * - call this function in the onmouseenter event
  337. *
  338. * @param {Element} tthis, the current TEXTAREA element (this on the function call)
  339. * @returns {void}
  340. *
  341. * This function is part of SqueeJS.
  342. */
  343. function myhighlightTextArea(tthis) {
  344. if (tthis.tagName !== "TEXTAREA") {
  345. return;
  346. }
  347. // --- saving original data
  348. myR = tthis.getBoundingClientRect();
  349. highlightIndex = tthis.getAttribute("highlightIndex");
  350. this.highlightOriTop[highlightIndex] = parseInt(myR.top);
  351. this.highlightOriHeight[highlightIndex] = parseInt(myR.height);
  352. this.highlightOriWidth[highlightIndex] = parseInt(myR.width);
  353. this.highlightOriFontSize[highlightIndex] = tthis.style.fontSize;
  354. this.highlightOriBorder[highlightIndex] = tthis.style.border;
  355. this.highlightOriPosition[highlightIndex] = tthis.style.position;
  356. // ---
  357. tthis.style.position = "absolute";
  358. tthis.style.height = "240px";
  359. tthis.style.width = "400px";
  360. tthis.style.border = "3px solid lightblue";
  361. tthis.style.fontSize = "25px";
  362. //document.getElementById("debug1").value=tthis.id+"-100px-"+tthis.tabIndex+" Enter";
  363. }
  364. /**
  365. * unlightTextArea
  366. *
  367. * Unlight the current TEXTAREA element
  368. *
  369. * Context:
  370. * - call this function in the onmouseleave event
  371. *
  372. * @param {Element} tthis, the current TEXTAREA element (this on the function call)
  373. * @returns {void}
  374. *
  375. * This function is part of SqueeJS.
  376. */
  377. function myunlightTextArea(tthis) {
  378. if (tthis.tagName !== "TEXTAREA") {
  379. return;
  380. }
  381. // --- restoring original data
  382. highlightIndex = tthis.getAttribute("highlightIndex");
  383. if (this.highlightOriTop[highlightIndex]===null) {
  384. return;
  385. }
  386. tthis.style.fontSize = this.highlightOriFontSize[highlightIndex];
  387. tthis.style.border = this.highlightOriBorder[highlightIndex];
  388. tthis.style.width = (this.highlightOriWidth[highlightIndex]-6)+"px";
  389. tthis.style.height = (this.highlightOriHeight[highlightIndex]-6)+"px";
  390. tthis.style.position = this.highlightOriPosition[highlightIndex];
  391. // ---
  392. //document.getElementById("debug1").value=tthis.id+"-30-"+tthis.tabIndex+"Leave";
  393. }
  394. // --- End Highlight
  395. /**
  396. *
  397. * Splash Screen
  398. */
  399. /**
  400. * createSplash
  401. *
  402. * Create the tag DIV for the splash screen
  403. *
  404. * Context:
  405. * - this function is for internal use
  406. *
  407. * @returns {void}
  408. *
  409. * This function is part of SqueeJS.
  410. */
  411. function mycreateSplash() {
  412. var D = document;
  413. w = gfSQJZDocWidth();
  414. splashLeft = parseInt((w - 265) / 2);
  415. h = gfSQJZDocHeight();
  416. title = this.splashTitle;
  417. logoURI = this.splashLogoURI;
  418. BG = this.splashBG;
  419. //alert(this.splashTitle);
  420. //alert(this.splashLogoURI);
  421. //alert(this.splashBG);
  422. splash = "";
  423. splash += "<br><br><br><br>";
  424. splash += "<div style='width:267px;margin:auto;text-align:center;'>"+title+"</div><br>";
  425. splash += "<div style='width:267px;margin:auto;'><img src='"+logoURI+"' style='width:265px;'></div>";
  426. newdiv=D.createElement("div");
  427. newdiv.id = "SQJSsplash";
  428. newdiv.style.background = BG;
  429. newdiv.style.width = w;
  430. newdiv.style.height = h;
  431. newdiv.style.textAlign = 'left';
  432. newdiv.style.fontFamily = 'Arial,Sans,Verdana';
  433. newdiv.style.fontSize = '35px';
  434. newdiv.style.fontWeight = '900';
  435. newdiv.style.paddingLeft = splashLeft+"px";
  436. newdiv.innerHTML = splash;
  437. D.body.appendChild(newdiv);
  438. }
  439. /**
  440. * SPALSHstartApp
  441. *
  442. * Start the web app just after the Splash
  443. *
  444. * Context:
  445. * - this function is for internal use
  446. *
  447. * @returns {void}
  448. *
  449. * This function is part of SqueeJS.
  450. */
  451. function mySplashStartApp() {
  452. //alert("hello");
  453. //Splash
  454. if (document.getElementById("SQJSsplash")) {
  455. document.getElementById("SQJSsplash").style.display = "none";
  456. }
  457. //Main Container
  458. document.getElementById(this.splashMainContainerId).style.height = this.splashMainContainerOriHeight;
  459. document.getElementById(this.splashMainContainerId).style.display = "inline";
  460. window.scrollTo(0,0);
  461. }
  462. /**
  463. * _SPLASHstartApp
  464. *
  465. * Set the timeout to start the web app just after the Splash
  466. *
  467. * Context:
  468. * - this function is for internal use
  469. *
  470. * @param {int} time, the interval of time to wait before to start the webapp
  471. * @returns {void}
  472. *
  473. * This function is part of SqueeJS.
  474. */
  475. //function _SPLASHstartApp(time) {
  476. // Fisnished the Intro with the Splash we load the app..
  477. // setTimeout("SPLASHstartApp()", time);
  478. //}
  479. /**
  480. * _initAppWithSplash
  481. *
  482. * Init the web app to start with the Splash
  483. *
  484. * Context:
  485. * - Call this function in the load event (ie. by a window.AddEventListener) of the webpage
  486. *
  487. * @param {string} mainContainerId, the container ID for the webpage content
  488. * @param {string} title, the title of the splash screen
  489. * @param {string} logoURI, the logo to display in the splash screen
  490. * @param {string} BG, the background for the splash screen
  491. * @param {int} timeout, the splash screen timeout
  492. * @returns {void}
  493. *
  494. * This function is part of SqueeJS.
  495. */
  496. function myinitAppWithSplash(mainContainerId, title, logoURI, BG, timeout) {
  497. this.splashMainContainerId = mainContainerId;
  498. this.splashTitle = title;
  499. this.splashLogoURI = logoURI;
  500. this.splashBG = BG;
  501. if (timeout!==null) {
  502. this.splashTimeout = timeout;
  503. }
  504. //Main Container
  505. document.getElementById(this.splashMainContainerId).style.display = "none";
  506. //Splash
  507. this.createSplash();
  508. document.getElementById("SQJSsplash").style.display = "inline";
  509. //window.scrollTo(1,1);
  510. document.body.style.height = parseInt(window.innerHeight) + "px";
  511. this.splashMainContainerOriHeight = document.getElementById(this.splashMainContainerId).style.height;
  512. document.getElementById(this.splashMainContainerId).style.height = parseInt(window.innerHeight) + "px";
  513. setTimeout("SQJS.splashStartApp()", this.splashTimeout);
  514. }
  515. /**
  516. * _initAppWithoutSplash
  517. *
  518. * Init the web app to start withOUT the Splash
  519. *
  520. * Context:
  521. * - Call this function in the load event (ie. by a window.AddEventListener) of the webpage
  522. *
  523. * @param {string} mainContainerId, the container ID for the webpage content
  524. * @returns {void}
  525. *
  526. * This function is part of SqueeJS.
  527. */
  528. function myinitAppWithoutSplash(mainContainerId) {
  529. this.splashMainContainerId = mainContainerId;
  530. //Main Container
  531. document.getElementById(this.splashMainContainerId).style.display = "inline";
  532. //Splash
  533. //document.getElementById("SQJSsplash").style.display = "none";
  534. setTimeout("SQJS.splashStartApp()", 1);
  535. }
  536. // --- End Splash Screen
  537. /**
  538. *
  539. * Work in Progress
  540. */
  541. /**
  542. * createWIP
  543. *
  544. * Create the tag DIV for the Work In Progress Banner
  545. *
  546. * Context:
  547. * - this function is for internal use
  548. *
  549. * @returns {void}
  550. *
  551. * This function is part of SqueeJS.
  552. */
  553. function _createWIP() {
  554. var D = document;
  555. w = gfSQJZDocWidth();
  556. wipLeft = parseInt((w - 450) / 2);
  557. h = gfSQJZDocHeight();
  558. bannerURI = "//squeejs.com/res/work-in-progress.png";
  559. BG = this.wipBG;
  560. wip = "";
  561. wip += "<br><br><br><br><br><br><br>";
  562. wip += "<div style='width:450px;margin:auto;'><img src='"+bannerURI+"' style='width:450px;'></div>";
  563. newdiv=D.createElement("div");
  564. newdiv.id = "SQJSWIP";
  565. newdiv.style.background = BG;
  566. newdiv.style.width = w;
  567. newdiv.style.height = h;
  568. newdiv.style.textAlign = 'left';
  569. newdiv.style.fontFamily = 'Arial,Sans,Verdana';
  570. newdiv.style.fontSize = '35px';
  571. newdiv.style.fontWeight = '900';
  572. newdiv.style.paddingLeft = wipLeft+"px";
  573. newdiv.innerHTML = wip;
  574. D.body.appendChild(newdiv);
  575. }
  576. /**
  577. * WIPstartApp
  578. *
  579. * Start the web app just after the WIP banner
  580. *
  581. * Context:
  582. * - this function is for internal use
  583. *
  584. * @returns {void}
  585. *
  586. * This function is part of SqueeJS.
  587. */
  588. function myWIPStartApp() {
  589. //Splash
  590. if (document.getElementById("SQJSWIP")) {
  591. document.getElementById("SQJSWIP").style.display = "none";
  592. }
  593. //Main Container
  594. document.getElementById(this.wipMainContainerId).style.height = this.wipMainContainerOriHeight;
  595. document.getElementById(this.wipMainContainerId).style.display = "inline";
  596. window.scrollTo(0,0);
  597. }
  598. /**
  599. * _WIPstartApp
  600. *
  601. * Set the timeout to start the web app just after the Splash
  602. *
  603. * Context:
  604. * - this function is for internal use
  605. *
  606. * @param {int} time, the interval of time to wait before to start the webapp
  607. * @returns {void}
  608. *
  609. * This function is part of SqueeJS.
  610. */
  611. //function _WIPstartApp(time) {
  612. // Fisnished the Intro with the Splash we load the app..
  613. // setTimeout("WIPstartApp()", time);
  614. //}
  615. /**
  616. * _initAppWithWIP
  617. *
  618. * Init the web app to start with the work in progress banner
  619. *
  620. * Context:
  621. * - Call this function in the load event (ie. by a window.AddEventListener) of the webpage
  622. *
  623. * @param {string} mainContainerId, the container ID for the webpage content
  624. * @param {string} BG, the background for the wip banner
  625. * @returns {void}
  626. *
  627. * This function is part of SqueeJS.
  628. */
  629. function myinitAppWithWIP(mainContainerId, BG) {
  630. this.wipMainContainerId = mainContainerId;
  631. this.wipBG = BG;
  632. //Main Container
  633. document.getElementById(this.wipMainContainerId).style.display = "none";
  634. //Banner
  635. _createWIP();
  636. document.getElementById("SQJSWIP").style.display = "inline";
  637. //window.scrollTo(1,1);
  638. document.body.style.height = parseInt(window.innerHeight) + "px";
  639. this.wipMainContainerOriHeight = document.getElementById(this.wipMainContainerId).style.height;
  640. document.getElementById(this.wipMainContainerId).style.height = parseInt(window.innerHeight) + "px";
  641. }
  642. /**
  643. * _initAppWithoutWIP
  644. *
  645. * Init the web app to start withOUT the WIP banner
  646. *
  647. * Context:
  648. * - Call this function in the load event (ie. by a window.AddEventListener) of the webpage
  649. *
  650. * @param {string} mainContainerId, the container ID for the webpage content
  651. * @returns {void}
  652. *
  653. * This function is part of SqueeJS.
  654. */
  655. function myinitAppWithoutWIP(mainContainerId) {
  656. this.wipMainContainerId = mainContainerId;
  657. //Main Container
  658. document.getElementById(this.wipMainContainerId).style.display = "inline";
  659. //Splash
  660. //document.getElementById("SQJSWIP").style.display = "none";
  661. setTimeout("SQJS.wipStartApp()", 1);
  662. }
  663. // --- Work in Progress
  664. /**
  665. *
  666. * Banner
  667. */
  668. /**
  669. * createBanner
  670. *
  671. * Create a new Banner
  672. *
  673. * Context:
  674. * - Call in the body of your webpage
  675. *
  676. * @param {string} img, the banner img (471px width)
  677. * @param {string} url, the banner target url
  678. * @param {string} align, the banner horizontal alignment [left|middle|right]
  679. * @param {string} display, the banner display [fixed|absolute|relative|none]
  680. * @param {int} minScreenWidth, min screen width to display the banner
  681. * @returns {string} the id of the resulting banner
  682. *
  683. * This function is part of SqueeJS.
  684. */
  685. function mycreateBanner(img, url, align, display, minScreenWidth) {
  686. this.bannerIndex++;
  687. this.bannerIMG[this.bannerIndex] = img;
  688. this.bannerURL[this.bannerIndex] = url;
  689. var D = document;
  690. w = gfSQJZDocWidth();
  691. switch (align) {
  692. case "middle":
  693. bannerLeft = parseInt((w - 473) / 2);
  694. break;
  695. case "left":
  696. bannerLeft = 0;
  697. break;
  698. case "right":
  699. bannerLeft = parseInt(w - 473);
  700. break;
  701. default:
  702. bannerLeft = parseInt((w - 473) / 2);
  703. break;
  704. }
  705. bbannerIMG = this.bannerIMG[this.bannerIndex];
  706. bbannerURL = this.bannerURL[this.bannerIndex];
  707. banner = "";
  708. banner += "<button type='button' class='SQJSclose-button' onclick='SQJS.closeBanner(this);'>";
  709. banner += "<span style='font-weight:900;'>&times;</span>";
  710. banner += "</button>";
  711. banner += "<a href='"+bbannerURL+"' target='_blank'><img src='"+bbannerIMG+"' style='width:471px;'></a>";
  712. newdiv=D.createElement("div");
  713. newdiv.id = "SQJSBANNER" + this.bannerIndex;
  714. //newdiv.style.width = w;
  715. //newdiv.style.height = h;
  716. newdiv.style.textAlign = 'left';
  717. //newdiv.style.fontFamily = 'Arial,Sans,Verdana';
  718. //newdiv.style.fontSize = '35px';
  719. //newdiv.style.fontWeight = '900';
  720. newdiv.style.marginLeft = bannerLeft+"px";
  721. bannerDisplay = true;
  722. switch (display) {
  723. case "fixed":
  724. newdiv.className = "SQJSbanner-fixed";
  725. newdiv.style.top = (((35 +62) * (this.bannerIndex-1))) + "px";
  726. break;
  727. case "absolute":
  728. newdiv.className = "SQJSbanner-absolute";
  729. newdiv.style.top = (((35 +62) * (this.bannerIndex-1))) + "px";
  730. break;
  731. case "relative":
  732. newdiv.className = "SQJSbanner-relative";
  733. break;
  734. case "none":
  735. bannerDisplay = false;
  736. break;
  737. }
  738. if (window.innerWidth < minScreenWidth) {
  739. bannerDisplay = false;
  740. }
  741. if (!bannerDisplay) {
  742. newdiv.style.display = "none";
  743. }
  744. newdiv.innerHTML = banner;
  745. //D.body.appendChild(newdiv);
  746. D.write(newdiv.outerHTML);
  747. return "SQJSBANNER"+this.bannerIndex;
  748. }
  749. function mycloseBanner(tthis) {
  750. tthis.parentNode.style.display = "none";
  751. }
  752. // --- Banner
  753. /**
  754. *
  755. * Footer
  756. */
  757. /**
  758. * createFooter
  759. *
  760. * Create the tag DIV for the footer
  761. *
  762. * Context:
  763. * - Call it in the body of your webpage
  764. *
  765. * @param {string} html, the html to insert as footer
  766. * @param {string} BG, the background of the footer
  767. * @param {string} align, the banner horizontal alignment [left|middle|right]
  768. * @param {string} display, the banner display [fixed|relative|none]
  769. * @returns {string} the id of the footer DIV element
  770. *
  771. * This function is part of SqueeJS.
  772. */
  773. function mycreateFooter(html, BG, align, display) {
  774. htollerance = 12;
  775. htollerance = 12;
  776. footerContHeight = 35;
  777. footerHeight = 32;
  778. footerFloat = "";
  779. this.footerHTML = html;
  780. this.BG = BG;
  781. var D = document;
  782. w = gfSQJZDocWidth();
  783. h = window.innerHeight;
  784. footerDisplay = true;
  785. footerContClassName = "";
  786. footerClassName = "";
  787. switch (display) {
  788. case "fixed":
  789. footerContClassName = "SQJSfooterCont";
  790. footerClassName = "SQJSfooter";
  791. break;
  792. case "relative":
  793. footerContClassName = "SQJSfooterCont";
  794. footerClassName = "SQJSfooter";
  795. break;
  796. case "none":
  797. footerContClassName = "SQJSfooterCont";
  798. footerClassName = "SQJSfooter";
  799. footerDisplay = false;
  800. break;
  801. default:
  802. display="relative";
  803. footerContClassName = "SQJSfooterCont";
  804. footerClassName = "SQJSfooter";
  805. break;
  806. }
  807. footer = "";
  808. footer += "<div class='"+footerContClassName+"'>&nbsp;</div>";
  809. footer += "<div class='"+footerClassName+"'>"+html+"</div> ";
  810. newdiv=D.createElement("div");
  811. newdiv.id = "SQJSfooter";
  812. newdiv.className = "footer";
  813. //newdiv.style.textAlign = 'left';
  814. newdiv.innerHTML = footer;
  815. D.body.appendChild(newdiv);
  816. document.getElementsByClassName(footerClassName)[0].style.background = BG;
  817. switch (align) {
  818. case "middle":
  819. footerLeft = parseInt((w - document.getElementsByClassName(footerClassName)[0].getBoundingClientRect().width) / 2);
  820. break;
  821. case "left":
  822. footerLeft = 0;
  823. footerFloat = "left";
  824. break;
  825. case "right":
  826. footerLeft = parseInt(w - document.getElementsByClassName(footerClassName)[0].getBoundingClientRect().width);
  827. footerFloat = "right";
  828. break;
  829. default:
  830. align="left";
  831. footerLeft = 0;
  832. footerFloat = "left";
  833. break;
  834. }
  835. document.getElementsByClassName(footerClassName)[0].style.float = footerFloat;
  836. if (display === "relative") {
  837. //document.getElementsByClassName(footerClassName)[0].style.top = "-" + footerContHeight + "px";
  838. } else if (display === "fixed") {
  839. document.getElementsByClassName("footer")[0].style.marginLeft = (footerLeft-wtollerance)+"px";
  840. document.getElementsByClassName("footer")[0].style.position = "fixed";
  841. document.getElementsByClassName("footer")[0].style.top = ""+parseInt(h - footerContHeight - htollerance) + "px";
  842. if (align === "right") {
  843. //document.getElementsByClassName("footer")[0].style.textAlign = "right";
  844. } else if (align === "middle") {
  845. //document.getElementsByClassName(footerClassName)[0].style.width = "800px";
  846. document.getElementsByClassName("footer")[0].style.textAlign = "center";
  847. }
  848. } else {
  849. newdiv.style.display = "none";
  850. }
  851. return newdiv.id;
  852. }
  853. // --- Footer
  854. /**
  855. *
  856. * AppMenu
  857. */
  858. /**
  859. * myappmenuPopUp
  860. *
  861. * Display/hide the appmenu
  862. *
  863. * Context:
  864. * - this function is for internal use
  865. *
  866. * @returns {void}
  867. *
  868. * This function is part of SqueeJS.
  869. */
  870. function myappmenuPopUp() {
  871. if (!this.appmenuVisible) {
  872. document.getElementById("SQJSappMenu").style.display = "inline";
  873. document.getElementById("SQJSappMenu").style.zIndex = "99998";
  874. document.getElementById(this.appmenuContentContId).style.zIndex = "99997";
  875. document.getElementById(this.appmenuContentContId ).style.opacity = "0.3";
  876. } else {
  877. document.getElementById("SQJSappMenu").style.display = "none";
  878. document.getElementById("SQJSappMenu").style.zIndex = "99992";
  879. document.getElementById(this.appmenuContentContId).style.zIndex = "99993";
  880. document.getElementById(this.appmenuContentContId).style.opacity = "1.0";
  881. }
  882. this.appmenuVisible=!this.appmenuVisible;
  883. }
  884. /**
  885. * myappmenuHide
  886. *
  887. * Hide the appmenu
  888. *
  889. * Context:
  890. * - this function is for internal use
  891. *
  892. * @returns {void}
  893. *
  894. * This function is part of SqueeJS.
  895. */
  896. function myappmenuHide() {
  897. document.getElementById("SQJSappMenu").style.display = "none";
  898. this.appmenuVisible=false;
  899. document.getElementById(this.appmenuContentContId).style.opacity = "1.0";
  900. }
  901. /**
  902. * myappmenuCheckFlagIco
  903. *
  904. * Check to true the menu icon flag
  905. *
  906. * Context:
  907. * - this function is for internal use
  908. *
  909. * @returns {void}
  910. *
  911. * This function is part of SqueeJS.
  912. */
  913. function myappmenuCheckFlagIco() {
  914. this.appmenuOnIco = true;
  915. }
  916. /**
  917. * myappmenuUnCheckFlagIco
  918. *
  919. * Check to false the menu icon flag
  920. *
  921. * Context:
  922. * - this function is for internal use
  923. *
  924. * @returns {void}
  925. *
  926. * This function is part of SqueeJS.
  927. */
  928. function myappmenuUnCheckFlagIco() {
  929. this.appmenuOnIco = false;
  930. }
  931. /**
  932. * myappmenuBodyOnClick
  933. *
  934. * Body click event function: if open, hide the menu
  935. *
  936. * Context:
  937. * - this function is for internal use
  938. *
  939. * @returns {void}
  940. *
  941. * This function is part of SqueeJS.
  942. */
  943. function myappmenuBodyOnClick() {
  944. if (!this.appmenuOnIco) {
  945. this.appmenuHide();
  946. }
  947. }
  948. /**
  949. * mycreateAppMenu
  950. *
  951. * Create the tag DIV of menu icon and app menu
  952. *
  953. * Context:
  954. * - Call it in the body of your webpage
  955. *
  956. * @param {string} icoURI, the URI of the menu icon
  957. * @param {string} menuURL, the URL of the menu web page
  958. * @param {string} contentContId, the container of the body content (the menu will disable it)
  959. * @param {string} top, the y coord of the menu position
  960. * @param {string} left, the x coord of the menu position
  961. * @param {string} width, the width of the menu
  962. * @param {string} height, the height of the menu
  963. * @returns {void}
  964. *
  965. * This function is part of SqueeJS.
  966. */
  967. function mycreateAppMenu(icoURI, menuURL, contentContId, top, left, width, height) {
  968. if (typeof jQuery === 'undefined') {
  969. throw new Error('This SqueeJS\'s function requires jQuery');
  970. }
  971. var D = document;
  972. //w = gfSQJZDocWidth();
  973. //h = gfSQJZDocHeight();
  974. this.appmenuContentContId = contentContId
  975. menuico = "";
  976. menuico = "<img src='"+icoURI+"' style='width:48px;height:48px;' alt='app menu'>";
  977. newdiv=D.createElement("div");
  978. newdiv.id = "SQJSappMenuIco";
  979. newdiv.style.width = "48px";
  980. newdiv.style.height = "48px";
  981. newdiv.innerHTML = menuico;
  982. //D.body.appendChild(newdiv);
  983. D.write(newdiv.outerHTML);
  984. //$("#SQJSappMenuIco").on("click",function(){SQJS.appmenuPopUp();});
  985. //$("#SQJSappMenuIco").on("mouseover",function(){SQJS.appmenuCheckFlagIco();});
  986. //$("#SQJSappMenuIco").on("mouseout",function(){SQJS.appmenuUnCheckFlagIco();});
  987. document.getElementById("SQJSappMenuIco").addEventListener("click", function() {
  988. SQJS.appmenuPopUp();
  989. });
  990. document.getElementById("SQJSappMenuIco").addEventListener("mouseover", function() {
  991. SQJS.appmenuCheckFlagIco();
  992. });
  993. document.getElementById("SQJSappMenuIco").addEventListener("mouseout", function() {
  994. SQJS.appmenuUnCheckFlagIco();
  995. });
  996. menu = "";
  997. menu += "<!-- Here goes the content of the AppMenu -->";
  998. newdiv=D.createElement("div");
  999. newdiv.id = "SQJSappMenu";
  1000. newdiv.style.top = top+"px";
  1001. newdiv.style.left = left+"px";
  1002. newdiv.style.width = width+"px";
  1003. newdiv.style.height = height+"px";
  1004. newdiv.innerHTML = menu;
  1005. D.body.appendChild(newdiv);
  1006. //D.write(newdiv.outerHTML);
  1007. //$("#SQJSappMenu").on("mouseover",function(){SQJS.appmenuCheckFlagIco();});
  1008. //$("#SQJSappMenu").on("mouseout",function(){SQJS.appmenuUnCheckFlagIco();});
  1009. document.getElementById("SQJSappMenu").addEventListener("mouseover", function() {
  1010. SQJS.appmenuCheckFlagIco();
  1011. });
  1012. document.getElementById("SQJSappMenu").addEventListener("mouseout", function() {
  1013. SQJS.appmenuUnCheckFlagIco();
  1014. });
  1015. //$("#SQJSappMenu").load(menuURL+"?rrnd=" + gfSQJZrnd(50000, 99999));
  1016. gfSQJZLoad("SQJSappMenu", menuURL+"?rrnd=" + gfSQJZrnd(50000, 99999));
  1017. //$(document.body).on("click", function() {SQJS.appmenuBodyOnClick();});
  1018. document.body.addEventListener("click", function() {
  1019. SQJS.appmenuBodyOnClick();
  1020. });
  1021. }
  1022. // --- AppMenu
  1023. /**
  1024. *
  1025. * GeoLocation
  1026. */
  1027. /**
  1028. * myretrieveGeoLocation
  1029. *
  1030. * Retreive the geolocation (country name)
  1031. *
  1032. * Context:
  1033. * - this function is for internal use
  1034. *
  1035. * @returns {void}
  1036. *
  1037. * This function is part of SqueeJS.
  1038. */
  1039. function myretrieveGeoLocation() {
  1040. if (!this.geoLocation || this.geoLocation=="") {
  1041. try {
  1042. var xhttp = new XMLHttpRequest();
  1043. var xmluri = SQJS_GEOURL;
  1044. //alert(xmluri);
  1045. xhttp.open("GET", xmluri, false);
  1046. xhttp.send();
  1047. this.geoLocation = xhttp.responseText;
  1048. } catch(e) {
  1049. throw new Error("CORS error: check the resource availability and Access-Control-Allow-Origin of your site.");
  1050. }
  1051. }
  1052. }
  1053. /**
  1054. * myhideElByGeoLocation
  1055. *
  1056. * Hide the given web page Element for the specified geolocation
  1057. *
  1058. * Context:
  1059. * - Call it in the body of your webpage
  1060. *
  1061. * @param {string} id, the id of the element to hide
  1062. * @param {string} geoloc, the geolocation (country name) to hide the el for
  1063. * @returns {void}
  1064. *
  1065. * This function is part of SqueeJS.
  1066. */
  1067. function myhideElByGeoLocation(id, geoloc) {
  1068. this.retrieveGeoLocation();
  1069. //alert("debug#2"+this.geoLocation);
  1070. if (this.geoLocation) {
  1071. if (geoloc.toLowerCase() === this.geoLocation.toLowerCase()) {
  1072. document.getElementById(id).style.display="none";
  1073. }
  1074. }
  1075. }
  1076. /**
  1077. * myshowElByGeoLocation
  1078. *
  1079. * Show the given web page Element for the specified geolocation
  1080. *
  1081. * Context:
  1082. * - Call it in the body of your webpage
  1083. *
  1084. * @param {string} id, the id of the element to show
  1085. * @param {string} geoloc, the geolocation (country name) to show the el for
  1086. * @returns {void}
  1087. *
  1088. * This function is part of SqueeJS.
  1089. */
  1090. function myshowElByGeoLocation(id, geoloc) {
  1091. this.retrieveGeoLocation();
  1092. //alert("debug#3"+this.geoLocation);
  1093. if (this.geoLocation) {
  1094. if (geoloc.toLowerCase() === this.geoLocation.toLowerCase()) {
  1095. document.getElementById(id).style.display="inline";
  1096. }
  1097. }
  1098. }
  1099. // --- GeoLocation
  1100. /**
  1101. *
  1102. * UserTranslation
  1103. */
  1104. /**
  1105. * myusertransPopUp
  1106. *
  1107. * Display/hide the user trans menu
  1108. *
  1109. * Context:
  1110. * - this function is for internal use
  1111. *
  1112. * @returns {void}
  1113. *
  1114. * This function is part of SqueeJS.
  1115. */
  1116. function myusertransPopUp() {
  1117. if (!this.usertransVisible) {
  1118. document.getElementById("SQJSuserTransMenu").style.display = "inline";
  1119. document.getElementById("SQJSuserTransMenu").style.zIndex = "99998";
  1120. document.getElementById(this.usertransContentContId).style.zIndex = "99997";
  1121. document.getElementById(this.usertransContentContId ).style.opacity = "0.3";
  1122. } else {
  1123. document.getElementById("SQJSuserTransMenu").style.display = "none";
  1124. document.getElementById("SQJSuserTransMenu").style.zIndex = "99992";
  1125. document.getElementById(this.usertransContentContId).style.zIndex = "99993";
  1126. document.getElementById(this.usertransContentContId).style.opacity = "1.0";
  1127. }
  1128. this.usertransVisible=!this.usertransVisible;
  1129. }
  1130. /**
  1131. * myusertransHide
  1132. *
  1133. * Hide the client trans menu
  1134. *
  1135. * Context:
  1136. * - this function is for internal use
  1137. *
  1138. * @returns {void}
  1139. *
  1140. * This function is part of SqueeJS.
  1141. */
  1142. function myusertransHide() {
  1143. document.getElementById("SQJSuserTransMenu").style.display = "none";
  1144. this.usertransVisible=false;
  1145. document.getElementById(this.usertransContentContId).style.opacity = "1.0";
  1146. }
  1147. /**
  1148. * myusertransCheckFlagIco
  1149. *
  1150. * Check to true the menu icon flag
  1151. *
  1152. * Context:
  1153. * - this function is for internal use
  1154. *
  1155. * @returns {void}
  1156. *
  1157. * This function is part of SqueeJS.
  1158. */
  1159. function myusertransCheckFlagIco() {
  1160. this.usertransOnIco = true;
  1161. }
  1162. /**
  1163. * myusertransUnCheckFlagIco
  1164. *
  1165. * Check to false the menu icon flag
  1166. *
  1167. * Context:
  1168. * - this function is for internal use
  1169. *
  1170. * @returns {void}
  1171. *
  1172. * This function is part of SqueeJS.
  1173. */
  1174. function myusertransUnCheckFlagIco() {
  1175. this.usertransOnIco = false;
  1176. }
  1177. /**
  1178. * myusertransBodyOnClick
  1179. *
  1180. * Body click event function: if open, hide the menu
  1181. *
  1182. * Context:
  1183. * - this function is for internal use
  1184. *
  1185. * @returns {void}
  1186. *
  1187. * This function is part of SqueeJS.
  1188. */
  1189. function myusertransBodyOnClick() {
  1190. if (!this.usertransOnIco) {
  1191. this.usertransHide();
  1192. }
  1193. }
  1194. /**
  1195. * mygetTranslitarates
  1196. *
  1197. * Get the transliterates to use in the translation
  1198. *
  1199. * Context:
  1200. * - this function is for internal use
  1201. *
  1202. * @returns {void}
  1203. *
  1204. * This function is part of SqueeJS.
  1205. */
  1206. function mygetTranslitarates() {
  1207. v=document.getElementById("SQJSuserTransTB").value.trim();
  1208. if (v!=="") {
  1209. if (v.substr(0,4).toLowerCase() === "http") {
  1210. transURL = v;
  1211. try {
  1212. var xhttp = new XMLHttpRequest();
  1213. var xmluri = transURL;
  1214. //alert(xmluri);
  1215. xhttp.open("GET", xmluri, false);
  1216. xhttp.send();
  1217. xml = xhttp.responseText;
  1218. } catch(e) {
  1219. throw new Error("404 or CORS error: check the resource availability and Access-Control-Allow-Origin of your site.");
  1220. }
  1221. } else {
  1222. xml = v;
  1223. }
  1224. //cleaning
  1225. xml = xml.trim("\n");
  1226. xml = xml.trim();
  1227. xml = xml.trim("\n");
  1228. xml = xml.trim();
  1229. // parsing text
  1230. tl = xml.split("\n");
  1231. it=0;
  1232. for (t of tl) {
  1233. curt = t.split("|||");
  1234. if (curt[0] && curt[0]!=="") {
  1235. this.tranSource[it] = curt[0];
  1236. this.tranDest[it] = curt[1];
  1237. }
  1238. it++;
  1239. }
  1240. }
  1241. }
  1242. /**
  1243. * mytranslate
  1244. *
  1245. * Make the client translation of the current web page
  1246. *
  1247. * Context:
  1248. * - this function is for internal use
  1249. *
  1250. * @returns {void}
  1251. *
  1252. * This function is part of SqueeJS.
  1253. */
  1254. function mytranslate() {
  1255. this.getTranslitarates();
  1256. it=0;
  1257. for (ts of this.tranSource) {
  1258. nl = document.getElementsByTagName("H1");
  1259. for (n of nl) {
  1260. n.innerHTML = n.innerHTML.replace(ts, this.tranDest[it]);
  1261. }
  1262. nl = document.getElementsByTagName("H2");
  1263. for (n of nl) {
  1264. n.innerHTML = n.innerHTML.replace(ts, this.tranDest[it]);
  1265. }
  1266. nl = document.getElementsByTagName("H3");
  1267. for (n of nl) {
  1268. n.innerHTML = n.innerHTML.replace(ts, this.tranDest[it]);
  1269. }
  1270. nl = document.getElementsByTagName("A");
  1271. for (n of nl) {
  1272. n.innerHTML = n.innerHTML.replace(ts, this.tranDest[it]);
  1273. }
  1274. nl = document.getElementsByTagName("DIV");
  1275. for (n of nl) {
  1276. n.innerHTML = n.innerHTML.replace(ts, this.tranDest[it]);
  1277. }
  1278. nl = document.getElementsByTagName("LABEL");
  1279. for (n of nl) {
  1280. n.innerHTML = n.innerHTML.replace(ts, this.tranDest[it]);
  1281. }
  1282. nl = document.getElementsByTagName("SPAN");
  1283. for (n of nl) {
  1284. n.innerHTML = n.innerHTML.replace(ts, this.tranDest[it]);
  1285. }
  1286. nl = document.getElementsByTagName("INPUT");
  1287. for (n of nl) {
  1288. n.value = n.value.replace(ts, this.tranDest[it]);
  1289. n.setAttribute("placeholder", n.getAttribute("placeholder").replace(ts, this.tranDest[it]));
  1290. }
  1291. nl = document.getElementsByTagName("TEXTAREA");
  1292. for (n of nl) {
  1293. if (n.id !== "SQJSuserTransTB") {
  1294. n.innerHTML = n.innerHTML.replace(ts, this.tranDest[it]);
  1295. }
  1296. }
  1297. it++;
  1298. }
  1299. }
  1300. /**
  1301. * mycreateUserTrans
  1302. *
  1303. * Create the tag DIV of user trans icon and user trans menu
  1304. *
  1305. * Context:
  1306. * - Call it in the body of your webpage
  1307. *
  1308. * @param {string} icoURI, the URI of the menu icon
  1309. * @param {string} contentContId, the container of the body content (the menu will disable it)
  1310. * @param {string} top, the y coord of the menu position
  1311. * @param {string} left, the x coord of the menu position
  1312. * @returns {void}
  1313. *
  1314. * This function is part of SqueeJS.
  1315. */
  1316. function mycreateUserTrans(icoURI, contentContId, top, left) {
  1317. //if (typeof jQuery === 'undefined') {
  1318. // throw new Error('This SqueeJS\'s function requires jQuery');
  1319. //}
  1320. var D = document;
  1321. //w = gfSQJZDocWidth();
  1322. //h = gfSQJZDocHeight();
  1323. this.usertransContentContId = contentContId;
  1324. menuico = "";
  1325. menuico = "<img src='"+icoURI+"' style='width:48px;height:48px;' alt='user translation'>";
  1326. newdiv=D.createElement("div");
  1327. newdiv.id = "SQJSuserTransIco";
  1328. newdiv.style.width = "48px";
  1329. newdiv.style.height = "48px";
  1330. newdiv.innerHTML = menuico;
  1331. //D.body.appendChild(newdiv);
  1332. D.write(newdiv.outerHTML);
  1333. //document.getElementById("SQJSuserTransIco").onclick = function(){SQJS.usertransPopUp();};
  1334. //document.getElementById("SQJSuserTransIco").onmouseover = function(){SQJS.usertransCheckFlagIco();};
  1335. //document.getElementById("SQJSuserTransIco").onmouseout = function(){SQJS.usertransUnCheckFlagIco();};
  1336. document.getElementById("SQJSuserTransIco").addEventListener("click", function() {
  1337. SQJS.usertransPopUp();
  1338. });
  1339. document.getElementById("SQJSuserTransIco").addEventListener("mouseover", function() {
  1340. SQJS.usertransCheckFlagIco();
  1341. });
  1342. document.getElementById("SQJSuserTransIco").addEventListener("mouseout", function() {
  1343. SQJS.usertransUnCheckFlagIco();
  1344. });
  1345. menu = "";
  1346. menu += "<span style='font-size:10px;'>text or link, use ||| to separate source from translation:</span>";
  1347. menu += "<textarea id='SQJSuserTransTB'></textarea><br>";
  1348. menu += "<button id='SQJSuserTransBUT' onclick='SQJS.translate();'><img src='//squeejs.com/res/trans.png' style='height:70px'></button><br>";
  1349. menu += "<br>";
  1350. newdiv=D.createElement("div");
  1351. newdiv.id = "SQJSuserTransMenu";
  1352. newdiv.style.top = top+"px";
  1353. newdiv.style.left = left+"px";
  1354. newdiv.style.width = "380px";
  1355. newdiv.style.height = "515px";
  1356. newdiv.innerHTML = menu;
  1357. D.body.appendChild(newdiv);
  1358. //D.write(newdiv.outerHTML);
  1359. //document.getElementById("SQJSuserTransMenu").onmouseover = function(){SQJS.usertransCheckFlagIco();};
  1360. //document.getElementById("SQJSuserTransMenu").onmouseout = function(){SQJS.usertransUnCheckFlagIco();};
  1361. document.getElementById("SQJSuserTransMenu").addEventListener("mouseover", function() {
  1362. SQJS.usertransCheckFlagIco();
  1363. });
  1364. document.getElementById("SQJSuserTransMenu").addEventListener("mouseout", function() {
  1365. SQJS.usertransUnCheckFlagIco();
  1366. });
  1367. //document.body.onclick = function(){SQJS.usertransBodyOnClick();};
  1368. document.body.addEventListener("click", function() {
  1369. SQJS.usertransBodyOnClick();
  1370. });
  1371. }
  1372. // --- UserTranslation
  1373. /**
  1374. *
  1375. * Sidebar
  1376. */
  1377. /**
  1378. * mysidebarShow
  1379. *
  1380. * Show the sidebar
  1381. *
  1382. * Context:
  1383. * - this function is for internal use
  1384. *
  1385. * @returns {void}
  1386. *
  1387. * This function is part of SqueeJS.
  1388. */
  1389. function mysidebarShow() {
  1390. if (!this.sidebarVisible) {
  1391. document.getElementById(this.sidebarContentContId).style.width = "100%";
  1392. //$("#SQJSsidebar").show("slow");
  1393. document.getElementById("SQJSsidebar").style.display = "inline";
  1394. }
  1395. this.sidebarVisible = true;
  1396. }
  1397. /**
  1398. * mysidebarClose
  1399. *
  1400. * Close the sidebar
  1401. *
  1402. * Context:
  1403. * - this function is for internal use
  1404. *
  1405. * @returns {void}
  1406. *
  1407. * This function is part of SqueeJS.
  1408. */
  1409. function mysidebarClose() {
  1410. document.getElementById("SQJSsidebar").style.display = "none";
  1411. document.getElementById(this.sidebarContentContId).style.width = "100%";
  1412. this.sidebarVisible = false;
  1413. }
  1414. /**
  1415. * mycreateSidebar
  1416. *
  1417. * Create the tag DIV of sidebar
  1418. *
  1419. * Context:
  1420. * - Call it in the body of your webpage
  1421. *
  1422. * @param {string} sidebarURL, the URI of the of the sidebar
  1423. * @param {string} contentContId, the container of the body content
  1424. * @param {string} width, the width of the sidebar
  1425. * @param {string} height, the height of the sidebar
  1426. * @returns {void}
  1427. *
  1428. * This function is part of SqueeJS.
  1429. */
  1430. function mycreateSidebar(sidebarURL, contentContId, width, height) {
  1431. if (typeof jQuery === 'undefined') {
  1432. throw new Error('This SqueeJS\'s function requires jQuery');
  1433. }
  1434. var D = document;
  1435. //w = gfSQJZDocWidth();
  1436. //h = gfSQJZDocHeight();
  1437. this.sidebarContentContId = contentContId;
  1438. barcall = "";
  1439. barcall = "&nbsp;";
  1440. newdiv=D.createElement("div");
  1441. newdiv.id = "SQJSsidebarCall";
  1442. newdiv.innerHTML = barcall;
  1443. D.body.appendChild(newdiv);
  1444. //D.write(newdiv.outerHTML);
  1445. //document.getElementById("SQJSsidebarCall").onmouseover = function(){SQJS.sidebarShow();};
  1446. document.getElementById("SQJSsidebarCall").addEventListener("mouseover", function() {
  1447. SQJS.sidebarShow();
  1448. });
  1449. sidebar = "";
  1450. sidebar += "<div sty='text-align:left;'>";
  1451. sidebar += "<button type='button' class='SQJSclose-button' style='left:10px' onclick='SQJS.sidebarClose();'>";
  1452. sidebar += "<span style='font-size:45px; font-weight:900;'>&times;</span>";
  1453. sidebar += "</button>";
  1454. sidebar += "</div>";
  1455. sidebar += "<div id='SQJSsidebarContent'>";
  1456. sidebar += "</div>";
  1457. newdiv=D.createElement("div");
  1458. newdiv.id = "SQJSsidebar";
  1459. newdiv.style.width = width + "px";
  1460. newdiv.style.height = height + "px";
  1461. newdiv.innerHTML = sidebar;
  1462. D.body.appendChild(newdiv);
  1463. //D.write(newdiv.outerHTML);
  1464. //$("#SQJSsidebarContent").load(sidebarURL+"?rrnd="+ gfSQJZrnd(50000, 99999));
  1465. gfSQJZLoad("SQJSsidebarContent", sidebarURL+"?rrnd="+ gfSQJZrnd(50000, 99999))
  1466. document.body.addEventListener("click", function() {
  1467. SQJS.sidebarClose();
  1468. });
  1469. }
  1470. // --- Sidebar
  1471. }
  1472. window.SQJS = window.SqueeJS = new SqueeJS();
  1473. window.addEventListener("load", function() {
  1474. nl = document.getElementsByTagName("DIV");
  1475. i=0;
  1476. for (n of nl) {
  1477. n.setAttribute("highlightIndex", i);
  1478. i++;
  1479. }
  1480. nl = document.getElementsByTagName("INPUT");
  1481. for (n of nl) {
  1482. n.setAttribute("highlightIndex", i);
  1483. i++;
  1484. }
  1485. nl = document.getElementsByTagName("TEXTAREA");
  1486. for (n of nl) {
  1487. n.setAttribute("highlightIndex", i);
  1488. i++;
  1489. }
  1490. },true);