common.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709
  1. var g_is_mobile = false;
  2. var g_language = "langrage_cn";
  3. var gConfigDirMydocument = "../user/My Document/";
  4. //输出调试信息
  5. function debugOutput(str, level = 0) {
  6. console.log(str);
  7. }
  8. function var_dump(str) {
  9. ntf_show(str);
  10. /*
  11. getStyleClass("debug_info").style.display = "-webkit-flex";
  12. getStyleClass("debug_info").style.animation = "viewbug 2s";
  13. document.getElementById("debug").innerHTML = str;
  14. var t = setTimeout("clearDebugMsg()", 2000);
  15. */
  16. }
  17. function clearDebugMsg() {
  18. document.getElementById("debug").innerHTML = "";
  19. getStyleClass("debug_info").style.display = "none";
  20. }
  21. //页面初始字体大小 单位 %
  22. var iStartFontSize = 100;
  23. function setHitsVisibility(isVisible) {
  24. var c = getStyleClass("hit");
  25. if (isVisible) {
  26. c.style.backgroundColor = "blue";
  27. c.style.color = "white";
  28. } else {
  29. c.style.backgroundColor = "white";
  30. c.style.color = "black";
  31. }
  32. }
  33. const root = document.documentElement;
  34. function setPageColor(sColor) {
  35. var cssobj = document.getElementById("colorchange");
  36. switch (sColor) {
  37. case 0:
  38. cssobj.setAttribute("href", "css/color_day.css");
  39. break;
  40. case 1:
  41. cssobj.setAttribute("href", "css/color_dawn.css");
  42. break;
  43. case 2:
  44. cssobj.setAttribute("href", "css/color_night.css");
  45. break;
  46. }
  47. }
  48. //修改页面字体大小
  49. function setPageFontSize(fChange) {
  50. iStartFontSize = iStartFontSize * fChange;
  51. var myBody = document.getElementById("mbody");
  52. myBody.style.fontSize = iStartFontSize + "%";
  53. setCookie("fontsize", iStartFontSize, 65);
  54. }
  55. function editSandhiDisplay(item, obj) {
  56. var isVisible = obj.checked;
  57. var xAllWord = gXmlBookDataBody.getElementsByTagName("word");
  58. switch (item) {
  59. case "parent":
  60. getStyleClass("un_parent").style.display = isVisible ? "block" : "none";
  61. break;
  62. case "comp_parent":
  63. getStyleClass("comp_parent").style.display = isVisible ? "block" : "none";
  64. break;
  65. }
  66. for (iWordIndex = 0; iWordIndex < xAllWord.length; iWordIndex++) {
  67. var un = getNodeText(xAllWord[iWordIndex], "un");
  68. if (un.length > 0) {
  69. switch (item) {
  70. case "begin":
  71. if (getNodeText(xAllWord[iWordIndex], "case") == ".un:begin.") {
  72. wordid = "wb" + getNodeText(xAllWord[iWordIndex], "id");
  73. document.getElementById(wordid).style.display = isVisible ? "block" : "none";
  74. }
  75. break;
  76. case "end":
  77. if (getNodeText(xAllWord[iWordIndex], "case") == ".un:end.") {
  78. wordid = "wb" + getNodeText(xAllWord[iWordIndex], "id");
  79. document.getElementById(wordid).style.display = isVisible ? "block" : "none";
  80. }
  81. break;
  82. case "word":
  83. if (
  84. getNodeText(xAllWord[iWordIndex], "case") != ".un:begin." ||
  85. getNodeText(xAllWord[iWordIndex], "case") != ".un:end." ||
  86. getNodeText(xAllWord[iWordIndex], "case") != ".ctl.#.a."
  87. ) {
  88. //既不是開始也不是結束
  89. wordid = "wb" + getNodeText(xAllWord[iWordIndex], "id");
  90. document.getElementById(wordid).style.display = isVisible ? "block" : "none";
  91. }
  92. break;
  93. case "parent":
  94. //document.getElementById("wb"+un).style.display=(isVisible ? 'block' : 'none');
  95. break;
  96. }
  97. }
  98. }
  99. }
  100. function setFootnotesVisibility(isVisible) {
  101. getStyleClass("note").style.display = isVisible ? "inline" : "none";
  102. }
  103. function setIdVisibility() {
  104. var isVisible = document.getElementById("B_Id").checked;
  105. getStyleClass("ID").style.display = isVisible ? "block" : "none";
  106. }
  107. function setMeaningVisibility(obj) {
  108. var isVisible = obj.checked;
  109. getStyleClass("mean").style.display = isVisible ? "flex" : "none";
  110. }
  111. function setOrgVisibility(obj) {
  112. var isVisible = obj.checked;
  113. getStyleClass("org").style.display = isVisible ? "flex" : "none";
  114. }
  115. function setOrgMeaningVisibility(obj) {
  116. var isVisible = obj.checked;
  117. getStyleClass("om").style.display = isVisible ? "flex" : "none";
  118. }
  119. function setGrammaVisibility(obj) {
  120. var isVisible = obj.checked;
  121. getStyleClass("case").style.display = isVisible ? "flex" : "none";
  122. }
  123. function set_WBW_ALL_Visibility(obj) {
  124. let isVisible = obj.checked;
  125. getStyleClass("mean").style.display = isVisible ? "flex" : "none";
  126. getStyleClass("org").style.display = isVisible ? "flex" : "none";
  127. getStyleClass("om").style.display = isVisible ? "flex" : "none";
  128. getStyleClass("case").style.display = isVisible ? "flex" : "none";
  129. document.getElementById("WBW_B_Meaning").checked = obj.checked;
  130. document.getElementById("WBW_B_Org").checked = obj.checked;
  131. document.getElementById("WBW_B_OrgMeaning").checked = obj.checked;
  132. document.getElementById("WBW_B_Gramma").checked = obj.checked;
  133. }
  134. //显示英译
  135. function setParTranEnVisibility(obj) {
  136. var isVisible = obj.checked;
  137. //getStyleClass('tran_par_en').style.display = (isVisible ? 'block' : 'none');
  138. getStyleClass("en_text").style.display = isVisible ? "block" : "none";
  139. }
  140. //显示中译
  141. function setParTranCnVisibility(obj) {
  142. var isVisible = obj.checked;
  143. //getStyleClass('tran_par_cn').style.display = (isVisible ? 'block' : 'none');
  144. getStyleClass("zh_text").style.display = isVisible ? "block" : "none";
  145. getStyleClass("tw_text").style.display = isVisible ? "block" : "none";
  146. }
  147. /*
  148. //显示模式
  149. _display_para_arrange=0;//0:横向 排列 1:纵向排列
  150. _display_sbs=0; //0:逐段 1:逐句
  151. */
  152. function setArrange(mode) {
  153. if (_display_para_arrange == mode) {
  154. return;
  155. }
  156. _display_para_arrange = mode;
  157. if (_display_para_arrange == 1) {
  158. /* 上下对读 */
  159. getStyleClass("wbwdiv").style.flex = "1";
  160. getStyleClass("trandiv").style.flex = "1";
  161. getStyleClass("pardiv").style.flexDirection = "column";
  162. getStyleClass("sent_wbw_trans").style.flexDirection = "column";
  163. $(".translate_sent_head").each(function(){
  164. $(this).height('auto');
  165. });
  166. $('.translate_sent').css('margin-top','unset');
  167. getStyleClass("sent_wbw_trans").style.margintop = '0';
  168. } else if (_display_para_arrange == 0) {
  169. /* 0 左右对读 */
  170. getStyleClass("wbwdiv").style.flex = "7";
  171. getStyleClass("trandiv").style.flex = "3";
  172. getStyleClass("pardiv").style.flexDirection = "row";
  173. getStyleClass("sent_wbw_trans").style.flexDirection = "row";
  174. $(".translate_sent_head").each(function(){
  175. $(this).height($(this).parent()[0].scrollHeight+"px");
  176. });
  177. getStyleClass("sent_wbw_trans").style.margintop = '-20px';
  178. $('.translate_sent').css('margin-top','-20px');
  179. }
  180. if (_display_sbs == 1) {
  181. /* 逐句对读 */
  182. getStyleClass("pardiv").style.flexDirection = "column";
  183. }
  184. }
  185. function setSbs(mode) {
  186. if (_display_sbs != mode) {
  187. _display_sbs = mode;
  188. if (_display_sbs == 1) {
  189. /* 逐句对读 */
  190. getStyleClass("translate_sent").style.display = "block";
  191. getStyleClass("pardiv").style.flexDirection = "column";
  192. updateWordParBlockInnerAll();
  193. var eAllSent = document.getElementsByClassName("tran_sent");
  194. for (var iSen = 0; iSen < eAllSent.length; iSen++) {
  195. var senA = eAllSent[iSen].getAttributeNode("sn").value;
  196. var blockId = eAllSent[iSen].getAttributeNode("block").value;
  197. var eSBSDiv = document.getElementById("sent_" + senA);
  198. if (eSBSDiv) {
  199. var eBlockSenDiv = document.getElementById("sent_" + senA + "_" + blockId);
  200. if (!eBlockSenDiv) {
  201. //没有 添加
  202. var divSen = document.createElement("div");
  203. var typ = document.createAttribute("class");
  204. typ.nodeValue = "sbs_sent_block";
  205. divSen.attributes.setNamedItem(typ);
  206. var typId = document.createAttribute("id");
  207. typId.nodeValue = "sent_" + senA + "_" + blockId;
  208. divSen.attributes.setNamedItem(typId);
  209. var sn = document.createAttribute("sn");
  210. sn.nodeValue = senA;
  211. divSen.attributes.setNamedItem(sn);
  212. var block = document.createAttribute("block");
  213. block.nodeValue = blockId;
  214. divSen.attributes.setNamedItem(block);
  215. divSen.innerHTML = eAllSent[iSen].innerHTML;
  216. eSBSDiv.appendChild(divSen);
  217. } else {
  218. eBlockSenDiv.innerHTML = eAllSent[iSen].innerHTML;
  219. }
  220. eAllSent[iSen].innerHTML = "";
  221. }
  222. }
  223. } else {
  224. /* 逐段对读 */
  225. //因为wbw重绘会覆盖逐句html
  226. //所以将逐句对读里的句子 转移到逐段div
  227. getStyleClass("translate_sent").style.display = "none";
  228. var eAllSent = document.getElementsByClassName("sbs_sent_block");
  229. for (var iSen = 0; iSen < eAllSent.length; iSen++) {
  230. var senA = eAllSent[iSen].getAttributeNode("sn").value;
  231. var blockId = eAllSent[iSen].getAttributeNode("block").value;
  232. var eSBSDiv = document.getElementById("tran_sent_" + blockId + "_" + senA);
  233. if (eSBSDiv) {
  234. //逐段div
  235. eSBSDiv.innerHTML = eAllSent[iSen].innerHTML;
  236. eAllSent[iSen].innerHTML = "";
  237. } else {
  238. ntf_show("error: 没有找到div:" + "tran_sent_" + blockId + "_" + senA);
  239. }
  240. }
  241. updateWordParBlockInnerAll();
  242. }
  243. }
  244. refreshNoteNumber()//切换逐句后刷新note编号
  245. }
  246. //显示段对译模式
  247. function setParTranShowMode(obj) {
  248. var isVisible = obj.checked;
  249. if (isVisible) {
  250. /* 上下对读 */
  251. _display_para_arrange = 1;
  252. getStyleClass("wbwdiv").style.flex = "1";
  253. getStyleClass("trandiv").style.flex = "1";
  254. getStyleClass("pardiv").style.flexDirection = "column";
  255. getStyleClass("sent_wbw_trans").style.flexDirection = "column";
  256. } else {
  257. /* 左右对读 */
  258. _display_para_arrange = 0;
  259. getStyleClass("wbwdiv").style.flex = "7";
  260. getStyleClass("trandiv").style.flex = "3";
  261. getStyleClass("pardiv").style.flexDirection = "row";
  262. getStyleClass("sent_wbw_trans").style.flexDirection = "row";
  263. }
  264. }
  265. //顯示逐句對讀模式
  266. function setSentTranShowMode(obj) {
  267. var isVisible = obj.checked;
  268. if (isVisible) {
  269. /* 逐句对读 */
  270. _display_sbs = 1;
  271. updateWordParBlockInnerAll();
  272. var eAllSent = document.getElementsByClassName("tran_sent");
  273. for (var iSen = 0; iSen < eAllSent.length; iSen++) {
  274. var senA = eAllSent[iSen].getAttributeNode("sn").value;
  275. var eSBSDiv = document.getElementById("sent_" + senA);
  276. if (eSBSDiv) {
  277. eSBSDiv.innerHTML = eAllSent[iSen].innerHTML;
  278. eAllSent[iSen].innerHTML = "";
  279. }
  280. }
  281. } else {
  282. /* 逐段对读 */
  283. _display_sbs = 0;
  284. //getStyleClass('trandiv').style.display="block";
  285. //getStyleClass('translate_sent').style.display="none";
  286. updateWordParBlockInnerAll();
  287. }
  288. }
  289. //显示单词表
  290. function setWordTableVisibility() {
  291. var isVisible = document.getElementById("B_WordTableShowMode").checked;
  292. document.getElementById("word_table").style.display = isVisible ? "block" : "none";
  293. }
  294. function getStyle(styleName) {
  295. for (var s = 0; s < document.styleSheets.length; s++) {
  296. if (document.styleSheets[s].rules) {
  297. for (var r = 0; r < document.styleSheets[s].rules.length; r++) {
  298. if (document.styleSheets[s].rules[r].selectorText == styleName) {
  299. return document.styleSheets[s].rules[r];
  300. }
  301. }
  302. } else if (document.styleSheets[s].cssRules) {
  303. for (var r = 0; r < document.styleSheets[s].cssRules.length; r++) {
  304. if (document.styleSheets[s].cssRules[r].selectorText == styleName)
  305. return document.styleSheets[s].cssRules[r];
  306. }
  307. }
  308. }
  309. return null;
  310. }
  311. function getStyleClass(className) {
  312. for (var s = 0; s < document.styleSheets.length; s++) {
  313. if (document.styleSheets[s].rules) {
  314. for (var r = 0; r < document.styleSheets[s].rules.length; r++) {
  315. if (document.styleSheets[s].rules[r].selectorText == "." + className) {
  316. return document.styleSheets[s].rules[r];
  317. }
  318. }
  319. } else if (document.styleSheets[s].cssRules) {
  320. for (var r = 0; r < document.styleSheets[s].cssRules.length; r++) {
  321. if (document.styleSheets[s].cssRules[r].selectorText == "." + className)
  322. return document.styleSheets[s].cssRules[r];
  323. }
  324. }
  325. }
  326. return null;
  327. }
  328. //读取cookie 中的字体大小
  329. function checkCookie() {
  330. mFontSize = getCookie("fontsize");
  331. if (mFontSize != null && mFontSize != "") {
  332. iStartFontSize = mFontSize;
  333. } else {
  334. mFontSize = 100;
  335. iStartFontSize = 100;
  336. setCookie("fontsize", mFontSize, 365);
  337. }
  338. setPageFontSize(1);
  339. setPageColor(0);
  340. }
  341. function setObjectVisibilityAlone(strIdGroup, strId) {
  342. var hiden = new Array();
  343. hiden = strIdGroup.split("&");
  344. for (i = 0; i < hiden.length; i++) {
  345. document.getElementById(hiden[i]).style.display = "none";
  346. }
  347. var obj = document.getElementById(strId);
  348. obj.style.display = "block";
  349. }
  350. function setObjectVisibility(strId) {
  351. var obj = document.getElementById(strId);
  352. if (obj.style.display == "none") {
  353. obj.style.display = "block";
  354. } else {
  355. obj.style.display = "none";
  356. }
  357. }
  358. function setObjectVisibility2(ControllerId, ObjId) {
  359. var isVisible = document.getElementById(ControllerId).checked;
  360. document.getElementById(ObjId).style.display = isVisible ? "block" : "none";
  361. }
  362. function setObjectVisibility3(Controller, ObjId) {
  363. var isVisible = Controller.checked;
  364. document.getElementById(ObjId).style.display = isVisible ? "block" : "none";
  365. }
  366. function setAllTitleVisibility(Controller, numTitle) {
  367. for (var i = 0; i < numTitle; i++) {
  368. document.getElementById("titlevisable" + numTitle).checked = Controller.checked;
  369. }
  370. }
  371. function windowsInit() {
  372. var strSertch = location.search;
  373. if (strSertch.length > 0) {
  374. strSertch = strSertch.substr(1);
  375. var sertchList = strSertch.split("&");
  376. for (x in sertchList) {
  377. var item = sertchList[x].split("=");
  378. if (item[0] == "filename") {
  379. g_filename = item[1];
  380. }
  381. }
  382. }
  383. checkCookie();
  384. setUseMode("Read");
  385. if (g_filename.length > 0) {
  386. loadDictFromDB(g_filename);
  387. loadxml(g_filename);
  388. } else {
  389. alert("error:没有指定文件名。");
  390. }
  391. }
  392. /*静态页面使用的初始化函数*/
  393. function windowsInitStatic() {
  394. checkCookie();
  395. setUseMode_Static("Read");
  396. }
  397. function indexInit() {
  398. showUserFilaList();
  399. }
  400. function goHome() {
  401. var r = confirm("在返回前请保存文件。否则所有的更改将丢失。\n 按<确定>回到主页。按<取消>留在当前页面。");
  402. if (r == true) {
  403. window.location.assign("./index.php?device=" + g_device);
  404. }
  405. }
  406. function get_Local_Code_Str(inStr, language) {
  407. var get_Local_Code_Str_i = 0;
  408. switch (language) {
  409. case "sinhala":
  410. for (get_Local_Code_Str_i in local_codestr_sinhala) {
  411. inStr = inStr.replace(
  412. local_codestr_sinhala[get_Local_Code_Str_i].id,
  413. local_codestr_sinhala[get_Local_Code_Str_i].value
  414. );
  415. }
  416. break;
  417. /*case "sc":
  418. for(get_Local_Code_Str_i in local_codestr_sc){
  419. inStr=inStr.replace(local_codestr_sc[get_Local_Code_Str_i].id,local_codestr_sc[get_Local_Code_Str_i].value);
  420. }
  421. break;
  422. case "tc":
  423. for(get_Local_Code_Str_i in local_codestr_tc){
  424. inStr=inStr.replace(local_codestr_tc[get_Local_Code_Str_i].id,local_codestr_tc[get_Local_Code_Str_i].value);
  425. }
  426. break;*/
  427. case "pali":
  428. break;
  429. }
  430. return inStr;
  431. }
  432. //将字符串变为本地化字符串
  433. function getLocalGrammaStr(inStr) {
  434. if (typeof inStr == "undefined") {
  435. return "";
  436. } else {
  437. let str = inStr;
  438. for (const iterator of gLocal.grammastr) {
  439. str = str.replace(iterator.id, iterator.value);
  440. }
  441. return str;
  442. }
  443. }
  444. function getLocalGrammaStr_a(inStr) {
  445. var inStr_array_0 = new Array();
  446. i_inStr_array_0 = 0;
  447. if (inStr.lastIndexOf("<br>") != -1) {
  448. var split_str = "<br>";
  449. } else if (inStr.lastIndexOf("#") != -1) {
  450. var split_str = "#";
  451. } else {
  452. inStr_array_0.push(inStr);
  453. }
  454. inStr_array_0 = inStr.split(split_str);
  455. for (i_inStr_array_0 in inStr_array_0) {
  456. if (inStr_array_0[i_inStr_array_0].lastIndexOf("$") != -1) {
  457. var inStr_array = inStr_array_0[i_inStr_array_0].split("$");
  458. for (i_instr in inStr_array) {
  459. inStr_array[i_instr] = inStr_array[i_instr].slice(1, inStr_array[i_instr].length - 1);
  460. inStr_array[i_instr] = "。" + inStr_array[i_instr] + "。";
  461. }
  462. inStr_array_0.splice(i_inStr_array_0, 1, inStr_array.join("@"));
  463. } else if (inStr_array_0[i_inStr_array_0] != "" /*&& inStr_array_0[i_inStr_array_0].lastIndexOf(\s)=-1*/) {
  464. inStr_array_0[i_inStr_array_0] = inStr_array_0[i_inStr_array_0].slice(
  465. 1,
  466. inStr_array_0[i_inStr_array_0].length - 1
  467. );
  468. inStr_array_0[i_inStr_array_0] = "。" + inStr_array_0[i_inStr_array_0] + "。";
  469. }
  470. }
  471. inStr = inStr_array_0.join(split_str);
  472. for (getLocalGrammaStr_i in gLocal.grammastr) {
  473. var str_Gramma = gLocal.grammastr[getLocalGrammaStr_i].id;
  474. if (str_Gramma != "$") {
  475. str_Gramma = str_Gramma.slice(1, str_Gramma.length - 1); //剝離前後的“.”
  476. str_Gramma = "。" + str_Gramma + "。"; //完成“.”到“。”的替換
  477. var special_RE = RegExp(str_Gramma, "g");
  478. inStr = inStr.replace(special_RE, gLocal.grammastr[getLocalGrammaStr_i].value);
  479. } else {
  480. var special_RE = RegExp("。@。", "g"); //轉化為正則表達式全局變量
  481. inStr = inStr.replace(special_RE, "。·。");
  482. }
  483. }
  484. //inStr=inStr.replace(/。/g,"");
  485. return inStr;
  486. }
  487. function getLocalDictname(inStr) {
  488. if (inStr) {
  489. var LocalDictname = inStr;
  490. } else {
  491. var LocalDictname = "NaN";
  492. }
  493. for (getLocalDictname_i in gLocal.dictname) {
  494. LocalDictname = LocalDictname.replace(
  495. gLocal.dictname[getLocalDictname_i].id,
  496. gLocal.dictname[getLocalDictname_i].value
  497. );
  498. }
  499. return LocalDictname;
  500. }
  501. function getLocalFormulaStr(inGramma, inStr) {
  502. if (inStr.indexOf("[") >= 0) {
  503. return inStr;
  504. }
  505. var output = inStr;
  506. for (i in gLocal.formula) {
  507. if (gLocal.formula[i].id == inGramma) {
  508. fList = gLocal.formula[i].value.split("$");
  509. output = fList[0].replace("~", inStr);
  510. }
  511. }
  512. return output;
  513. }
  514. function getFormulaList(strGramma) {
  515. var output = new Array();
  516. //先加载用户字典里的格位公式
  517. if (myFormula.length > 0) {
  518. for (let i in myFormula) {
  519. if (myFormula[i].gramma == strGramma) {
  520. if (myFormula[i].mean && myFormula[i].mean != "") {
  521. output.push(myFormula[i].mean);
  522. }
  523. }
  524. }
  525. }
  526. for (i in gLocal.formula) {
  527. if (gLocal.formula[i].id == strGramma) {
  528. return output.concat(gLocal.formula[i].value.split("$"));
  529. }
  530. }
  531. }
  532. function getLocalParentFormulaStr(inGramma, inStr) {
  533. var output = inStr;
  534. for (i in gLocal.parent_formula) {
  535. if (gLocal.parent_formula[i].id == inGramma) {
  536. output = gLocal.parent_formula[i].value.replace("~", inStr);
  537. }
  538. }
  539. return output;
  540. }
  541. function cutString(inString, cutLen) {
  542. if (inString) {
  543. if (inString.length > cutLen) {
  544. return inString.substring(0, cutLen - 1) + "…";
  545. } else {
  546. return inString;
  547. }
  548. } else {
  549. return "";
  550. }
  551. }
  552. function getElementWH(element) {
  553. var scrW, scrH;
  554. if (element.innerHeight && element.scrollMaxY) {
  555. // Mozilla
  556. scrW = element.innerWidth + element.scrollMaxX;
  557. scrH = element.innerHeight + element.scrollMaxY;
  558. } else if (element.scrollHeight > element.offsetHeight) {
  559. // all but IE Mac
  560. scrW = element.scrollWidth;
  561. scrH = element.scrollHeight;
  562. } else if (element) {
  563. // IE Mac
  564. scrW = element.offsetWidth;
  565. scrH = element.offsetHeight;
  566. }
  567. var obj = new Object();
  568. obj.width = scrW;
  569. obj.height = scrH;
  570. return obj;
  571. }
  572. /*
  573. 函数:tab_click
  574. 功能:点击选项卡时切换选项卡
  575. 参数:
  576. panalId:选项卡对应的面板id
  577. tabid:选项卡id
  578. callback:回调函数
  579. parm:回调函数参数
  580. 返回值:无
  581. */
  582. function tab_click(panalId, tabid, callback = null, parm = null) {
  583. $("#" + tabid)
  584. .siblings()
  585. .removeClass("act");
  586. $("#" + tabid).addClass("act");
  587. if (panalId != "") {
  588. $("#" + panalId).show();
  589. $("#" + panalId)
  590. .siblings()
  591. .hide();
  592. $("#" + panalId + "_head").show();
  593. $("#" + panalId + "_head")
  594. .siblings()
  595. .hide();
  596. }
  597. if (callback != null) {
  598. if (parm != null) {
  599. callback(parm);
  600. }
  601. }
  602. guide_init();
  603. }
  604. /*
  605. 函数:tab_click_b
  606. 功能:点击选项卡时切换选项卡 一个
  607. 参数:
  608. panalId:选项卡对应的面板id
  609. tabid:选项卡id
  610. callback:回调函数
  611. parm:回调函数参数
  612. 返回值:无
  613. */
  614. function tab_click_b(panalId, tabid, callback = null, parm = null) {
  615. if ($("#" + tabid).hasClass("act")) {
  616. $("#" + tabid).removeClass("act");
  617. } else {
  618. $("#" + tabid)
  619. .siblings()
  620. .removeClass("act");
  621. $("#" + tabid).addClass("act");
  622. }
  623. if (panalId != "") {
  624. $("#" + panalId).show();
  625. $("#" + panalId)
  626. .siblings()
  627. .hide();
  628. $("#" + panalId + "_head").show();
  629. $("#" + panalId + "_head")
  630. .siblings()
  631. .hide();
  632. }
  633. if (callback != null) {
  634. if (parm != null) {
  635. callback(parm);
  636. }
  637. }
  638. }
  639. function get_string_lang(inString) {
  640. let pattern2 = new RegExp("[A-Za-z]+");
  641. if (pattern2.test(inString)) {
  642. return "en";
  643. }
  644. let pattern = new RegExp("[\u4E00-\u9FA5]+");
  645. if (pattern.test(inString)) {
  646. return "zh";
  647. }
  648. return "en";
  649. }
  650. //查询某个字符串是否在字符串数组中出现‘
  651. //@parm:str 被查询的字符串
  652. //@parm:arr 数组
  653. //@return:true 查到 false 没查到
  654. function str_in_array(str, arr) {
  655. for (let x in arr) {
  656. if (arr[x] == str) {
  657. return true;
  658. }
  659. }
  660. return false;
  661. }