article.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. var _articel_id = "";
  2. var _channal = "";
  3. var _lang = "";
  4. var _author = "";
  5. var _display = "";
  6. var _collect_id = "";
  7. var _collection_id = "";
  8. function article_onload() {
  9. historay_init();
  10. }
  11. function articel_load(id, collection_id) {
  12. if (id == "") {
  13. return;
  14. }
  15. $.get(
  16. "../article/get.php",
  17. {
  18. id: id,
  19. collection_id: collection_id,
  20. setting: "",
  21. },
  22. function (data, status) {
  23. if (status == "success") {
  24. try {
  25. let result = JSON.parse(data);
  26. if (result) {
  27. $("#article_title").html(result.title);
  28. $("#page_title").text(result.title);
  29. $("#article_subtitle").html(result.subtitle);
  30. $("#article_author").html(result.username.nickname + "@" + result.username.username);
  31. $("#contents").html(note_init(result.content));
  32. note_refresh_new();
  33. }
  34. } catch (e) {
  35. console.error(e);
  36. }
  37. } else {
  38. console.error("ajex error");
  39. }
  40. }
  41. );
  42. }
  43. function collect_load(id) {
  44. if (id == "") {
  45. return;
  46. }
  47. $.get(
  48. "../article/collect_get.php",
  49. {
  50. id: id,
  51. setting: "",
  52. },
  53. function (data, status) {
  54. if (status == "success") {
  55. try {
  56. let result = JSON.parse(data);
  57. if (result) {
  58. $("#article_title").html(result.title);
  59. $("#page_title").text(result.title);
  60. if (result.subtitle) {
  61. $("#article_subtitle").html(result.subtitle);
  62. }
  63. $("#article_author").html(result.username.nickname + "@" + result.username.username);
  64. $("#contents").html(marked(result.summary));
  65. let article_list = JSON.parse(result.article_list);
  66. render_article_list(article_list, id);
  67. }
  68. } catch (e) {
  69. console.error(e);
  70. }
  71. } else {
  72. console.error("ajex error");
  73. }
  74. }
  75. );
  76. }
  77. function articel_load_collect(article_id) {
  78. $.get(
  79. "../article/collect_get.php",
  80. {
  81. article: article_id,
  82. setting: "",
  83. },
  84. function (data, status) {
  85. if (status == "success") {
  86. try {
  87. let result = JSON.parse(data);
  88. if (result && result.length > 0) {
  89. //$("#collect_title").html(result[0].title);
  90. let strTitle = "<a href='../article/?collect=" + result[0].id + "'>" + result[0].title + "</a>";
  91. $("#pali_pedia").html(strTitle);
  92. let article_list = JSON.parse(result[0].article_list);
  93. render_article_list(article_list, result[0].id);
  94. }
  95. } catch (e) {
  96. console.error(e);
  97. }
  98. } else {
  99. console.error("ajex error");
  100. }
  101. }
  102. );
  103. }
  104. //在collect 中 的article列表
  105. function render_article_list(article_list, collection_id) {
  106. let html = "";
  107. html += "<ul>";
  108. let display = "";
  109. if (_display == "para") {
  110. display = "&display=para";
  111. }
  112. let prevArticle = "无";
  113. let nextArticle = "无";
  114. let urlCollection = "&collection=" + collection_id;
  115. for (let index = 0; index < article_list.length; index++) {
  116. const element = article_list[index];
  117. if (element.article == _articel_id) {
  118. if (index > 0) {
  119. const prev = article_list[index - 1];
  120. prevArticle =
  121. "<a href='../article/index.php?id=" +
  122. prev.article +
  123. display +
  124. urlCollection +
  125. "'>" +
  126. prev.title +
  127. "</a>";
  128. }
  129. if (index < article_list.length - 1) {
  130. const next = article_list[index + 1];
  131. nextArticle =
  132. "<a href='../article/index.php?id=" +
  133. next.article +
  134. display +
  135. urlCollection +
  136. "'>" +
  137. next.title +
  138. "</a>";
  139. }
  140. $("#contents_nav_left").html(prevArticle);
  141. $("#contents_nav_right").html(nextArticle);
  142. }
  143. html +=
  144. "<li class='level_" +
  145. element.level +
  146. "'>" +
  147. "<a href='../article/index.php?id=" +
  148. element.article +
  149. display +
  150. urlCollection +
  151. "'>" +
  152. element.title +
  153. "</a></li>";
  154. }
  155. html += "</ul>";
  156. $("#toc_content").html(html);
  157. }
  158. function set_channal(channalid) {
  159. let url = "../article/index.php?id=" + _articel_id;
  160. if (channalid != "") {
  161. url += "&channal=" + channalid;
  162. }
  163. if (_display != "") {
  164. url += "&display=" + _display;
  165. }
  166. location.assign(url);
  167. }