2
0

article.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. var _articel_id = "";
  2. var _channal = "";
  3. var _lang = "";
  4. var _author = "";
  5. var _display = "";
  6. var _collect_id = "";
  7. var _collection_id = "";
  8. function article_onload() {
  9. historay_init();
  10. }
  11. function articel_load(id, collection_id) {
  12. if (id == "") {
  13. return;
  14. }
  15. $.get(
  16. "../article/get.php",
  17. {
  18. id: id,
  19. collection_id: collection_id,
  20. setting: "",
  21. },
  22. function (data, status) {
  23. if (status == "success") {
  24. try {
  25. let result = JSON.parse(data);
  26. if (result) {
  27. $("#article_title").html(result.title);
  28. $("#page_title").text(result.title);
  29. $("#article_subtitle").html(result.subtitle);
  30. $("#article_author").html(result.username.nickname + "@" + result.username.username);
  31. $("#contents").html(note_init(result.content));
  32. note_refresh_new();
  33. guide_init();
  34. }
  35. } catch (e) {
  36. console.error(e);
  37. }
  38. } else {
  39. console.error("ajex error");
  40. }
  41. }
  42. );
  43. }
  44. function collect_load(id) {
  45. if (id == "") {
  46. return;
  47. }
  48. $.get(
  49. "../article/collect_get.php",
  50. {
  51. id: id,
  52. setting: "",
  53. },
  54. function (data, status) {
  55. if (status == "success") {
  56. try {
  57. let result = JSON.parse(data);
  58. if (result) {
  59. $("#article_title").html(result.title);
  60. $("#page_title").text(result.title);
  61. if (result.subtitle) {
  62. $("#article_subtitle").html(result.subtitle);
  63. }
  64. $("#article_author").html(result.username.nickname + "@" + result.username.username);
  65. $("#contents").html(marked(result.summary));
  66. let article_list = JSON.parse(result.article_list);
  67. render_article_list(article_list, id);
  68. }
  69. } catch (e) {
  70. console.error(e);
  71. }
  72. } else {
  73. console.error("ajex error");
  74. }
  75. }
  76. );
  77. }
  78. function articel_load_collect(article_id) {
  79. $.get(
  80. "../article/collect_get.php",
  81. {
  82. article: article_id,
  83. setting: "",
  84. },
  85. function (data, status) {
  86. if (status == "success") {
  87. try {
  88. let result = JSON.parse(data);
  89. if (result && result.length > 0) {
  90. //$("#collect_title").html(result[0].title);
  91. let strTitle = "<a href='../article/?collect=" + result[0].id + "'>" + result[0].title + "</a>";
  92. $("#pali_pedia").html(strTitle);
  93. let article_list = JSON.parse(result[0].article_list);
  94. render_article_list(article_list, result[0].id);
  95. }
  96. } catch (e) {
  97. console.error(e);
  98. }
  99. } else {
  100. console.error("ajex error");
  101. }
  102. }
  103. );
  104. }
  105. //在collect 中 的article列表
  106. function render_article_list(article_list, collection_id) {
  107. let html = "";
  108. html += "<ul>";
  109. let display = "";
  110. if (_display == "para") {
  111. display = "&display=para";
  112. }
  113. let prevArticle = "无";
  114. let nextArticle = "无";
  115. let urlCollection = "&collection=" + collection_id;
  116. for (let index = 0; index < article_list.length; index++) {
  117. const element = article_list[index];
  118. if (element.article == _articel_id) {
  119. if (index > 0) {
  120. const prev = article_list[index - 1];
  121. prevArticle = "<a onclick=\"gotoArticle('" + prev.article + "')\">" + prev.title + "</a>";
  122. }
  123. if (index < article_list.length - 1) {
  124. const next = article_list[index + 1];
  125. nextArticle = "<a onclick=\"gotoArticle('" + next.article + "')\">" + next.title + "</a>";
  126. }
  127. $("#contents_nav_left").html(prevArticle);
  128. $("#contents_nav_right").html(nextArticle);
  129. }
  130. html +=
  131. "<li class='level_" +
  132. element.level +
  133. "'>" +
  134. "<a onclick=\"gotoArticle('" +
  135. element.article +
  136. "')\">" +
  137. element.title +
  138. "</a></li>";
  139. }
  140. html += "</ul>";
  141. $("#toc_content").html(html);
  142. }
  143. function set_channal(channalid) {
  144. let url = "../article/index.php?id=" + _articel_id;
  145. if (channalid != "") {
  146. url += "&channal=" + channalid;
  147. }
  148. if (_display != "") {
  149. url += "&display=" + _display;
  150. }
  151. if (_mode != "") {
  152. url += "&mode=" + _mode;
  153. }
  154. if (_direction != "") {
  155. url += "&direction=" + _direction;
  156. }
  157. location.assign(url);
  158. }
  159. function setMode(mode = "read") {
  160. let url = "../article/index.php?id=" + _articel_id;
  161. if (_channal != "") {
  162. url += "&channal=" + _channal;
  163. }
  164. if (_display != "") {
  165. if (mode == "read") {
  166. url += "&display=" + _display;
  167. } else {
  168. url += "&display=sent";
  169. }
  170. }
  171. if (mode != "") {
  172. url += "&mode=" + mode;
  173. }
  174. if (_direction != "") {
  175. url += "&direction=" + _direction;
  176. }
  177. location.assign(url);
  178. }
  179. //跳转到另外一个文章
  180. function gotoArticle(articleId) {
  181. let url = "../article/index.php?id=" + articleId;
  182. if (_channal != "") {
  183. url += "&channal=" + _channal;
  184. }
  185. if (_display != "") {
  186. url += "&display=" + _display;
  187. }
  188. if (_mode != "") {
  189. url += "&mode=" + _mode;
  190. }
  191. if (_direction != "") {
  192. url += "&direction=" + _direction;
  193. }
  194. location.assign(url);
  195. }