term.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654
  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. var strTermTanslationTmp="[%mean%](%pali% %mean2% %mymean%)";
  8. var strTermTanslationTmp2="[%mean%]";
  9. var termCounter=new Array();
  10. var noteCounter=0; //正文内注释计数器
  11. function note(noteId,strDef="unkow"){
  12. document.write("haha");
  13. }
  14. function note_replace(strIn){
  15. /*
  16. */
  17. var output = strIn.replace("/*","<script>");
  18. output = output.replace("*/","</script>");
  19. return(output);
  20. }
  21. function term_init(){
  22. }
  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){
  30. return(strIn.replace(/\[\[/g,"<term status='0'>").replace(/\]\]/g,"</term>"));
  31. }
  32. function term_std_str_to_edit(strIn){
  33. var arrText = strIn.split("/");
  34. for(var i in arrText){
  35. //头尾是*
  36. if(arrText[i].substring(0,1)=="*" && arrText[i].substring(arrText[i].length-1)=="*"){
  37. var arrOneTermWord=arrText[i].split("@");
  38. if(arrOneTermWord.length==2){
  39. arrText[i]="*"+arrOneTermWord[1];
  40. }
  41. }
  42. }
  43. return(arrText.join("/"));
  44. }
  45. function term_tran_edit_replace(strIn){
  46. var strEdit=strIn;
  47. for(var x=0;x<arrTerm2.length;x++){
  48. var strReplace="strEdit=strEdit.replace(/"+arrTerm2[x].meaning+"/g,\"/*"+arrTerm2[x].meaning+"*/\")";
  49. eval(strReplace);
  50. }
  51. //strEdit=strEdit.replace(/\/*\/*/g,"\/*");
  52. //strEdit=strEdit.replace(/\*\/\*\//g,"*\/");
  53. return(strEdit);
  54. }
  55. function term_edit_to_std_str(strIn){
  56. var arrText = strIn.split("/");
  57. for(var i in arrText){
  58. //头尾是*
  59. if(arrText[i].substring(0,1)=="*" && arrText[i].substring(arrText[i].length-1)=="*"){
  60. var wordMeaning=arrText[i].substring(1,arrText[i].length-1);
  61. arrText[i]="*"+term_get_std_str(wordMeaning)+"*";
  62. }
  63. }
  64. return(arrText.join("/"));
  65. }
  66. function term_get_std_str(strMean){
  67. for(var x=0;x<arrTerm2.length;x++){
  68. if(arrTerm2[x].meaning==strMean){
  69. return(arrTerm2[x].guid+"@"+strMean);
  70. }
  71. }
  72. return("unkow@"+strMean);
  73. }
  74. function term_get_my_std_str(strMean){
  75. for(var x in arrMyTerm){
  76. if(arrMyTerm[x].meaning==strMean){
  77. return(arrMyTerm[x].guid+"@"+strMean);
  78. }
  79. }
  80. return("unkow@"+strMean);
  81. }
  82. function note_lookup(word,showto){
  83. $("#"+showto).load("../term/term.php?op=search&word="+word+"&username="+getCookie("username"),function(responseTxt,statusTxt,xhr){
  84. if(statusTxt=="success"){
  85. $(".term_note").each(function(index,element){
  86. $(this).html(note_init($(this).html()));
  87. $(this).attr("status",1);
  88. note_refresh_new();
  89. });
  90. }
  91. else if(statusTxt=="error"){
  92. console.error("Error: "+xhr.status+": "+xhr.statusText);
  93. }
  94. });
  95. }
  96. function note_lookup_guid_json(guid,showto){
  97. $.get("../term/term.php",
  98. {
  99. op:"load_id",
  100. id:guid,
  101. format:"json"
  102. },
  103. function(data,status){
  104. let html="";
  105. if(status=="success"){
  106. try{
  107. let result= JSON.parse(data)[0];
  108. html = "<div class='term_block'>";
  109. html += "<h2>"+result.word+"</h2>";
  110. html += "<div class='meaning'>"+result.meaning+"</div>";
  111. html += "<div class='term_note' status='1'>"+note_init(result.note)+"</div>";
  112. html += "</div>";
  113. $("#"+showto).html(html);
  114. note_refresh_new();
  115. }
  116. catch(e){
  117. console.error("note_lookup_guid_json:"+e+" data:"+data);
  118. }
  119. }
  120. });
  121. }
  122. var term_get_word_to_div_callback=null;
  123. function term_get_word_to_div(strWord,div,callback){
  124. term_get_word_to_div_callback=callback;
  125. $.get("../term/term.php",
  126. {
  127. op:"get",
  128. word:strWord,
  129. format:"json"
  130. },
  131. function(data,status){
  132. let html="";
  133. if(status=="success"){
  134. try{
  135. let result= JSON.parse(data);
  136. let html="";
  137. if(result.length>0){
  138. let type=new Array();
  139. let authors=new Array();
  140. for(x in result){
  141. if(result[x].tag==""){
  142. result[x].tag="_null_";
  143. }
  144. if(type[result[x].tag]==null){
  145. type[result[x].tag]=new Array();
  146. }
  147. type[result[x].tag].push(result[x].meaning);
  148. authors[result[x].owner]=1;
  149. }
  150. html += "<div class='term_word_head'>";
  151. html += "<div class='term_word_head_pali'>";
  152. html += result[0].word;
  153. html += "</div>";
  154. for(y in type){
  155. html += "<div class='term_word_head_mean'>";
  156. if(y!="_null_"){
  157. html += y+":";
  158. }
  159. for(k in type[y]){
  160. html += type[y][k];
  161. }
  162. html += "</div>";
  163. }
  164. html += "<div class='term_word_head_authors'>贡献者:";
  165. for(y in authors){
  166. html += "<a onclick=\"\">"+y+"</a> "
  167. }
  168. html += "</div>";
  169. html += "</div>";
  170. for(x in result){
  171. html += "<div class='term_block'>";
  172. html += "<div class='term_block_bar'>";
  173. html += "<div class='term_block_bar_left'>";
  174. html += "<div class='term_block_bar_left_icon'>";
  175. html += result[x].owner.slice(0,1);
  176. html += "</div>";
  177. html += "<div class='term_block_bar_left_info'>";
  178. html += "<div class='term_meaning'>"+result[x].meaning;
  179. if(result[x].tag!="_null_"){
  180. html += "<span class='term_tag'>"+result[x].tag+"</span>";
  181. }
  182. html += "</div>";
  183. html += "<div class='term_author'>"+result[x].owner+"</div>";
  184. html += "</div>";
  185. html += "</div>";
  186. html += "<div class='term_block_bar_right'>";
  187. html += "<span><a href='#'>[编辑]</a><a href='#'>[赞]</a><a href='#'>[收藏]</a></span>";
  188. html += "</div>";
  189. html += "</div>";
  190. //html += "<div class='term_meaning2'>"+result[x].other_meaning+"</div>";
  191. html += "<div class='term_note' status='1'>"+note_init(result[x].note)+"</div>";
  192. html += "</div>";
  193. }
  194. }
  195. else{
  196. html += "<div >词条尚未创建</div>";
  197. html += "<div ><input type=\"input\" value=\"\" placeholder=\"pali\"/></div>";
  198. html += "<div ><input type=\"input\" value=\"\" placeholder=\"meaning\"/></div>";
  199. html += "<div ><input type=\"input\" value=\"\" placeholder=\"other meaning\"/></div>";
  200. html += "<div ><input type=\"input\" value=\"\" placeholder=\"category\"/></div>";
  201. html += "<div ><input type=\"input\" value=\"\" placeholder=\"language\"/></div>";
  202. html += "<div ><textarea></textarea></div>";
  203. }
  204. $("#"+div).html(html);
  205. note_refresh_new();
  206. if(term_get_word_to_div_callback!=null){
  207. term_get_word_to_div_callback(result);
  208. }
  209. }
  210. catch(e){
  211. console.error("term_get_word_to_div:"+e+" data:"+data);
  212. }
  213. }
  214. });
  215. }
  216. function term_get_guid_to_html(strGuid){
  217. }
  218. function term_apply(guid){
  219. if(g_eCurrWord){
  220. setNodeText(g_eCurrWord,"note","=term("+guid+")");
  221. term_array_updata();
  222. }
  223. }
  224. function term_data_copy_to_me(guid){
  225. $("#term_dict").load("term.php?op=copy&wordid="+guid);
  226. }
  227. //我的术语字典进入编辑模式
  228. function term_edit(guid){
  229. $("#term_edit_btn1_"+guid).hide();
  230. $("#term_edit_btn2_"+guid).show();
  231. document.getElementById("term_dict_my_"+guid).style.display="none";
  232. document.getElementById("term_dict_my_edit_"+guid).style.display="block";
  233. }
  234. //我的术语字典退出编辑模式
  235. function term_data_esc_edit(guid){
  236. $("#term_edit_btn1_"+guid).show();
  237. $("#term_edit_btn2_"+guid).hide();
  238. document.getElementById("term_dict_my_"+guid).style.display="block";
  239. document.getElementById("term_dict_my_edit_"+guid).style.display="none";
  240. }
  241. //我的术语字典 编辑模式 保存
  242. function term_data_save(guid){
  243. if(guid==""){
  244. var strWord=$("#term_new_word").val();
  245. var strMean=$("#term_new_mean").val();
  246. var strMean2=$("#term_new_mean2").val();
  247. var strNote=$("#term_new_note").val();
  248. var strTag=$("#term_new_tag").val();
  249. let newTerm = new Object();
  250. newTerm.guid=com_guid();
  251. newTerm.word=strWord;
  252. newTerm.meaning = strMean;
  253. newTerm.other_meaning = strMean2;
  254. arrMyTerm.push(newTerm);
  255. }
  256. else{
  257. var strWord=$("#term_edit_word_"+guid).val();
  258. var strMean=$("#term_edit_mean_"+guid).val();
  259. var strMean2=$("#term_edit_mean2_"+guid).val();
  260. var strTag=$("#term_edit_tag_"+guid).val();
  261. var strNote=$("#term_edit_note_"+guid).val();
  262. }
  263. $.get("../term/term.php",
  264. {
  265. op:"save",
  266. guid:guid,
  267. word:strWord,
  268. mean:strMean,
  269. mean2:strMean2,
  270. tag:strTag,
  271. note:strNote,
  272. username:getCookie("username")
  273. },
  274. function(data,status){
  275. try{
  276. let result= JSON.parse(data);
  277. if(result.status==0){
  278. note_lookup(result.message,"term_dict");
  279. }
  280. else{
  281. ntf_show("term error"+result.message);
  282. }
  283. }
  284. catch(e){
  285. console.error("term_get_all_pali:"+e+" data:"+data);
  286. ntf_show("term error");
  287. }
  288. });
  289. }
  290. function term_get_all_pali(){
  291. $.get("term.php",
  292. {
  293. op:"allpali"
  294. },
  295. function(data,status){
  296. if(data.length>0){
  297. try{
  298. arrTermAllPali = JSON.parse(data);
  299. }
  300. catch(e){
  301. console.error("term_get_all_pali:"+e+" data:"+data);
  302. }
  303. }
  304. });
  305. }
  306. function term_lookup_all(pali){
  307. for(var x in arrTermAllPali){
  308. if(arrTermAllPali[x].word==pali){
  309. return(arrTermAllPali[x]);
  310. }
  311. }
  312. return(null);
  313. }
  314. function term_get_my(){
  315. $.get("term.php",
  316. {
  317. op:"my"
  318. },
  319. function(data,status){
  320. if(data.length>0){
  321. try{
  322. arrMyTerm = JSON.parse(data);
  323. }
  324. catch(e){
  325. console.error(e.error+" data:"+data);
  326. }
  327. }
  328. });
  329. }
  330. //在我的术语字典里查询
  331. function term_lookup_my(pali){
  332. for(var x in arrMyTerm){
  333. if(arrMyTerm[x].meaning==pali){
  334. return(arrMyTerm[x]);
  335. }
  336. if(arrMyTerm[x].word==pali){
  337. return(arrMyTerm[x]);
  338. }
  339. }
  340. return(null);
  341. }
  342. function term_lookup_my_id(id){
  343. for(var x in arrMyTerm){
  344. if(arrMyTerm[x].guid==id){
  345. return(arrMyTerm[x]);
  346. }
  347. }
  348. return(null);
  349. }
  350. function term_get_all_meaning(word){
  351. $.get("term.php",
  352. {
  353. op:"allmean",
  354. word:word
  355. },
  356. function(data,status){
  357. $("#term_win_other_mean").html(data);
  358. });
  359. }
  360. //刷新文档正在使用的术语数据
  361. function term_array_updata(){
  362. arrTerm2=new Array();
  363. var arrTermDownLoadList=new Array();
  364. var arrWordIdTermId=new Array();
  365. var xAllWord = gXmlBookDataBody.getElementsByTagName("word");
  366. for(var x=0;x<xAllWord.length;x++){
  367. var sNote = getNodeText(xAllWord[x],"note");
  368. var wid=getNodeText(xAllWord[x],"id");
  369. if(sNote.substring(0,6)=="=term("){
  370. var termId=sNote.slice(6,-1);
  371. if(!arrTerm[termId]){
  372. arrTermDownLoadList.push(termId);
  373. }
  374. //person={wid:wid,tid:termId};
  375. arrWordIdTermId.push({wid:wid,tid:termId});
  376. }
  377. }
  378. if(arrTermDownLoadList.length>0){
  379. var idlist=arrTermDownLoadList.join();
  380. idlist = idlist.replace(/,/g,"','");
  381. idlist = "'"+ idlist + "'";
  382. $.get("term.php",
  383. {
  384. op:"extract",
  385. list:idlist
  386. },
  387. function(data,status){
  388. var obj = JSON.parse(data);
  389. for(var x in obj){
  390. arrTerm[obj[x].guid]=obj[x];
  391. arrTerm2.push(obj[x]);
  392. }
  393. if(g_eCurrWord){
  394. updataWordHeadById(getNodeText(g_eCurrWord,"id"));
  395. refreshWordNote(g_eCurrWord.parentNode.parentNode);
  396. }
  397. for(var i=0;i<arrWordIdTermId.length;i++){
  398. var wid=arrWordIdTermId[i].wid;
  399. var sMean=arrTerm[arrWordIdTermId[i].tid].meaning;
  400. doc_setWordDataById(wid,"mean",sMean);
  401. updateWordBodyById(wid);
  402. }
  403. });
  404. }
  405. }
  406. function term_updata_translation(){
  407. termCounter=new Array();
  408. noteCounter=1;
  409. $("term").each(function(){
  410. let status=$(this).attr("status");
  411. let termText = $(this).text();
  412. if(termText.slice(0,1)=="#"){
  413. if(status==0){
  414. $(this).attr("status","1");
  415. $(this).attr("type","1");
  416. $(this).attr("text",termText.slice(1));
  417. }
  418. let noteText=$(this).attr("text");
  419. $(this).html("<a onclick=\"alert('"+noteText+"')\">["+noteCounter+"]</a>");
  420. noteCounter++;
  421. }
  422. else{
  423. if(status==0 || status==2){
  424. let myterm=term_lookup_my(termText);//我的术语字典
  425. if(myterm){
  426. $(this).attr("status","1");
  427. $(this).attr("type","0");
  428. $(this).attr("guid",myterm.guid);
  429. $(this).attr("pali",myterm.word);
  430. $(this).attr("mean",myterm.meaning);
  431. $(this).attr("mean2",myterm.other_meaning);
  432. $(this).attr("replace",myterm.meaning);
  433. }
  434. else{
  435. $(this).attr("status","2");
  436. $(this).attr("pali",termText);
  437. }
  438. }
  439. let guid=$(this).attr("guid");
  440. let pali=$(this).attr("pali");
  441. let mean=$(this).attr("mean");
  442. let mean2=$(this).attr("mean2");
  443. var renderTo=$(this).attr("pos");
  444. var noteText="";
  445. if(termCounter[guid]){
  446. termCounter[guid]=2;
  447. }
  448. else{
  449. termCounter[guid]=1;
  450. }
  451. var myterm=term_lookup_my(pali);//我的术语字典
  452. let linkclass="";
  453. if(myterm){
  454. linkclass="term_link";
  455. }
  456. else{
  457. linkclass="term_link_new";
  458. }
  459. if(guid){
  460. if(renderTo=="wbw"){
  461. noteText="%note%";
  462. }
  463. else{
  464. if(termCounter[guid]==1){
  465. noteText=strTermTanslationTmp;
  466. }
  467. else{
  468. noteText=strTermTanslationTmp2;
  469. }
  470. }
  471. noteText=noteText.replace("[","<span class='"+linkclass+"' onclick=\""+str_term_fun_word_link+"('"+guid+"','"+pali+"')\">");
  472. noteText=noteText.replace("]","</span>");
  473. noteText=noteText.replace("%mean%","<span class='term_mean'>"+mean+"</span>");
  474. noteText=noteText.replace("%pali%","<span class='term_pali'>"+pali+"</span>");
  475. noteText=noteText.replace("%mean2%","<span class='term_mean2'>"+mean2+"</span>");
  476. noteText=noteText.replace("%note%","<span class='term_note'>"+""+"</span>");
  477. if(myterm){
  478. if(myterm.meaning!=mean){
  479. noteText=noteText.replace("%mymean%","<span class='term_mean_my'>"+myterm.meaning+"</span>");
  480. }
  481. else{
  482. noteText=noteText.replace("%mymean%","");
  483. }
  484. }
  485. else{
  486. noteText=noteText.replace("%mymean%","");
  487. }
  488. }
  489. else{
  490. noteText="<span class='"+linkclass+"' onclick=\""+str_term_fun_word_link+"('','"+termText+"')\">"+termText+"</span>";
  491. }
  492. $(this).html(noteText);
  493. }
  494. });
  495. }
  496. function term_show_win(guid,keyWord=""){
  497. if(guid==""){
  498. $(term_body).html("当前词条未创建。<br /><a onclick=\"term_add_new('"+keyWord+"')\">现在创建</a>");
  499. }
  500. else{
  501. let currWord = term_lookup_my_id(guid);
  502. if(currWord){
  503. let termString="";
  504. let pali=currWord.word;
  505. let pali_1= pali.substring(0,1).toUpperCase();
  506. pali=pali_1+pali.substring(1);
  507. let mean=currWord.meaning;
  508. let myterm=term_lookup_my(currWord.word);//我的术语字典
  509. termString+="<div class='term_win_mean'>"+pali+"</div>";
  510. termString+="<div class='term_win_pali'>意思:"+currWord.meaning+"</div>";
  511. termString+="<div class='term_win_mean2'>其他意思:"+currWord.other_meaning+"</div>";
  512. termString+="<div class='term_win_mymean'>我的词库:";
  513. if(myterm){
  514. termString+="<b>"+myterm.meaning+"</b> ";
  515. }
  516. else{
  517. termString+="<input type='input' placeholder='我的释义'>";
  518. }
  519. termString+="<span>其他:</span><span id='term_win_other_mean'></span>";
  520. termString+="</div>";
  521. if(currWord.note){
  522. termString+="<div class='term_win_note'>"+currWord.note+"</div>";
  523. }
  524. else{
  525. termString+="<div class='term_win_note'>Loading</div>";
  526. }
  527. $(term_body).html(termString);
  528. term_get_all_meaning(currWord.word);
  529. if(!currWord.note){
  530. $.get("term.php",
  531. {
  532. op:"load_id",
  533. id:currWord.guid
  534. },
  535. function(data,status,xhr){
  536. switch(status){
  537. case "success":
  538. try{
  539. let loadWord = JSON.parse(data);
  540. $("#term_win_note").html(loadWord[0].note);
  541. //修改内存数据
  542. for(let x in arrMyTerm){
  543. if(arrMyTerm[x].guid==loadWord[0].guid){
  544. arrMyTerm[x].note=loadWord[0].note;
  545. return;
  546. }
  547. }
  548. }
  549. catch(e){
  550. console.error(e+" data:"+data);
  551. }
  552. break;
  553. case "error":
  554. console.error("Error: "+xhr.status+": "+xhr.statusText);
  555. break;
  556. }
  557. });
  558. }
  559. }
  560. else{
  561. $(term_body).html("undefined guid");
  562. }
  563. }
  564. document.getElementById("term_win").style.display="flex";
  565. }
  566. function term_tmp(type,tmp){
  567. if(tmp=="new"){
  568. switch(type){
  569. case "a":
  570. strTermTanslationTmp=$("#term_my_tmp").val();
  571. break;
  572. case "a2":
  573. strTermTanslationTmp2=$("#term_my_tmp").val();
  574. break;
  575. }
  576. }
  577. else{
  578. switch(type){
  579. case "a":
  580. strTermTanslationTmp=tmp;
  581. break;
  582. case "a2":
  583. strTermTanslationTmp2=tmp;
  584. break;
  585. }
  586. }
  587. term_updata_translation();
  588. }
  589. function term_add_new(keyword){
  590. document.getElementById("term_win").style.display="none";
  591. tab_click_b('sys_term','tab_rb_sys_term',right_panal_slide_toggle,'tab_rb_sys_term');
  592. editor_show_right_tool_bar(true);
  593. note_lookup(keyword,"term_dict");
  594. }
  595. function term_show_new(){
  596. $("#term_new_recorder").slideToggle();
  597. }