reader.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. var _reader_view = "sent";
  2. var _reader_book = -1;
  3. var _reader_para = -1;
  4. var _reader_begin = -1;
  5. var _reader_end = -1;
  6. var _channal = "";
  7. var _lang = "";
  8. var _author = "";
  9. var _display = "para";
  10. var arrMyTerm = new Array();
  11. var _sent_data = new Array();
  12. palicanon_load_term();
  13. function reader_load() {
  14. $.get(
  15. "../reader/get_para.php",
  16. {
  17. view: _reader_view,
  18. book: _reader_book,
  19. para: _reader_para,
  20. begin: _reader_begin,
  21. end: _reader_end,
  22. },
  23. function (data) {
  24. _sent_data = JSON.parse(data);
  25. let tpl = "";
  26. let currPara = 0;
  27. $("#contents").html("");
  28. if (_sent_data.sentences.length > 0) {
  29. for (const iterator of _sent_data.sentences) {
  30. if (currPara != iterator.paragraph) {
  31. tpl += "\n";
  32. currPara = iterator.paragraph;
  33. tpl += "```para\n";
  34. tpl += currPara + "\n";
  35. tpl += "```\n";
  36. }
  37. tpl +=
  38. "{{" +
  39. iterator.book +
  40. "-" +
  41. iterator.paragraph +
  42. "-" +
  43. iterator.begin +
  44. "-" +
  45. iterator.end +
  46. "}}\n";
  47. }
  48. $("#contents").html(note_init(tpl));
  49. note_refresh_new();
  50. reader_draw_para_menu();
  51. //右侧目录
  52. let tocHtml = "";
  53. let tocNextMenu = "";
  54. if (_sent_data.toc.length > 0) {
  55. let firstLevel = _sent_data.toc[0].level;
  56. for (let index = 1; index < _sent_data.toc.length; index++) {
  57. const element = _sent_data.toc[index];
  58. tocHtml +=
  59. "<div class='reader_right_toc level_" +
  60. (element.level - firstLevel) +
  61. "'><a href='#para_" +
  62. element.paragraph +
  63. "'>" +
  64. element.toc +
  65. "</a></div>";
  66. tocNextMenu +=
  67. "<a href='../reader/?view=chapter&book=" +
  68. _reader_book +
  69. "&para=" +
  70. element.paragraph +
  71. "'>" +
  72. element.toc +
  73. "</a>";
  74. }
  75. $("#toc_content").html(tocHtml);
  76. if (tocNextMenu === "") {
  77. $("#para_path_next_level").hide();
  78. } else {
  79. $("#toc_next_menu").html(tocNextMenu);
  80. $("#para_path_next_level").show();
  81. }
  82. }
  83. }
  84. if (_sent_data.head == 1 || _sent_data.sentences.length == 0) {
  85. //渲染目录
  86. tpl = "<h2>Table of Content</h2>";
  87. if (_sent_data.toc.length > 0) {
  88. let firstLevel = _sent_data.toc[0].level;
  89. for (let index = 1; index < _sent_data.toc.length; index++) {
  90. const element = _sent_data.toc[index];
  91. if (element.level < 8) {
  92. tpl +=
  93. "<div class='reader_main_toc level_" +
  94. (element.level - firstLevel) +
  95. "'><a href='../reader/?view=chapter&book=" +
  96. _reader_book +
  97. "&para=" +
  98. element.paragraph +
  99. "&display=" +
  100. _display +
  101. "'>" +
  102. element.toc +
  103. "</a></div>";
  104. }
  105. }
  106. }
  107. $("#contents_toc").html(tpl);
  108. }
  109. }
  110. );
  111. reader_get_path();
  112. }
  113. function reader_draw_para_menu() {
  114. $(".language-para").each(function () {
  115. let strPara = $(this).text();
  116. $(this).addClass("case_dropdown");
  117. let html = "<a name='para_" + strPara + "'></a>";
  118. html += "<div class='case_dropdown-content para_menu'>";
  119. if (typeof _reader_view != "undefined" && _reader_view != "para") {
  120. html += "<a onclick=\"junp_to_para('" + _reader_book + "','" + strPara + "')\">仅显示此段</a>";
  121. }
  122. html += "<a onclick=\"edit_wbw('" + _reader_book + "','" + strPara + "')\">" + gLocal.gui.edit_now + "</a>";
  123. html +=
  124. "<a onclick=\"copy_para_ref('" + _reader_book + "','" + strPara + "')\">" + gLocal.gui.copy_link + "</a>";
  125. html +=
  126. "<a onclick=\"copy_text('" +
  127. _reader_book +
  128. "','" +
  129. strPara +
  130. "')\">" +
  131. gLocal.gui.copy +
  132. "“" +
  133. gLocal.gui.pāli +
  134. "”</a>";
  135. html +=
  136. "<a onclick=\"add_to_list('" +
  137. _reader_book +
  138. "','" +
  139. strPara +
  140. "')\">" +
  141. gLocal.gui.add_to_edit_list +
  142. "</a>";
  143. html += "</div>";
  144. $(this).append(html);
  145. });
  146. }
  147. function junp_to_para(book, para) {
  148. let url = "../reader/?view=para&book=" + book + "&para=" + para + "&display=sent";
  149. location.assign(url);
  150. }
  151. function copy_para_ref(book, para) {
  152. let output = "";
  153. let currPara = para;
  154. for (const iterator of _sent_data.sentences) {
  155. if (iterator.book == book && iterator.paragraph == para) {
  156. output += "{{" + book + "-" + para + "-" + iterator.begin + "-" + iterator.end + "}}\n";
  157. }
  158. }
  159. output += "\n";
  160. copy_to_clipboard(output);
  161. }
  162. function reader_get_path() {
  163. $.get(
  164. "../reader/get_path.php",
  165. {
  166. book: _reader_book,
  167. para: _reader_para,
  168. },
  169. function (data) {
  170. $("#para_path").html(data);
  171. $("chapter").each(function () {
  172. //替换为本地语言字符串
  173. let title = $(this).text();
  174. let strLocalTitle = "";
  175. if (
  176. (strLocalTitle = term_lookup_my(
  177. title,
  178. _channal.split()[0],
  179. getCookie("userid"),
  180. getCookie("language")
  181. ))
  182. ) {
  183. $(this).html(strLocalTitle.word);
  184. } else if (
  185. (strLocalTitle = term_lookup_my_a(
  186. title,
  187. _channal.split()[0],
  188. getCookie("userid"),
  189. getCookie("language")
  190. ))
  191. ) {
  192. let newLocal = title.replace(strLocalTitle.word, strLocalTitle.meaning);
  193. $(this).html(newLocal);
  194. }
  195. });
  196. let suttaTitle = $("chapter").last().html();
  197. $("#article_title").html(suttaTitle);
  198. if (_reader_view == "chapter") {
  199. //$("chapter").last().hide();
  200. }
  201. }
  202. );
  203. }
  204. function palicanon_load_term() {
  205. $.get(
  206. "../term/term.php",
  207. {
  208. op: "my",
  209. },
  210. function (data) {
  211. arrMyTerm = JSON.parse(data);
  212. }
  213. );
  214. }
  215. function set_channal(channalid) {
  216. let url = "../reader/?view=" + _reader_view;
  217. if (_reader_book != -1) {
  218. url += "&book=" + _reader_book;
  219. }
  220. if (_reader_para != -1) {
  221. url += "&para=" + _reader_para;
  222. }
  223. if (_reader_begin != -1) {
  224. url += "&begin=" + _reader_begin;
  225. }
  226. if (_reader_end != -1) {
  227. url += "&end=" + _reader_end;
  228. }
  229. if (channalid != "") {
  230. url += "&channal=" + channalid;
  231. }
  232. if (_display != "") {
  233. url += "&display=" + _display;
  234. }
  235. location.assign(url);
  236. }
  237. function edit_wbw(book, para) {
  238. wbw_channal_list_open(book, [para]);
  239. }