reader.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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 += "{{" + iterator.book + "-" + iterator.paragraph + "-" + iterator.begin + "-" + iterator.end + "}}\n";
  38. }
  39. $("#contents").html(note_init(tpl));
  40. note_refresh_new();
  41. reader_draw_para_menu();
  42. //右侧目录
  43. let tocHtml = "";
  44. let tocNextMenu = "";
  45. if (_sent_data.toc.length > 0) {
  46. let firstLevel = _sent_data.toc[0].level;
  47. for (let index = 1; index < _sent_data.toc.length; index++) {
  48. const element = _sent_data.toc[index];
  49. tocHtml += "<div class='reader_right_toc level_" + (element.level - firstLevel) + "'><a href='#para_" + element.paragraph + "'>" + element.toc + "</a></div>";
  50. tocNextMenu += "<a href='../reader/?view=chapter&book=" + _reader_book + "&para=" + element.paragraph + "'>" + element.toc + "</a>";
  51. }
  52. $("#toc_content").html(tocHtml);
  53. if (tocNextMenu === "") {
  54. $("#para_path_next_level").hide();
  55. }
  56. else {
  57. $("#toc_next_menu").html(tocNextMenu);
  58. $("#para_path_next_level").show();
  59. }
  60. }
  61. }
  62. if (_sent_data.head == 1 || _sent_data.sentences.length == 0) {
  63. //渲染目录
  64. tpl = "<h2>Table of Content</h2>";
  65. if (_sent_data.toc.length > 0) {
  66. let firstLevel = _sent_data.toc[0].level;
  67. for (let index = 1; index < _sent_data.toc.length; index++) {
  68. const element = _sent_data.toc[index];
  69. if (element.level < 8) {
  70. tpl += "<div class='reader_main_toc level_" + (element.level - firstLevel) + "'><a href='../reader/?view=chapter&book=" + _reader_book + "&para=" + element.paragraph + "&display=" + _display + "'>" + element.toc + "</a></div>";
  71. }
  72. }
  73. }
  74. $("#contents_toc").html(tpl);
  75. }
  76. }
  77. );
  78. reader_get_path();
  79. }
  80. function reader_draw_para_menu() {
  81. $(".language-para").each(function () {
  82. let strPara = $(this).text();
  83. $(this).addClass("case_dropdown");
  84. let html = "<a name='para_" + strPara + "'></a>";
  85. html += "<div class='case_dropdown-content para_menu'>";
  86. if (typeof _reader_view != "undefined" && _reader_view != "para") {
  87. html += "<a onclick='junp_to('" + _reader_book + "','" + strPara + "')'>跳转至此段</a>";
  88. }
  89. html += "<a onclick=\"copy_para_ref('" + _reader_book + "','" + strPara + "')\">" + gLocal.gui.copy_link + "</a>";
  90. html += "<a onclick='copy_text(this)'>" + gLocal.gui.copy + "“" + gLocal.gui.pāli + "”</a>";
  91. html += "<a onclick='add_to_list()'>" + gLocal.gui.add_to_edit_list + "</a>";
  92. html += "</div>";
  93. $(this).append(html);
  94. });
  95. }
  96. function copy_para_ref(book, para) {
  97. let output = "";
  98. let currPara = para;
  99. for (const iterator of _sent_data.sentences) {
  100. if (iterator.book == book && iterator.paragraph == para) {
  101. output += "{{" + book + "-" + para + "-" + iterator.begin + "-" + iterator.end + "}}\n";
  102. }
  103. }
  104. output += "\n";
  105. copy_to_clipboard(output)
  106. }
  107. function reader_get_path() {
  108. $.get(
  109. "../reader/get_path.php",
  110. {
  111. book: _reader_book,
  112. para: _reader_para,
  113. },
  114. function (data) {
  115. $("#para_path").html(data);
  116. $("chapter").each(function () {
  117. let title = $(this).text();
  118. let strLocalTitle = "";
  119. if (strLocalTitle = term_lookup_my(title, _channal.split()[0], getCookie("userid"), getCookie("language"))) {
  120. $(this).html(strLocalTitle.word);
  121. }
  122. else if (strLocalTitle = term_lookup_my_a(title, _channal.split()[0], getCookie("userid"), getCookie("language"))) {
  123. let newLocal = title.replace(strLocalTitle.word, strLocalTitle.meaning);
  124. $(this).html(newLocal);
  125. }
  126. });
  127. let suttaTitle = $("chapter").last().html();
  128. $("#article_title").html(suttaTitle);
  129. if (_reader_view == "chapter") {
  130. //$("chapter").last().hide();
  131. }
  132. }
  133. );
  134. }
  135. function palicanon_load_term() {
  136. $.get(
  137. "../term/term.php",
  138. {
  139. op: "my"
  140. },
  141. function (data) {
  142. arrMyTerm = JSON.parse(data);
  143. }
  144. );
  145. }
  146. function set_channal(channalid) {
  147. let url = "../reader/?view=" + _reader_view;
  148. if (_reader_book != -1) {
  149. url += "&book=" + _reader_book;
  150. }
  151. if (_reader_para != -1) {
  152. url += "&para=" + _reader_para;
  153. }
  154. if (_reader_begin != -1) {
  155. url += "&begin=" + _reader_begin;
  156. }
  157. if (_reader_end != -1) {
  158. url += "&end=" + _reader_end;
  159. }
  160. if (channalid != "") {
  161. url += "&channal=" + channalid;
  162. }
  163. if (_display != "") {
  164. url += "&display=" + _display;
  165. }
  166. location.assign(url);
  167. }