note.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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 +=
  29. '<p class="submenu_title1" onclick="submenu_show_detail(this)">';
  30. output += arrInput[x].slice(2, -2);
  31. output += '<svg class="icon" style="transform: rotate(45deg);">';
  32. output += '<use xlink:href="svg/icon.svg#ic_add"></use>';
  33. output += "</svg>";
  34. output += "</p>";
  35. output += '<div class="submenu_details1" >';
  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. let objNotes = document.querySelectorAll("note");
  53. let arrSentInfo = new Array();
  54. for (const iterator of objNotes) {
  55. let id = iterator.id;
  56. if (id == null || id == "") {
  57. id = com_guid();
  58. iterator.id = id;
  59. let info = iterator.getAttributeNode("info").value;
  60. if (info && info != "") {
  61. arrSentInfo.push({ id: id, data: info });
  62. }
  63. }
  64. {
  65. $.post(
  66. "../term/note.php",
  67. {
  68. data: JSON.stringify(arrSentInfo),
  69. },
  70. function (data, status) {
  71. if (status == "success") {
  72. try {
  73. let arrData = JSON.parse(data);
  74. for (const iterator of arrData) {
  75. let id = iterator.id;
  76. let strHtml = note_json_html(iterator);
  77. $("#" + id).html(strHtml);
  78. }
  79. note_ref_init();
  80. term_get_dict();
  81. } catch (e) {
  82. console.error(e);
  83. }
  84. }
  85. }
  86. );
  87. }
  88. }
  89. }
  90. function note_ref_init() {
  91. $("chapter").click(function () {
  92. let bookid = $(this).attr("book");
  93. let para = $(this).attr("para");
  94. window.open(
  95. "../pcdl/reader.php?view=chapter&book=" + bookid + "&para=" + para,
  96. "_blank"
  97. );
  98. });
  99. $("para").click(function () {
  100. let bookid = $(this).attr("book");
  101. let para = $(this).attr("para");
  102. window.open(
  103. "../pcdl/reader.php?view=para&book=" + bookid + "&para=" + para,
  104. "_blank"
  105. );
  106. });
  107. }
  108. /*
  109. id
  110. palitext
  111. tran
  112. ref
  113. */
  114. function note_json_html(in_json) {
  115. let output = "";
  116. output += "<div class='palitext'>" + in_json.palitext + "</div>";
  117. output +=
  118. "<div class='tran'>" + term_std_str_to_tran(in_json.tran) + "</div>";
  119. output += "<div class='ref'>" + in_json.ref + "</div>";
  120. return output;
  121. }