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