reader.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  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 += "<a onclick='goto_nissaya(" + _reader_book + "," + strPara + ")'>" + gLocal.gui.show_nissaya + "</a>";
  124. html +=
  125. "<a onclick=\"copy_para_ref('" + _reader_book + "','" + strPara + "')\">" + gLocal.gui.copy_link + "</a>";
  126. html +=
  127. "<a onclick=\"copy_text('" +
  128. _reader_book +
  129. "','" +
  130. strPara +
  131. "')\">" +
  132. gLocal.gui.copy +
  133. "“" +
  134. gLocal.gui.pāli +
  135. "”</a>";
  136. html +=
  137. "<a onclick=\"add_to_list('" +
  138. _reader_book +
  139. "','" +
  140. strPara +
  141. "')\">" +
  142. gLocal.gui.add_to_edit_list +
  143. "</a>";
  144. html += "</div>";
  145. $(this).append(html);
  146. });
  147. }
  148. function junp_to_para(book, para) {
  149. let url = "../reader/?view=para&book=" + book + "&para=" + para + "&display=sent";
  150. location.assign(url);
  151. }
  152. function copy_para_ref(book, para) {
  153. let output = "";
  154. let currPara = para;
  155. for (const iterator of _sent_data.sentences) {
  156. if (iterator.book == book && iterator.paragraph == para) {
  157. output += "{{" + book + "-" + para + "-" + iterator.begin + "-" + iterator.end + "}}\n";
  158. }
  159. }
  160. output += "\n";
  161. copy_to_clipboard(output);
  162. }
  163. function reader_get_path() {
  164. $.get(
  165. "../reader/get_path.php",
  166. {
  167. book: _reader_book,
  168. para: _reader_para,
  169. },
  170. function (data) {
  171. $("#para_path").html(data);
  172. $("chapter").each(function () {
  173. //替换为本地语言字符串
  174. let title = $(this).text();
  175. let strLocalTitle = "";
  176. if (
  177. (strLocalTitle = term_lookup_my(
  178. title,
  179. _channal.split()[0],
  180. getCookie("userid"),
  181. getCookie("language")
  182. ))
  183. ) {
  184. $(this).html(strLocalTitle.word);
  185. } else if (
  186. (strLocalTitle = term_lookup_my_a(
  187. title,
  188. _channal.split()[0],
  189. getCookie("userid"),
  190. getCookie("language")
  191. ))
  192. ) {
  193. let newLocal = title.replace(strLocalTitle.word, strLocalTitle.meaning);
  194. $(this).html(newLocal);
  195. }
  196. });
  197. let suttaTitle = $("chapter").last().html();
  198. $("#article_title").html(suttaTitle);
  199. $("#page_title").text(suttaTitle);
  200. if (_reader_view == "chapter") {
  201. //$("chapter").last().hide();
  202. }
  203. }
  204. );
  205. }
  206. function palicanon_load_term() {
  207. $.get(
  208. "../term/term.php",
  209. {
  210. op: "my",
  211. },
  212. function (data) {
  213. arrMyTerm = JSON.parse(data);
  214. }
  215. );
  216. }
  217. function set_channal(channalid) {
  218. let url = "../reader/?view=" + _reader_view;
  219. if (_reader_book != -1) {
  220. url += "&book=" + _reader_book;
  221. }
  222. if (_reader_para != -1) {
  223. url += "&para=" + _reader_para;
  224. }
  225. if (_reader_begin != -1) {
  226. url += "&begin=" + _reader_begin;
  227. }
  228. if (_reader_end != -1) {
  229. url += "&end=" + _reader_end;
  230. }
  231. if (channalid != "") {
  232. url += "&channal=" + channalid;
  233. }
  234. if (_display != "") {
  235. url += "&display=" + _display;
  236. }
  237. location.assign(url);
  238. }
  239. function edit_wbw(book, para) {
  240. wbw_channal_list_open(book, [para]);
  241. }
  242. function show_dict(obj) {
  243. $("#main_view_shell").toggleClass("right_float_min");
  244. $("#main_view").toggleClass("main_view_right_float_min");
  245. $(obj).toggleClass("active");
  246. gBuildinDictIsOpen = $(obj).hasClass("active");
  247. }
  248. function close_right_float() {
  249. $("#main_view_shell").removeClass("right_float_min");
  250. $("#main_view_shell").removeClass("right_float_max");
  251. $("#main_view").removeClass("main_view_right_float_min");
  252. $("#main_view").removeClass("main_view_right_float_max");
  253. $("#max_right_float").show();
  254. $("#min_right_float").hide();
  255. $("#btn_show_dict").removeClass("active");
  256. gBuildinDictIsOpen = false;
  257. }
  258. function min_right_float(obj) {
  259. $(obj).siblings().show();
  260. $(obj).hide();
  261. $("#main_view_shell").addClass("right_float_min");
  262. $("#main_view_shell").removeClass("right_float_max");
  263. $("#main_view").addClass("main_view_right_float_min");
  264. $("#main_view").removeClass("main_view_right_float_max");
  265. }
  266. function max_right_float(obj) {
  267. $(obj).siblings().show();
  268. $(obj).hide();
  269. $("#main_view_shell").addClass("right_float_max");
  270. $("#main_view_shell").removeClass("right_float_min");
  271. $("#main_view").addClass("main_view_right_float_max");
  272. $("#main_view").removeClass("main_view_right_float_min");
  273. }