common.js 20 KB

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