2
0

article.js 3.3 KB

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