article.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. function articel_load(id) {
  9. if (id == "") {
  10. return;
  11. }
  12. $.get(
  13. "../article/get.php",
  14. {
  15. id: id,
  16. setting: "",
  17. },
  18. function (data, status) {
  19. if (status == "success") {
  20. try {
  21. let result = JSON.parse(data);
  22. if (result) {
  23. $("#article_title").html(result.title);
  24. $("#article_subtitle").html(result.subtitle);
  25. $("#article_author").html(
  26. result.username.nickname + "@" + result.username.username
  27. );
  28. $("#contents").html(note_init(result.content));
  29. note_refresh_new();
  30. }
  31. } catch (e) {
  32. console.error(e);
  33. }
  34. } else {
  35. console.error("ajex error");
  36. }
  37. }
  38. );
  39. }
  40. function collect_load(id) {
  41. if (id == "") {
  42. return;
  43. }
  44. $.get(
  45. "../article/collect_get.php",
  46. {
  47. id: id,
  48. setting: "",
  49. },
  50. function (data, status) {
  51. if (status == "success") {
  52. try {
  53. let result = JSON.parse(data);
  54. if (result) {
  55. $("#article_title").html(result.title);
  56. if (result.subtitle) {
  57. $("#article_subtitle").html(result.subtitle);
  58. }
  59. $("#article_author").html(
  60. result.username.nickname + "@" + result.username.username
  61. );
  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 article_list = JSON.parse(result[0].article_list);
  89. render_article_list(article_list);
  90. }
  91. } catch (e) {
  92. console.error(e);
  93. }
  94. } else {
  95. console.error("ajex error");
  96. }
  97. }
  98. );
  99. }
  100. function render_article_list(article_list) {
  101. let html = "";
  102. html += "<ul>";
  103. let display = "";
  104. if (_display == "para") {
  105. display = "&display=para";
  106. }
  107. let prevArticle = "无";
  108. let nextArticle = "无";
  109. for (let index = 0; index < article_list.length; index++) {
  110. const element = article_list[index];
  111. if (element.article == _articel_id) {
  112. if (index > 0) {
  113. const prev = article_list[index - 1];
  114. prevArticle =
  115. "<a href='../article/index.php?id=" +
  116. prev.article +
  117. display +
  118. "'>" +
  119. prev.title +
  120. "</a>";
  121. }
  122. if (index < article_list.length - 1) {
  123. const next = article_list[index + 1];
  124. nextArticle =
  125. "<a href='../article/index.php?id=" +
  126. next.article +
  127. display +
  128. "'>" +
  129. next.title +
  130. "</a>";
  131. }
  132. $("#contents_nav_left").html(prevArticle);
  133. $("#contents_nav_right").html(nextArticle);
  134. }
  135. html +=
  136. "<li class='level_" +
  137. element.level +
  138. "'>" +
  139. "<a href='../article/index.php?id=" +
  140. element.article +
  141. display +
  142. "'>" +
  143. element.title +
  144. "</a></li>";
  145. }
  146. html += "</ul>";
  147. $("#toc_content").html(html);
  148. }
  149. function set_channal(channalid) {
  150. let url = "../article/index.php?id=" + _articel_id;
  151. if (channalid != "") {
  152. url += "&channal=" + channalid;
  153. }
  154. if (_display != "") {
  155. url += "&display=" + _display;
  156. }
  157. location.assign(url);
  158. }