note.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*
  2. {{203-1654-23-45@11@en@*}}
  3. <note>203-1654-23-45@11@en@*</note>
  4. <note id=guid book=203 para=1654 begin=23 end=45 author=11 lang=en tag=*></note>
  5. <note id=guid book=203 para=1654 begin=23 end=45 author=11 lang=en tag=*>
  6. <div class=text>
  7. pali text
  8. </div>
  9. <tran>
  10. </tran>
  11. <ref>
  12. </ref>
  13. </note>
  14. */
  15. /*
  16. 解析百科字符串
  17. {{203-1654-23-45@11@en@*}}
  18. <note id=12345 info="203-1654-23-45@11@en@*"><note>
  19. <note id="guid" book=203 para=1654 begin=23 end=45 author=11 lang=en tag=*></note>
  20. */
  21. function note_init(input){
  22. let output="<div>";
  23. let arrInput = input.split("\n");
  24. for(x in arrInput){
  25. if(arrInput[x].slice(0,2)=="==" && arrInput[x].slice(-2)=="=="){
  26. output += "</div></div>";
  27. output += "<div class=\"submenu1\">";
  28. output += "<p class=\"submenu_title1\" onclick=\"submenu_show_detail(this)\">";
  29. output += arrInput[x].slice(2,-2);
  30. output += "<svg class=\"icon\" style=\"transform: rotate(45deg);\">";
  31. output += "<use xlink:href=\"svg/icon.svg#ic_add\"></use>";
  32. output += "</svg>";
  33. output += "</p>";
  34. output += "<div class=\"submenu_details1\" >";
  35. }
  36. else{
  37. let row=arrInput[x];
  38. row = row.replace(/\{\{/g,"<note info=\"");
  39. row = row.replace(/\}\}/g,"\"></note>");
  40. if(row.match("{") && row.match("}")){
  41. row=row.replace("{","<strong>");
  42. row=row.replace("}","</strong>");
  43. }
  44. output+=row;
  45. }
  46. }
  47. output += "</div>";
  48. return(output);
  49. }
  50. //
  51. function note_refresh_new(){
  52. $("note").each(function(index,element){
  53. let html=$(this).html();
  54. let id=$(this).attr("id");
  55. if(id==null || id==""){
  56. id=com_guid();
  57. $(this).attr("id",id);
  58. let info=$(this).attr("info");
  59. if(info && info!=""){
  60. $.get("../term/note.php",
  61. {
  62. id:id,
  63. info:info,
  64. },
  65. function(data,status){
  66. try{
  67. let arrData=JSON.parse(data);
  68. let id=arrData.id;
  69. let strHtml = note_json_html(arrData);
  70. $("#"+id).html(strHtml);
  71. term_updata_translation();
  72. }
  73. catch(e){
  74. console.error(e);
  75. }
  76. }
  77. );
  78. }
  79. }
  80. });
  81. }
  82. /*
  83. id
  84. palitext
  85. tran
  86. ref
  87. */
  88. function note_json_html(in_json){
  89. let output="";
  90. output += "<div class='palitext'>"+in_json.palitext+"</div>";
  91. output += "<div class='tran'>"+term_std_str_to_tran(in_json.tran)+"</div>";
  92. output += "<div class='ref'>"+in_json.ref+"</div>";
  93. return(output);
  94. }