article.js 3.5 KB

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