note.js 6.1 KB

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