note.js 7.1 KB

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