term.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883
  1. var arrTerm = new Array();
  2. var arrTerm2 = new Array();
  3. var arrMyTerm = new Array();
  4. var arrAllMean = new Array();
  5. var arrTermAllPali = new Array();
  6. var arrWordIdTermId = new Array();
  7. //术语渲染模板
  8. var strTermTanslationTmp = "[%mean%](%pali% %mean2% %mymean%)";
  9. var strTermTanslationTmp2 = "[%mean%]";
  10. var termCounter = new Array();
  11. var noteCounter = 0; //正文内注释计数器
  12. function note(noteId, strDef = "unkow") {
  13. document.write("haha");
  14. }
  15. function note_replace(strIn) {
  16. /*
  17. */
  18. var output = strIn.replace("/*", "<script>");
  19. output = output.replace("*/", "</script>");
  20. return output;
  21. }
  22. function term_init() {}
  23. var str_term_fun_word_link = "term_show_win";
  24. function term_word_link_fun(fun_name) {
  25. str_term_fun_word_link = fun_name;
  26. }
  27. //将存储状态的字符串转换为预显示字符串
  28. //设置状态为 0:未处理的原始状态
  29. function term_std_str_to_tran(strIn, channal = "", editor = "", lang = "") {
  30. return strIn
  31. .replace(/\[\[/g, "<term status='0' channal='" + channal + "' editor='" + editor + "' lang='" + lang + "'>")
  32. .replace(/\]\]/g, "</term>");
  33. }
  34. function term_std_str_to_edit(strIn) {
  35. var arrText = strIn.split("/");
  36. for (var i in arrText) {
  37. //头尾是*
  38. if (arrText[i].substring(0, 1) == "*" && arrText[i].substring(arrText[i].length - 1) == "*") {
  39. var arrOneTermWord = arrText[i].split("@");
  40. if (arrOneTermWord.length == 2) {
  41. arrText[i] = "*" + arrOneTermWord[1];
  42. }
  43. }
  44. }
  45. return arrText.join("/");
  46. }
  47. function term_tran_edit_replace(strIn) {
  48. var strEdit = strIn;
  49. for (var x = 0; x < arrTerm2.length; x++) {
  50. var strReplace = "strEdit=strEdit.replace(/" + arrTerm2[x].meaning + '/g,"/*' + arrTerm2[x].meaning + '*/")';
  51. eval(strReplace);
  52. }
  53. //strEdit=strEdit.replace(/\/*\/*/g,"\/*");
  54. //strEdit=strEdit.replace(/\*\/\*\//g,"*\/");
  55. return strEdit;
  56. }
  57. function term_edit_to_std_str(strIn) {
  58. var arrText = strIn.split("/");
  59. for (var i in arrText) {
  60. //头尾是*
  61. if (arrText[i].substring(0, 1) == "*" && arrText[i].substring(arrText[i].length - 1) == "*") {
  62. var wordMeaning = arrText[i].substring(1, arrText[i].length - 1);
  63. arrText[i] = "*" + term_get_std_str(wordMeaning) + "*";
  64. }
  65. }
  66. return arrText.join("/");
  67. }
  68. function term_get_std_str(strMean) {
  69. for (var x = 0; x < arrTerm2.length; x++) {
  70. if (arrTerm2[x].meaning == strMean) {
  71. return arrTerm2[x].guid + "@" + strMean;
  72. }
  73. }
  74. return "unkow@" + strMean;
  75. }
  76. function term_get_my_std_str(strMean) {
  77. for (const iterator of arrMyTerm) {
  78. if (iterator.meaning == strMean) {
  79. return iterator.guid + "@" + strMean;
  80. }
  81. }
  82. return "unkow@" + strMean;
  83. }
  84. function note_lookup(word, showto) {
  85. $("#" + showto).load(
  86. "../term/term.php?op=search&word=" + word + "&username=" + getCookie("username"),
  87. function (responseTxt, statusTxt, xhr) {
  88. if (statusTxt == "success") {
  89. $(".term_note").each(function (index, element) {
  90. $(this).html(note_init($(this).html()));
  91. $(this).attr("status", 1);
  92. note_refresh_new();
  93. });
  94. } else if (statusTxt == "error") {
  95. console.error("Error: " + xhr.status + ": " + xhr.statusText);
  96. }
  97. }
  98. );
  99. }
  100. function term_get_guid_to_html(strGuid) {}
  101. function term_apply(guid) {
  102. if (g_eCurrWord) {
  103. setNodeText(g_eCurrWord, "note", "=term(" + guid + ")");
  104. term_array_updata();
  105. }
  106. }
  107. function term_data_copy_to_me(guid) {
  108. $("#term_dict").load("../term/term.php?op=copy&wordid=" + guid);
  109. }
  110. //我的术语字典进入编辑模式
  111. function term_edit(guid) {
  112. $("#term_edit_btn1_" + guid).hide();
  113. $("#term_edit_btn2_" + guid).show();
  114. document.getElementById("term_dict_my_" + guid).style.display = "none";
  115. document.getElementById("term_dict_my_edit_" + guid).style.display = "block";
  116. }
  117. //我的术语字典退出编辑模式
  118. function term_data_esc_edit(guid) {
  119. $("#term_edit_btn1_" + guid).show();
  120. $("#term_edit_btn2_" + guid).hide();
  121. document.getElementById("term_dict_my_" + guid).style.display = "block";
  122. document.getElementById("term_dict_my_edit_" + guid).style.display = "none";
  123. }
  124. //我的术语字典 编辑模式 保存
  125. function term_data_save(guid) {
  126. if (guid == "") {
  127. var strWord = $("#term_new_word").val();
  128. var strMean = $("#term_new_mean").val();
  129. var strMean2 = $("#term_new_mean2").val();
  130. var strTag = $("#term_new_tag").val();
  131. var strChannal = $("#term_new_channal").val();
  132. var strLanguage = $("#term_new_language").val();
  133. var strNote = $("#term_new_note").val();
  134. let newTerm = new Object();
  135. newTerm.guid = com_guid();
  136. newTerm.word = strWord;
  137. newTerm.meaning = strMean;
  138. newTerm.other_meaning = strMean2;
  139. newTerm.tag = strTag;
  140. newTerm.channal = strChannal;
  141. newTerm.language = strLanguage;
  142. arrMyTerm.push(newTerm);
  143. } else {
  144. var strWord = $("#term_edit_word_" + guid).val();
  145. var strMean = $("#term_edit_mean_" + guid).val();
  146. var strMean2 = $("#term_edit_mean2_" + guid).val();
  147. var strTag = $("#term_edit_tag_" + guid).val();
  148. var strChannal = $("#term_edit_channal_" + guid).val();
  149. var strLanguage = $("#term_edit_language_" + guid).val();
  150. var strNote = $("#term_edit_note_" + guid).val();
  151. }
  152. $.post(
  153. "../term/term_post.php",
  154. {
  155. id: guid,
  156. word: strWord,
  157. mean: strMean,
  158. mean2: strMean2,
  159. tag: strTag,
  160. channal: strChannal,
  161. language: strLanguage,
  162. note: strNote,
  163. },
  164. function (data, status) {
  165. try {
  166. let result = JSON.parse(data);
  167. if (result.status == 0) {
  168. note_lookup(result.message, "term_dict");
  169. } else {
  170. ntf_show("term error" + result.message);
  171. }
  172. } catch (e) {
  173. console.error("term_get_all_pali:" + e + " data:" + data);
  174. ntf_show("term error");
  175. }
  176. }
  177. );
  178. }
  179. function term_get_all_pali() {
  180. $.get(
  181. "../term/term.php",
  182. {
  183. op: "allpali",
  184. },
  185. function (data, status) {
  186. if (data.length > 0) {
  187. try {
  188. arrTermAllPali = JSON.parse(data);
  189. } catch (e) {
  190. console.error("term_get_all_pali:" + e + " data:" + data);
  191. }
  192. }
  193. }
  194. );
  195. }
  196. function term_lookup_all(pali) {
  197. for (var x in arrTermAllPali) {
  198. if (arrTermAllPali[x].word == pali) {
  199. return arrTermAllPali[x];
  200. }
  201. }
  202. return null;
  203. }
  204. function term_get_my() {
  205. $.get(
  206. "../term/term.php",
  207. {
  208. op: "my",
  209. },
  210. function (data, status) {
  211. if (data.length > 0) {
  212. try {
  213. arrMyTerm = JSON.parse(data);
  214. } catch (e) {
  215. console.error(e.error + " data:" + data);
  216. }
  217. }
  218. }
  219. );
  220. }
  221. //在我的术语字典里查询
  222. function term_lookup_my(pali, channal = "", owner = "", lang = "") {
  223. let langFamily = lang.split("-")[0];
  224. //相同的channel
  225. for (const iterator of arrMyTerm) {
  226. if (channal != "") {
  227. if (channal == iterator.channal && iterator.word == pali) {
  228. return iterator;
  229. }
  230. }
  231. }
  232. if (owner != "") {
  233. //我自己的相同语言
  234. for (const iterator of arrMyTerm) {
  235. if (iterator.word == pali && owner == iterator.owner && iterator.language == lang) {
  236. return iterator;
  237. }
  238. }
  239. //自己相似的语言
  240. for (const iterator of arrMyTerm) {
  241. if (pali == iterator.word && owner == iterator.owner) {
  242. let thisLangFamily = iterator.language.split("-")[0];
  243. if (thisLangFamily == langFamily) {
  244. return iterator;
  245. }
  246. }
  247. }
  248. }
  249. //别人的相同语言
  250. for (const iterator of arrMyTerm) {
  251. if (iterator.word == pali && iterator.language == lang) {
  252. return iterator;
  253. }
  254. }
  255. //找别人的相似语言
  256. for (const iterator of arrMyTerm) {
  257. if (pali == iterator.word) {
  258. let thisLangFamily = iterator.language.split("-")[0];
  259. if (thisLangFamily == langFamily) {
  260. return iterator;
  261. }
  262. }
  263. }
  264. return false;
  265. }
  266. //在我的术语字典里查询 模糊查询
  267. function term_lookup_my_a(pali, channal = "", owner = "", lang = "") {
  268. let langFamily = lang.split("-")[0];
  269. for (const iterator of arrMyTerm) {
  270. if (channal != "") {
  271. if (channal == iterator.channal) {
  272. if (iterator.word.indexOf(pali) != -1) {
  273. return iterator;
  274. }
  275. }
  276. }
  277. }
  278. //我自己的相同语言
  279. if (owner != "") {
  280. for (const iterator of arrMyTerm) {
  281. if (pali == iterator.word && owner == iterator.owner && iterator.language == lang) {
  282. return iterator;
  283. }
  284. }
  285. //自己相似的语言
  286. for (const iterator of arrMyTerm) {
  287. if (pali == iterator.word && owner == iterator.owner) {
  288. let thisLangFamily = iterator.language.split("-")[0];
  289. if (thisLangFamily == langFamily) {
  290. return iterator;
  291. }
  292. }
  293. }
  294. //别人的相同语言
  295. for (const iterator of arrMyTerm) {
  296. if (pali == iterator.word && iterator.language == lang) {
  297. return iterator;
  298. }
  299. }
  300. //找别人的相似语言
  301. for (const iterator of arrMyTerm) {
  302. if (pali == iterator.word) {
  303. let thisLangFamily = iterator.language.split("-")[0];
  304. if (thisLangFamily == langFamily) {
  305. return iterator;
  306. }
  307. }
  308. }
  309. }
  310. return false;
  311. }
  312. function term_lookup_my_id(id) {
  313. for (const iterator of arrMyTerm) {
  314. if (iterator.guid == id) {
  315. return iterator;
  316. }
  317. }
  318. return null;
  319. }
  320. function term_get_all_meaning(word) {
  321. $.get(
  322. "../term/term.php",
  323. {
  324. op: "allmean",
  325. word: word,
  326. },
  327. function (data, status) {
  328. $("#term_win_other_mean").html(data);
  329. }
  330. );
  331. }
  332. //刷新文档正在使用的术语数据
  333. function term_array_updata() {
  334. arrTerm2 = new Array();
  335. var arrTermDownLoadList = new Array();
  336. var arrWordIdTermId = new Array();
  337. var xAllWord = gXmlBookDataBody.getElementsByTagName("word");
  338. for (var x = 0; x < xAllWord.length; x++) {
  339. var sNote = getNodeText(xAllWord[x], "note");
  340. var wid = getNodeText(xAllWord[x], "id");
  341. if (sNote.substring(0, 6) == "=term(") {
  342. var termId = sNote.slice(6, -1);
  343. if (!arrTerm[termId]) {
  344. arrTermDownLoadList.push(termId);
  345. }
  346. //person={wid:wid,tid:termId};
  347. arrWordIdTermId.push({ wid: wid, tid: termId });
  348. }
  349. }
  350. if (arrTermDownLoadList.length > 0) {
  351. var idlist = arrTermDownLoadList.join();
  352. idlist = idlist.replace(/,/g, "','");
  353. idlist = "'" + idlist + "'";
  354. $.get(
  355. "../term/term.php",
  356. {
  357. op: "extract",
  358. list: idlist,
  359. },
  360. function (data, status) {
  361. var obj = JSON.parse(data);
  362. for (var x in obj) {
  363. arrTerm[obj[x].guid] = obj[x];
  364. arrTerm2.push(obj[x]);
  365. }
  366. if (g_eCurrWord) {
  367. updataWordHeadById(getNodeText(g_eCurrWord, "id"));
  368. refreshWordNote(g_eCurrWord.parentNode.parentNode);
  369. }
  370. for (var i = 0; i < arrWordIdTermId.length; i++) {
  371. var wid = arrWordIdTermId[i].wid;
  372. var sMean = arrTerm[arrWordIdTermId[i].tid].meaning;
  373. doc_setWordDataById(wid, "mean", sMean);
  374. updateWordBodyById(wid);
  375. }
  376. }
  377. );
  378. }
  379. }
  380. /*
  381. *-----------------------
  382. * 更新术语显示
  383. * 默认模版<a href='{{ link }}'>{{meaning}}</a>({{word}},{{meaning2}})
  384. *-----------------------
  385. */
  386. function term_updata_translation(callback=null) {
  387. termCounter = new Array();
  388. noteCounter = 1;
  389. //计算有效模版数量
  390. let iValidTmp = 0;
  391. if (typeof setting !== "undefined") {
  392. for (const iterator of setting["term.template"]) {
  393. if (iterator != "") {
  394. iValidTmp++;
  395. }
  396. }
  397. }
  398. $("term").each(function () {
  399. let status = $(this).attr("status");
  400. let orgWord = $(this).text().split('|');
  401. let termText;
  402. if(status == 0){
  403. if(orgWord.length>1){
  404. $(this).attr("pali",orgWord[0]) ;
  405. $(this).attr("show",orgWord[1]) ;
  406. $(this).text(orgWord[0]);
  407. }
  408. }
  409. termText = $(this).attr("pali");
  410. if(typeof termText=="undefined"){
  411. termText = $(this).text();
  412. }
  413. if (termText.slice(0, 1) == "#") {
  414. if (status == 0) {
  415. $(this).attr("status", "1");
  416. $(this).attr("type", "1");
  417. $(this).attr("text", termText.slice(1));
  418. }
  419. let noteText = $(this).attr("text");
  420. $(this).html("<a onclick=\"alert('" + noteText + "')\">[" + noteCounter + "]</a>");
  421. noteCounter++;
  422. } else {
  423. //if (status == 0 || status == 2)
  424. {
  425. let myterm = term_lookup_my(
  426. termText,
  427. $(this).attr("channal"),
  428. $(this).attr("editor"),
  429. $(this).attr("lang")
  430. ); //我的术语字典
  431. if (myterm) {
  432. //查字典成功
  433. $(this).attr("status", "1");
  434. $(this).attr("type", "0");
  435. $(this).attr("guid", myterm.guid);
  436. $(this).attr("pali", myterm.word);
  437. $(this).attr("mean", myterm.meaning);
  438. $(this).attr("mean2", myterm.other_meaning);
  439. $(this).attr("replace", myterm.meaning);
  440. } else {
  441. //没查到
  442. $(this).attr("status", "2");
  443. $(this).attr("pali", termText);
  444. }
  445. }
  446. let guid = $(this).attr("guid");
  447. let pali = $(this).attr("pali");
  448. let meaningShow = $(this).attr("show");
  449. let mean = $(this).attr("mean");
  450. let mean2 = $(this).attr("mean2");
  451. let renderTo = $(this).attr("pos");
  452. let channel = $(this).attr("channal");
  453. let lang = $(this).attr("lang");
  454. let noteText = "";
  455. let realMeaning = '';
  456. if(typeof meaningShow !== "undefined"){
  457. //指定显示意思优先
  458. realMeaning = meaningShow;
  459. }else{
  460. realMeaning = mean;
  461. }
  462. if (termCounter[guid]) {
  463. termCounter[guid]++;
  464. } else {
  465. termCounter[guid] = 1;
  466. }
  467. console.log("termCounter",termCounter[guid]);
  468. myterm = term_lookup_my(pali, $(this).attr("channal"), $(this).attr("editor"), $(this).attr("lang")); //我的术语字典
  469. let linkclass = "";
  470. if (myterm) {
  471. linkclass = "term_link";
  472. } else {
  473. linkclass = "term_link_new";
  474. }
  475. if (guid) {
  476. if (renderTo == "wbw") {
  477. noteText = "%note%";
  478. } else {
  479. if (typeof setting !== "undefined") {
  480. let currTermCounter = termCounter[guid];
  481. if (currTermCounter > iValidTmp) {
  482. currTermCounter = iValidTmp;
  483. }
  484. noteText = setting["term.template"][currTermCounter - 1];
  485. } else {
  486. if (termCounter[guid] == 1) {
  487. noteText = strTermTanslationTmp;
  488. } else {
  489. noteText = strTermTanslationTmp2;
  490. }
  491. }
  492. }
  493. console.log("term temlate",noteText);
  494. noteText = noteText.replace(
  495. "[",
  496. "<span class='" +
  497. linkclass +
  498. "' id='term_link_" +
  499. guid +
  500. "' gid='" +
  501. guid +
  502. "' onclick=\"" +
  503. str_term_fun_word_link +
  504. "('" +
  505. guid +
  506. "','" +
  507. pali +
  508. "','"+channel+"','"+lang+"')\">"
  509. );
  510. noteText = noteText.replace("]", "</span>");
  511. noteText = noteText.replace("%mean%", "<span class='term_mean'>" + realMeaning + "</span>");
  512. noteText = noteText.replace("%pali%", "<span class='term_pali'>" + pali + "</span>");
  513. if (mean2 != "") {
  514. noteText = noteText.replace("%mean2%", ", <span class='term_mean2'>" + mean2 + "</span>");
  515. } else {
  516. noteText = noteText.replace("%mean2%", "");
  517. }
  518. noteText = noteText.replace("%note%", "<span class='term_note'>" + "" + "</span>");
  519. {
  520. if (myterm) {
  521. //匹配术语成功
  522. if (myterm.meaning != mean) {
  523. realMeaning = "<span class='term_mean_my'>" + myterm.meaning + "</span>";
  524. } else {
  525. realMeaning = '';
  526. }
  527. } else {
  528. realMeaning = '';
  529. }
  530. }
  531. noteText = noteText.replace("%mymean%", realMeaning);
  532. } else {
  533. noteText =
  534. "<span class='" +
  535. linkclass +
  536. "' onclick=\"" +
  537. str_term_fun_word_link +
  538. "('','" +
  539. termText +
  540. "','"+channel+"','"+lang+"')\">" +
  541. termText +
  542. "</span>";
  543. }
  544. $(this).html(noteText);
  545. }
  546. });
  547. term_popup_init();
  548. if(callback){
  549. callback();
  550. }
  551. }
  552. function term_show_win(guid, keyWord = "",channel="",lang="") {
  553. if (guid == "") {
  554. if (typeof term_body == "undefined") {
  555. term_edit_dlg_open("", keyWord,channel,lang);
  556. } else {
  557. $(term_body).html(
  558. "“" +
  559. keyWord +
  560. "”" +
  561. gLocal.gui.no_created +
  562. "<br /><button onclick=\"term_add_new('" +
  563. keyWord +
  564. "')\">" +
  565. gLocal.gui.create_now +
  566. "</button>"
  567. );
  568. }
  569. } else {
  570. let currWord = term_lookup_my_id(guid);
  571. if (currWord) {
  572. let termString = "";
  573. let pali = currWord.word;
  574. let pali_1 = pali.substring(0, 1).toUpperCase();
  575. pali = pali_1 + pali.substring(1);
  576. let mean = currWord.meaning;
  577. let myterm = term_lookup_my(currWord.word); //我的术语字典
  578. termString += "<div class='term_win_mean'>" + pali + "</div>";
  579. termString += "<div class='term_win_pali'>意思:" + currWord.meaning + "</div>";
  580. termString += "<div class='term_win_mean2'>其他意思:" + currWord.other_meaning + "</div>";
  581. termString += "<div class='term_win_mymean'>我的词库:";
  582. if (myterm) {
  583. termString += "<b>" + myterm.meaning + "</b> ";
  584. } else {
  585. termString += "<input type='input' placeholder='我的释义'>";
  586. }
  587. termString += "<span>其他:</span><span id='term_win_other_mean'></span>";
  588. termString += "</div>";
  589. if (currWord.note) {
  590. termString += "<div class='term_win_note'>" + currWord.note + "</div>";
  591. } else {
  592. termString += "<div class='term_win_note'>Loading</div>";
  593. }
  594. $(term_body).html(termString);
  595. term_get_all_meaning(currWord.word);
  596. if (!currWord.note) {
  597. $.get(
  598. "../term/term.php",
  599. {
  600. op: "load_id",
  601. id: currWord.guid,
  602. },
  603. function (data, status, xhr) {
  604. switch (status) {
  605. case "success":
  606. try {
  607. let loadWord = JSON.parse(data);
  608. $("#term_win_note").html(loadWord[0].note);
  609. //修改内存数据
  610. for (let index = 0; index < arrMyTerm.length; index++) {
  611. if (arrMyTerm[index].guid == loadWord[0].guid) {
  612. arrMyTerm[index].note = loadWord[0].note;
  613. return;
  614. }
  615. }
  616. } catch (e) {
  617. console.error(e + " data:" + data);
  618. }
  619. break;
  620. case "error":
  621. console.error("Error: " + xhr.status + ": " + xhr.statusText);
  622. break;
  623. }
  624. }
  625. );
  626. }
  627. } else {
  628. $(term_body).html("undefined guid");
  629. }
  630. }
  631. document.getElementById("term_win").style.display = "flex";
  632. }
  633. function term_tmp(type, tmp) {
  634. if (tmp == "new") {
  635. switch (type) {
  636. case "a":
  637. strTermTanslationTmp = $("#term_my_tmp").val();
  638. break;
  639. case "a2":
  640. strTermTanslationTmp2 = $("#term_my_tmp").val();
  641. break;
  642. }
  643. } else {
  644. switch (type) {
  645. case "a":
  646. strTermTanslationTmp = tmp;
  647. break;
  648. case "a2":
  649. strTermTanslationTmp2 = tmp;
  650. break;
  651. }
  652. }
  653. term_updata_translation();
  654. }
  655. function term_add_new(keyword) {
  656. document.getElementById("term_win").style.display = "none";
  657. tab_click_b("sys_term", "tab_rb_sys_term", right_panal_slide_toggle, "tab_rb_sys_term");
  658. editor_show_right_tool_bar(true);
  659. note_lookup(keyword, "term_dict");
  660. }
  661. function term_show_new() {
  662. $("#term_new_recorder").slideToggle();
  663. $("#new_term_button").hide();
  664. guide_init();
  665. }
  666. function term_get_dict(callback=null) {
  667. if (arrMyTerm.length > 0) {
  668. term_updata_translation(callback);
  669. return;
  670. }
  671. let termwordlist = new Array();
  672. $("term").each(function () {
  673. if ($(this).attr("status") == 0) {
  674. let word = $(this).text().split('|');
  675. $(this).attr("pali", word[0]);
  676. if(word.length>1){
  677. $(this).attr("show", word[1]);
  678. $(this).text(word[0]);
  679. }
  680. }
  681. let termword = new Object();
  682. termword.pali = $(this).attr("pali");
  683. termword.channal = $(this).attr("channal");
  684. termword.editor = $(this).attr("editor");
  685. termword.lang = $(this).attr("lang");
  686. termwordlist.push(termword);
  687. });
  688. let readonly = true;
  689. if (_display == "sent") {
  690. readonly = false;
  691. }
  692. console.log('term list',termwordlist);
  693. $.post(
  694. "../term/term_get.php",
  695. {
  696. words: JSON.stringify(termwordlist),
  697. channal: _channal,
  698. readonly: readonly,
  699. },
  700. function (data, status) {
  701. if (data.length > 0) {
  702. arrMyTerm = JSON.parse(data);
  703. term_updata_translation(callback);
  704. }
  705. }
  706. );
  707. }
  708. function term_get_used(){
  709. let output = [];
  710. $("term").each(function () {
  711. let word = $(this).attr("pali");
  712. let meaning = $(this).attr("mean");
  713. let meaning2 = $(this).attr("mean2");
  714. if(word !== ""){
  715. output[word] = {
  716. pali:word,
  717. pali_en:com_getPaliEn(word),
  718. meaning:meaning,
  719. meaning2:meaning2
  720. };
  721. }
  722. });
  723. let arrWord=[];
  724. for (const key in output) {
  725. if (output.hasOwnProperty.call(output, key)) {
  726. const element = output[key];
  727. arrWord.push(element);
  728. }
  729. }
  730. arrWord = arrWord.sort(function(a, b){
  731. var x = a.pali_en;
  732. var y = b.pali_en;
  733. if (x < y) {return -1;}
  734. if (x > y) {return 1;}
  735. return 0;
  736. });
  737. let arrMeaning=[];
  738. for (const key in output) {
  739. if (output.hasOwnProperty.call(output, key)) {
  740. const element = output[key];
  741. if(element.meaning != ""){
  742. arrMeaning.push(element);
  743. }
  744. }
  745. }
  746. arrMeaning = arrMeaning.sort(function(a, b){
  747. var x = a.meaning;
  748. var y = b.meaning;
  749. if (x < y) {return -1;}
  750. if (x > y) {return 1;}
  751. return 0;
  752. });
  753. return {
  754. glossary:{
  755. word:arrWord,
  756. meaning:arrMeaning
  757. }
  758. }
  759. }
  760. /*
  761. function term_popup_init() {
  762. $(".term_link").each(function () {
  763. if ($(this).attr("init") != "1") {
  764. if ($(this).text().length > 0) {
  765. $(this).css("background", "unset");
  766. }
  767. let gid = $(this).attr("gid");
  768. if ($(this).offset().left < $(document.body).width() / 2) {
  769. //出现在左侧
  770. $(this).append(
  771. '<div id="gid_' +
  772. gid +
  773. '" class="guide_contence" style="left: -5px;"></div>'
  774. );
  775. $(".guide_contence:after").css("left", "0");
  776. } else {
  777. //出现在右侧
  778. $(this).append(
  779. '<div id="gid_' +
  780. gid +
  781. '" class="guide_contence" style="right: -5px;"></div>'
  782. );
  783. $(".guide_contence:after").css("right", "0");
  784. }
  785. $(this).attr("init", "1");
  786. }
  787. });
  788. $(".term_link").mouseenter(function () {
  789. if ($(this).children(".guide_contence").first().html().length > 0) {
  790. return;
  791. }
  792. let gid = $(this).attr("gid");
  793. term_load_preview(gid, "gid_" + gid);
  794. });
  795. }
  796. function term_load_preview(guid, showto) {
  797. $.get(
  798. "../term/term.php",
  799. {
  800. op: "load_id",
  801. id: guid,
  802. format: "json",
  803. },
  804. function (data, status) {
  805. let html = "";
  806. if (status == "success") {
  807. try {
  808. let result = JSON.parse(data)[0];
  809. html = "<div class='term_block'>";
  810. html += "<h2>" + result.word + "</h2>";
  811. html += "<div class='meaning'>" + result.meaning + "</div>";
  812. html +=
  813. "<div class='term_note' status='1'>" +
  814. note_init(result.note) +
  815. "</div>";
  816. html +=
  817. "<div ><a href='../wiki/wiki.php?word=" +
  818. result.word +
  819. "' target='_blank'>更多</a></div>";
  820. html += "</div>";
  821. $("#" + showto).html(html);
  822. } catch (e) {
  823. console.error("note_lookup_guid_json:" + e + " data:" + data);
  824. }
  825. }
  826. }
  827. );
  828. }
  829. */