article.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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. $("#article_path_title").html(result.title);
  29. $("#page_title").text(result.title);
  30. $("#article_subtitle").html(result.subtitle);
  31. $("#article_author").html(result.username.nickname + "@" + result.username.username);
  32. $("#contents").html(note_init(result.content));
  33. note_refresh_new();
  34. guide_init();
  35. }
  36. } catch (e) {
  37. console.error(e);
  38. }
  39. } else {
  40. console.error("ajex error");
  41. }
  42. }
  43. );
  44. }
  45. function collect_load(id) {
  46. if (id == "") {
  47. return;
  48. }
  49. $.get(
  50. "../article/collect_get.php",
  51. {
  52. id: id,
  53. setting: "",
  54. },
  55. function (data, status) {
  56. if (status == "success") {
  57. try {
  58. let result = JSON.parse(data);
  59. if (result) {
  60. $("#article_title").html(result.title);
  61. $("#page_title").text(result.title);
  62. if (result.subtitle) {
  63. $("#article_subtitle").html(result.subtitle);
  64. }
  65. $("#article_author").html(result.username.nickname + "@" + result.username.username);
  66. $("#contents").html(marked(result.summary));
  67. let article_list = JSON.parse(result.article_list);
  68. render_article_list(article_list);
  69. }
  70. } catch (e) {
  71. console.error(e);
  72. }
  73. } else {
  74. console.error("ajex error");
  75. }
  76. }
  77. );
  78. }
  79. function articel_load_article_list(articleId,collectionId) {
  80. $.get(
  81. "../article/collect_get.php",
  82. {
  83. id: collectionId,
  84. setting: "",
  85. },
  86. function (data, status) {
  87. if (status == "success") {
  88. try {
  89. let result = JSON.parse(data);
  90. if (result) {
  91. let article_list = JSON.parse(result.article_list);
  92. render_article_list(article_list,collectionId,articleId);
  93. let strTitle = "<a href='../article/?collection=" + result.id + "'>" + result.title + "</a> / ";
  94. for (const iterator of tocActivePath) {
  95. strTitle += "<a href='../article/?id="+iterator.key+"&collection=" + result.id + "'>" + iterator.title + "</a> / ";
  96. }
  97. $("#article_path").html(strTitle);
  98. }
  99. } catch (e) {
  100. console.error(e);
  101. }
  102. } else {
  103. console.error("ajex error");
  104. }
  105. }
  106. );
  107. }
  108. //在collect 中 的article列表
  109. function render_article_list(article_list,collectId="",articleId="") {
  110. $("#toc_content").fancytree({
  111. autoScroll: true,
  112. source: tocGetTreeData(article_list,articleId),
  113. activate: function(e, data) {
  114. gotoArticle(data.node.key,collectId);
  115. return false;
  116. }
  117. });
  118. }
  119. function set_channal(channalid) {
  120. let url = "../article/index.php?id=" + _articel_id;
  121. if (_collection_id != "") {
  122. url += "&collection=" + _collection_id;
  123. }
  124. if (channalid != "") {
  125. url += "&channal=" + channalid;
  126. }
  127. if (_display != "") {
  128. url += "&display=" + _display;
  129. }
  130. if (_mode != "") {
  131. url += "&mode=" + _mode;
  132. }
  133. if (_direction != "") {
  134. url += "&direction=" + _direction;
  135. }
  136. location.assign(url);
  137. }
  138. function setMode(mode = "read") {
  139. let url = "../article/index.php?id=" + _articel_id;
  140. if (_channal != "") {
  141. url += "&channal=" + _channal;
  142. }
  143. if (_display != "") {
  144. if (mode == "read") {
  145. url += "&display=" + _display;
  146. } else {
  147. url += "&display=sent";
  148. }
  149. }
  150. if (mode != "") {
  151. url += "&mode=" + mode;
  152. }
  153. if (_direction != "") {
  154. url += "&direction=" + _direction;
  155. }
  156. location.assign(url);
  157. }
  158. //跳转到另外一个文章
  159. function gotoArticle(articleId) {
  160. let url = "../article/index.php?id=" + articleId;
  161. if (_collection_id != "") {
  162. url += "&collection=" + _collection_id;
  163. }
  164. if (_channal != "") {
  165. url += "&channal=" + _channal;
  166. }
  167. if (_display != "") {
  168. url += "&display=" + _display;
  169. }
  170. if (_mode != "") {
  171. url += "&mode=" + _mode;
  172. }
  173. if (_direction != "") {
  174. url += "&direction=" + _direction;
  175. }
  176. location.assign(url);
  177. }