article.js 3.3 KB

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