note.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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. var _channal = "";
  22. var _lang = "";
  23. var _author = "";
  24. function note_init(input) {
  25. let output = "<div>";
  26. let arrInput = input.split("\n");
  27. for (x in arrInput) {
  28. if (arrInput[x].slice(0, 2) == "==" && arrInput[x].slice(-2) == "==") {
  29. output += "</div></div>";
  30. output += '<div class="submenu1">';
  31. output +=
  32. '<p class="submenu_title1" onclick="submenu_show_detail(this)">';
  33. output += arrInput[x].slice(2, -2);
  34. output += '<svg class="icon" style="transform: rotate(45deg);">';
  35. output += '<use xlink:href="svg/icon.svg#ic_add"></use>';
  36. output += "</svg>";
  37. output += "</p>";
  38. output += '<div class="submenu_details1" >';
  39. } else {
  40. let row = arrInput[x];
  41. row = row.replace(/\{\{/g, '<note info="');
  42. row = row.replace(/\}\}/g, '"></note>');
  43. if (row.match("{") && row.match("}")) {
  44. row = row.replace("{", "<strong>");
  45. row = row.replace("}", "</strong>");
  46. }
  47. output += row;
  48. }
  49. }
  50. output += "</div>";
  51. return output;
  52. }
  53. //
  54. function note_refresh_new() {
  55. let objNotes = document.querySelectorAll("note");
  56. let arrSentInfo = new Array();
  57. for (const iterator of objNotes) {
  58. let id = iterator.id;
  59. if (id == null || id == "") {
  60. id = com_guid();
  61. iterator.id = id;
  62. let info = iterator.getAttributeNode("info").value;
  63. if (info && info != "") {
  64. arrSentInfo.push({ id: id, data: info });
  65. }
  66. }
  67. }
  68. if (arrSentInfo.length > 0) {
  69. let setting = new Object();
  70. setting.lang = "";
  71. setting.channal = _channal;
  72. $.post(
  73. "../term/note.php",
  74. {
  75. setting: JSON.stringify(setting),
  76. data: JSON.stringify(arrSentInfo),
  77. },
  78. function (data, status) {
  79. if (status == "success") {
  80. try {
  81. let arrData = JSON.parse(data);
  82. for (const iterator of arrData) {
  83. let id = iterator.id;
  84. let strHtml = note_json_html(iterator);
  85. $("#" + id).html(strHtml);
  86. }
  87. $(".palitext").click(function () {
  88. let sentid = $(this).parent().attr("info").split("-");
  89. window.open(
  90. "../pcdl/reader.php?view=sent&book=" +
  91. sentid[0] +
  92. "&para=" +
  93. sentid[1] +
  94. "&begin=" +
  95. sentid[2] +
  96. "&end=" +
  97. sentid[3]
  98. );
  99. });
  100. note_ref_init();
  101. term_get_dict();
  102. note_channal_list();
  103. } catch (e) {
  104. console.error(e);
  105. }
  106. }
  107. }
  108. );
  109. }
  110. }
  111. function note_channal_list() {
  112. console.log("note_channal_list start");
  113. let objNotes = document.querySelectorAll("note");
  114. let arrSentInfo = new Array();
  115. for (const iterator of objNotes) {
  116. {
  117. let info = iterator.getAttributeNode("info").value;
  118. if (info && info != "") {
  119. arrSentInfo.push({ id: "", data: info });
  120. }
  121. }
  122. }
  123. if (arrSentInfo.length > 0) {
  124. $.post(
  125. "../term/channal_list.php",
  126. {
  127. setting: "",
  128. data: JSON.stringify(arrSentInfo),
  129. },
  130. function (data, status) {
  131. if (status == "success") {
  132. try {
  133. let arrData = JSON.parse(data);
  134. let strHtml = "";
  135. for (const iterator of arrData) {
  136. strHtml += render_channal_list(iterator);
  137. }
  138. $("#channal_list").html(strHtml);
  139. } catch (e) {
  140. console.error(e);
  141. }
  142. }
  143. }
  144. );
  145. }
  146. }
  147. function render_channal_list(channalinfo) {
  148. let output = "";
  149. output += "<div class='list_with_head'>";
  150. output += "<div class='head'>";
  151. output += "<span class='head_img'>";
  152. output += channalinfo.nickname.slice(0, 2);
  153. output += "</span>";
  154. output += "</div>";
  155. output += "<div>";
  156. output += "<div>";
  157. output += "<a href='../wiki/wiki.php?word=" + _word;
  158. output += "&channal=" + channalinfo.id + "' >";
  159. output += channalinfo["nickname"];
  160. output += "/" + channalinfo["name"];
  161. output += "</a>";
  162. output += "</div>";
  163. output += "<div>";
  164. output += "@" + channalinfo["username"];
  165. output += "</div>";
  166. output += "</div>";
  167. output += "</div>";
  168. return output;
  169. }
  170. function note_ref_init() {
  171. $("chapter").click(function () {
  172. let bookid = $(this).attr("book");
  173. let para = $(this).attr("para");
  174. window.open(
  175. "../pcdl/reader.php?view=chapter&book=" + bookid + "&para=" + para,
  176. "_blank"
  177. );
  178. });
  179. $("para").click(function () {
  180. let bookid = $(this).attr("book");
  181. let para = $(this).attr("para");
  182. window.open(
  183. "../pcdl/reader.php?view=para&book=" + bookid + "&para=" + para,
  184. "_blank"
  185. );
  186. });
  187. }
  188. /*
  189. id
  190. palitext
  191. tran
  192. ref
  193. */
  194. function note_json_html(in_json) {
  195. let output = "";
  196. output += "<div class='palitext'>" + in_json.palitext + "</div>";
  197. output +=
  198. "<div class='tran'>" + term_std_str_to_tran(in_json.tran) + "</div>";
  199. output += "<div class='ref'>" + in_json.ref + "</div>";
  200. return output;
  201. }