article.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. //import {Like,LikeRefresh} from '../widget/like.js';
  2. var _view = "";
  3. var _id = "";
  4. var _articel_id = "";
  5. var _channal = "";
  6. var _lang = "";
  7. var _author = "";
  8. var _display = "";
  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. let htmlLike = "";
  69. htmlLike += "<like liketype='like' restype='collection' resid='"+id+"'></like>";
  70. htmlLike += "<like liketype='favorite' restype='collection' resid='"+id+"'></like>";
  71. $("#like_div").html(htmlLike);
  72. $("#summary").html(result.summary);
  73. $("#contents").html("<div id='content_text'></div><h3>目录</h3><div id='content_toc'></div>");
  74. let article_list = JSON.parse(result.article_list);
  75. render_article_list(article_list);
  76. render_article_list_in_content(article_list);
  77. $("#content_toc").fancytree("getRootNode").visit(function(node){
  78. node.setExpanded(true);
  79. });
  80. Like();
  81. }
  82. } catch (e) {
  83. console.error(e);
  84. }
  85. } else {
  86. console.error("ajex error");
  87. }
  88. }
  89. );
  90. }
  91. function articel_load_article_list(articleId,collectionId) {
  92. $.get(
  93. "../article/collect_get.php",
  94. {
  95. id: collectionId,
  96. setting: "",
  97. },
  98. function (data, status) {
  99. if (status == "success") {
  100. try {
  101. let result = JSON.parse(data);
  102. if (result) {
  103. let article_list = JSON.parse(result.article_list);
  104. render_article_list(article_list,collectionId,articleId);
  105. let strTitle = "<a href='../article/?view=collection&collection=" + result.id + "'>" + result.title + "</a> / ";
  106. for (const iterator of tocActivePath) {
  107. strTitle += "<a href='../article/?view=article&id="+iterator.key+"&collection=" + result.id + "'>" + iterator.title + "</a> / ";
  108. }
  109. $("#article_path").html(strTitle);
  110. }
  111. } catch (e) {
  112. console.error(e);
  113. }
  114. } else {
  115. console.error("ajex error");
  116. }
  117. }
  118. );
  119. }
  120. //在collect 中 的article列表
  121. function render_article_list(article_list,collectId="",articleId="") {
  122. $("#toc_content").fancytree({
  123. autoScroll: true,
  124. source: tocGetTreeData(article_list,articleId),
  125. activate: function(e, data) {
  126. gotoArticle(data.node.key,collectId);
  127. return false;
  128. }
  129. });
  130. }
  131. //在 正文中的目录
  132. function render_article_list_in_content(article_list,collectId="",articleId="") {
  133. $("#content_toc").fancytree({
  134. autoScroll: true,
  135. source: tocGetTreeData(article_list,articleId),
  136. activate: function(e, data) {
  137. gotoArticle(data.node.key,collectId);
  138. return false;
  139. }
  140. });
  141. }
  142. function set_channal(channalid) {
  143. let url = "../article/index.php?view=article&id=" + _articel_id;
  144. if (_collection_id != "") {
  145. url += "&collection=" + _collection_id;
  146. }
  147. if (channalid != "") {
  148. url += "&channal=" + channalid;
  149. }
  150. if (_display != "") {
  151. url += "&display=" + _display;
  152. }
  153. if (_mode != "") {
  154. url += "&mode=" + _mode;
  155. }
  156. if (_direction != "") {
  157. url += "&direction=" + _direction;
  158. }
  159. location.assign(url);
  160. }
  161. function setMode(mode = "read") {
  162. let url = "../article/index.php?view=article&id=" + _articel_id;
  163. if (_collection_id != "") {
  164. url += "&collection=" + _collection_id;
  165. }
  166. if (_channal != "") {
  167. url += "&channal=" + _channal;
  168. }
  169. if (_display != "") {
  170. if (mode == "read") {
  171. url += "&display=" + _display;
  172. } else {
  173. url += "&display=sent";
  174. }
  175. }
  176. if (mode != "") {
  177. url += "&mode=" + mode;
  178. }
  179. if (_direction != "") {
  180. url += "&direction=" + _direction;
  181. }
  182. location.assign(url);
  183. }
  184. //跳转到另外一个文章
  185. function gotoArticle(articleId) {
  186. let url = "../article/index.php?view=article&id=" + articleId;
  187. if (_collection_id != "") {
  188. url += "&collection=" + _collection_id;
  189. }
  190. if (_channal != "") {
  191. url += "&channal=" + _channal;
  192. }
  193. if (_display != "") {
  194. url += "&display=" + _display;
  195. }
  196. if (_mode != "") {
  197. url += "&mode=" + _mode;
  198. }
  199. if (_direction != "") {
  200. url += "&direction=" + _direction;
  201. }
  202. location.assign(url);
  203. }