article.js 4.9 KB

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