note.js 6.1 KB

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