article.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. $("#article_subtitle").html(result.subtitle);
  27. $("#article_author").html(result.username.nickname + "@" + result.username.username);
  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(result.username.nickname + "@" + result.username.username);
  60. $("#contents").html(marked(result.summary));
  61. let article_list = JSON.parse(result.article_list);
  62. render_article_list(article_list);
  63. }
  64. } catch (e) {
  65. console.error(e);
  66. }
  67. } else {
  68. console.error("ajex error");
  69. }
  70. }
  71. );
  72. }
  73. function articel_load_collect(article_id) {
  74. $.get(
  75. "../article/collect_get.php",
  76. {
  77. article: article_id,
  78. setting: "",
  79. },
  80. function (data, status) {
  81. if (status == "success") {
  82. try {
  83. let result = JSON.parse(data);
  84. if (result && result.length > 0) {
  85. $("#collect_title").html(result[0].title);
  86. let article_list = JSON.parse(result[0].article_list);
  87. render_article_list(article_list);
  88. }
  89. } catch (e) {
  90. console.error(e);
  91. }
  92. } else {
  93. console.error("ajex error");
  94. }
  95. }
  96. );
  97. }
  98. function render_article_list(article_list) {
  99. let html = "";
  100. html += "<ul>";
  101. let display = "";
  102. if (_display == "para") {
  103. display = "&display=para";
  104. }
  105. let prevArticle = "无";
  106. let nextArticle = "无";
  107. for (let index = 0; index < article_list.length; index++) {
  108. const element = article_list[index];
  109. if (element.article == _articel_id) {
  110. if (index > 0) {
  111. const prev = article_list[index - 1];
  112. prevArticle = "<a href='../article/index.php?id=" + prev.article + display + "'>" + prev.title + "</a>";
  113. }
  114. if (index < article_list.length - 1) {
  115. const next = article_list[index + 1];
  116. nextArticle = "<a href='../article/index.php?id=" + next.article + display + "'>" + next.title + "</a>";
  117. }
  118. $("#contents_nav_left").html(prevArticle);
  119. $("#contents_nav_right").html(nextArticle);
  120. }
  121. html +=
  122. "<li class='level_" +
  123. element.level +
  124. "'>" +
  125. "<a href='../article/index.php?id=" +
  126. element.article +
  127. display +
  128. "'>" +
  129. element.title +
  130. "</a></li>";
  131. }
  132. html += "</ul>";
  133. $("#toc_content").html(html);
  134. }
  135. function set_channal(channalid) {
  136. let url = "../article/index.php?id=" + _articel_id;
  137. if (channalid != "") {
  138. url += "&channal=" + channalid;
  139. }
  140. if (_display != "") {
  141. url += "&display=" + _display;
  142. }
  143. location.assign(url);
  144. }