squeejs.js 49 KB

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