note.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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. note_ref_init();
  88. term_get_dict();
  89. note_channal_list();
  90. } catch (e) {
  91. console.error(e);
  92. }
  93. }
  94. }
  95. );
  96. }
  97. }
  98. function note_channal_list() {
  99. console.log("note_channal_list start");
  100. let objNotes = document.querySelectorAll("note");
  101. let arrSentInfo = new Array();
  102. for (const iterator of objNotes) {
  103. {
  104. let info = iterator.getAttributeNode("info").value;
  105. if (info && info != "") {
  106. arrSentInfo.push({ id: "", data: info });
  107. }
  108. }
  109. }
  110. if (arrSentInfo.length > 0) {
  111. $.post(
  112. "../term/channal_list.php",
  113. {
  114. setting: "",
  115. data: JSON.stringify(arrSentInfo),
  116. },
  117. function (data, status) {
  118. if (status == "success") {
  119. try {
  120. let arrData = JSON.parse(data);
  121. let strHtml = "";
  122. for (const iterator of arrData) {
  123. strHtml += render_channal_list(iterator);
  124. }
  125. $("#channal_list").html(strHtml);
  126. } catch (e) {
  127. console.error(e);
  128. }
  129. }
  130. }
  131. );
  132. }
  133. }
  134. function render_channal_list(channalinfo) {
  135. let output = "";
  136. output += "<div class='list_with_head'>";
  137. output += "<div class='head'>";
  138. output += "<span class='head_img'>";
  139. output += channalinfo.nickname.slice(0, 2);
  140. output += "</span>";
  141. output += "</div>";
  142. output += "<div>";
  143. output += "<div>";
  144. output += "<a href='../wiki/wiki.php?word=" + _word;
  145. output += "&channal=" + channalinfo.id + "' >";
  146. output += channalinfo["nickname"];
  147. output += "/" + channalinfo["name"];
  148. output += "</a>";
  149. output += "</div>";
  150. output += "<div>";
  151. output += "@" + channalinfo["username"];
  152. output += "</div>";
  153. output += "</div>";
  154. output += "</div>";
  155. return output;
  156. }
  157. function note_ref_init() {
  158. $("chapter").click(function () {
  159. let bookid = $(this).attr("book");
  160. let para = $(this).attr("para");
  161. window.open(
  162. "../pcdl/reader.php?view=chapter&book=" + bookid + "&para=" + para,
  163. "_blank"
  164. );
  165. });
  166. $("para").click(function () {
  167. let bookid = $(this).attr("book");
  168. let para = $(this).attr("para");
  169. window.open(
  170. "../pcdl/reader.php?view=para&book=" + bookid + "&para=" + para,
  171. "_blank"
  172. );
  173. });
  174. }
  175. /*
  176. id
  177. palitext
  178. tran
  179. ref
  180. */
  181. function note_json_html(in_json) {
  182. let output = "";
  183. output += "<div class='palitext'>" + in_json.palitext + "</div>";
  184. output +=
  185. "<div class='tran'>" + term_std_str_to_tran(in_json.tran) + "</div>";
  186. output += "<div class='ref'>" + in_json.ref + "</div>";
  187. return output;
  188. }