2
0

reader.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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_para('" + _reader_book + "','" + strPara + "')\">仅显示此段</a>";
  88. }
  89. html += "<a onclick=\"edit_wbw('" + _reader_book + "','" + strPara + "')\">" + gLocal.gui.edit_now + "</a>";
  90. html += "<a onclick=\"copy_para_ref('" + _reader_book + "','" + strPara + "')\">" + gLocal.gui.copy_link + "</a>";
  91. html += "<a onclick=\"copy_text('" + _reader_book + "','" + strPara + "')\">" + gLocal.gui.copy + "“" + gLocal.gui.pāli + "”</a>";
  92. html += "<a onclick=\"add_to_list('" + _reader_book + "','" + strPara + "')\">" + gLocal.gui.add_to_edit_list + "</a>";
  93. html += "</div>";
  94. $(this).append(html);
  95. });
  96. }
  97. function junp_to_para(book, para) {
  98. let url = "../reader/?view=para&book=" + book + "&para=" + para + "&display=sent";
  99. location.assign(url);
  100. }
  101. function copy_para_ref(book, para) {
  102. let output = "";
  103. let currPara = para;
  104. for (const iterator of _sent_data.sentences) {
  105. if (iterator.book == book && iterator.paragraph == para) {
  106. output += "{{" + book + "-" + para + "-" + iterator.begin + "-" + iterator.end + "}}\n";
  107. }
  108. }
  109. output += "\n";
  110. copy_to_clipboard(output)
  111. }
  112. function reader_get_path() {
  113. $.get(
  114. "../reader/get_path.php",
  115. {
  116. book: _reader_book,
  117. para: _reader_para,
  118. },
  119. function (data) {
  120. $("#para_path").html(data);
  121. $("chapter").each(function () {
  122. let title = $(this).text();
  123. let strLocalTitle = "";
  124. if (strLocalTitle = term_lookup_my(title, _channal.split()[0], getCookie("userid"), getCookie("language"))) {
  125. $(this).html(strLocalTitle.word);
  126. }
  127. else if (strLocalTitle = term_lookup_my_a(title, _channal.split()[0], getCookie("userid"), getCookie("language"))) {
  128. let newLocal = title.replace(strLocalTitle.word, strLocalTitle.meaning);
  129. $(this).html(newLocal);
  130. }
  131. });
  132. let suttaTitle = $("chapter").last().html();
  133. $("#article_title").html(suttaTitle);
  134. if (_reader_view == "chapter") {
  135. //$("chapter").last().hide();
  136. }
  137. }
  138. );
  139. }
  140. function palicanon_load_term() {
  141. $.get(
  142. "../term/term.php",
  143. {
  144. op: "my"
  145. },
  146. function (data) {
  147. arrMyTerm = JSON.parse(data);
  148. }
  149. );
  150. }
  151. function set_channal(channalid) {
  152. let url = "../reader/?view=" + _reader_view;
  153. if (_reader_book != -1) {
  154. url += "&book=" + _reader_book;
  155. }
  156. if (_reader_para != -1) {
  157. url += "&para=" + _reader_para;
  158. }
  159. if (_reader_begin != -1) {
  160. url += "&begin=" + _reader_begin;
  161. }
  162. if (_reader_end != -1) {
  163. url += "&end=" + _reader_end;
  164. }
  165. if (channalid != "") {
  166. url += "&channal=" + channalid;
  167. }
  168. if (_display != "") {
  169. url += "&display=" + _display;
  170. }
  171. location.assign(url);
  172. }