note.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. var _display = "";
  2. var _word = "";
  3. var _channal = "";
  4. var _lang = "";
  5. var _author = "";
  6. /*
  7. {{203-1654-23-45@11@en@*}}
  8. <note>203-1654-23-45@11@en@*</note>
  9. <note id=guid book=203 para=1654 begin=23 end=45 author=11 lang=en tag=*></note>
  10. <note id=guid book=203 para=1654 begin=23 end=45 author=11 lang=en tag=*>
  11. <div class=text>
  12. pali text
  13. </div>
  14. <tran>
  15. </tran>
  16. <ref>
  17. </ref>
  18. </note>
  19. */
  20. /*
  21. 解析百科字符串
  22. {{203-1654-23-45@11@en@*}}
  23. <note id=12345 info="203-1654-23-45@11@en@*"><note>
  24. <note id="guid" book=203 para=1654 begin=23 end=45 author=11 lang=en tag=*></note>
  25. */
  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 =
  116. "<pali book='" +
  117. iterator.book +
  118. "' para='" +
  119. iterator.para +
  120. "' begin='" +
  121. iterator.begin +
  122. "' end='" +
  123. iterator.end +
  124. "' >" +
  125. iterator.palitext +
  126. "</pali>";
  127. let divPali = $("#" + id)
  128. .parent()
  129. .children(".palitext");
  130. if (divPali.length == 0) {
  131. $("#" + id)
  132. .parent()
  133. .prepend("<div class='palitext'></div>");
  134. }
  135. $("#" + id)
  136. .parent()
  137. .children(".palitext")
  138. .first()
  139. .append(strPalitext);
  140. let htmlTran =
  141. "<span class='tran'>" +
  142. marked(term_std_str_to_tran(iterator.tran)) +
  143. "</span>";
  144. $("#" + id).html(htmlTran);
  145. } else {
  146. strHtml += note_json_html(iterator);
  147. $("#" + id).html(strHtml);
  148. }
  149. }
  150. $(".palitext").click(function () {
  151. let sentid = $(this).parent().attr("info").split("-");
  152. window.open(
  153. "../pcdl/reader.php?view=sent&book=" +
  154. sentid[0] +
  155. "&para=" +
  156. sentid[1] +
  157. "&begin=" +
  158. sentid[2] +
  159. "&end=" +
  160. sentid[3]
  161. );
  162. });
  163. $("pali").click(function () {
  164. window.open(
  165. "../pcdl/reader.php?view=sent&book=" +
  166. $(this).attr("book") +
  167. "&para=" +
  168. $(this).attr("para") +
  169. "&begin=" +
  170. $(this).attr("begin") +
  171. "&end=" +
  172. $(this).attr("end")
  173. );
  174. });
  175. note_ref_init();
  176. term_get_dict();
  177. note_channal_list();
  178. } catch (e) {
  179. console.error(e);
  180. }
  181. }
  182. }
  183. );
  184. }
  185. }
  186. function note_channal_list() {
  187. console.log("note_channal_list start");
  188. let objNotes = document.querySelectorAll("note");
  189. let arrSentInfo = new Array();
  190. for (const iterator of objNotes) {
  191. {
  192. let info = iterator.getAttributeNode("info").value;
  193. if (info && info != "") {
  194. arrSentInfo.push({ id: "", data: info });
  195. }
  196. }
  197. }
  198. if (arrSentInfo.length > 0) {
  199. $.post(
  200. "../term/channal_list.php",
  201. {
  202. setting: "",
  203. data: JSON.stringify(arrSentInfo),
  204. },
  205. function (data, status) {
  206. if (status == "success") {
  207. try {
  208. let arrData = JSON.parse(data);
  209. let strHtml = "";
  210. for (const iterator of arrData) {
  211. strHtml += render_channal_list(iterator);
  212. }
  213. $("#channal_list").html(strHtml);
  214. } catch (e) {
  215. console.error(e);
  216. }
  217. }
  218. }
  219. );
  220. }
  221. }
  222. function render_channal_list(channalinfo) {
  223. let output = "";
  224. output += "<div class='list_with_head'>";
  225. output += "<div class='head'>";
  226. output += "<span class='head_img'>";
  227. output += channalinfo.nickname.slice(0, 2);
  228. output += "</span>";
  229. output += "</div>";
  230. output += "<div>";
  231. output += "<div>";
  232. // output += "<a href='../wiki/wiki.php?word=" + _word;
  233. // output += "&channal=" + channalinfo.id + "' >";
  234. output += "<a onclick=\"set_channal('" + channalinfo.id + "')\">";
  235. output += channalinfo["nickname"];
  236. output += "/" + channalinfo["name"];
  237. output += "</a>";
  238. output += "</div>";
  239. output += "<div>";
  240. output += "@" + channalinfo["username"];
  241. output += "</div>";
  242. output += "</div>";
  243. output += "</div>";
  244. return output;
  245. }
  246. function note_ref_init() {
  247. $("chapter").click(function () {
  248. let bookid = $(this).attr("book");
  249. let para = $(this).attr("para");
  250. window.open(
  251. "../pcdl/reader.php?view=chapter&book=" + bookid + "&para=" + para,
  252. "_blank"
  253. );
  254. });
  255. $("para").click(function () {
  256. let bookid = $(this).attr("book");
  257. let para = $(this).attr("para");
  258. window.open(
  259. "../pcdl/reader.php?view=para&book=" + bookid + "&para=" + para,
  260. "_blank"
  261. );
  262. });
  263. }
  264. /*
  265. id
  266. palitext
  267. tran
  268. ref
  269. */
  270. function note_json_html(in_json) {
  271. let output = "";
  272. output += "<div class='palitext'>" + in_json.palitext + "</div>";
  273. output +=
  274. "<div class='tran'>" +
  275. marked(term_std_str_to_tran(in_json.tran)) +
  276. "</div>";
  277. output += "<div class='ref'>" + in_json.ref;
  278. output +=
  279. "<span class='sent_no'>" +
  280. in_json.book +
  281. "-" +
  282. in_json.para +
  283. "-" +
  284. in_json.begin +
  285. "-" +
  286. in_json.end +
  287. "<span>" +
  288. "</div>";
  289. return output;
  290. }