article.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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 strTitle = "<a href='../article/?collect=" + result[0].id + "'>" + result[0].title + "</a>";
  87. $("#pali_pedia").html(strTitle);
  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 = "<a href='../article/index.php?id=" + prev.article + display + "'>" + prev.title + "</a>";
  115. }
  116. if (index < article_list.length - 1) {
  117. const next = article_list[index + 1];
  118. nextArticle = "<a href='../article/index.php?id=" + next.article + display + "'>" + next.title + "</a>";
  119. }
  120. $("#contents_nav_left").html(prevArticle);
  121. $("#contents_nav_right").html(nextArticle);
  122. }
  123. html +=
  124. "<li class='level_" +
  125. element.level +
  126. "'>" +
  127. "<a href='../article/index.php?id=" +
  128. element.article +
  129. display +
  130. "'>" +
  131. element.title +
  132. "</a></li>";
  133. }
  134. html += "</ul>";
  135. $("#toc_content").html(html);
  136. }
  137. function set_channal(channalid) {
  138. let url = "../article/index.php?id=" + _articel_id;
  139. if (channalid != "") {
  140. url += "&channal=" + channalid;
  141. }
  142. if (_display != "") {
  143. url += "&display=" + _display;
  144. }
  145. location.assign(url);
  146. }