article.js 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  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. var _book=0,_par=0,_start=0,_end=0;
  11. var _sent_data;
  12. function article_onload() {
  13. historay_init();
  14. }
  15. function articel_load(id, collection_id) {
  16. if (id == "") {
  17. return;
  18. }
  19. $.get(
  20. "../article/get.php",
  21. {
  22. id: id,
  23. collection_id: collection_id,
  24. setting: "",
  25. },
  26. function (data, status) {
  27. if (status == "success") {
  28. try {
  29. let result = JSON.parse(data);
  30. if (result) {
  31. $("#article_title").html(result.title);
  32. $("#article_path_title").html(result.title);
  33. $("#page_title").text(result.title);
  34. $("#article_subtitle").html(result.subtitle);
  35. $("#article_author").html(result.username.nickname + "@" + result.username.username);
  36. $("#contents").html(note_init(result.content));
  37. note_refresh_new();
  38. guide_init();
  39. }
  40. } catch (e) {
  41. console.error(e);
  42. }
  43. } else {
  44. console.error("ajex error");
  45. }
  46. }
  47. );
  48. }
  49. function collect_load(id) {
  50. if (id == "") {
  51. return;
  52. }
  53. $.get(
  54. "../article/collect_get.php",
  55. {
  56. id: id,
  57. setting: "",
  58. },
  59. function (data, status) {
  60. if (status == "success") {
  61. try {
  62. let result = JSON.parse(data);
  63. if (result) {
  64. $("#article_title").html(result.title);
  65. $("#page_title").text(result.title);
  66. if (result.subtitle) {
  67. $("#article_subtitle").html(result.subtitle);
  68. }
  69. $("#article_author").html(result.username.nickname + "@" + result.username.username);
  70. let htmlLike = "";
  71. htmlLike += "<like liketype='like' restype='collection' resid='"+id+"'></like>";
  72. htmlLike += "<like liketype='favorite' restype='collection' resid='"+id+"'></like>";
  73. $("#like_div").html(htmlLike);
  74. $("#summary").html(result.summary);
  75. $("#contents").html("<div id='content_text'></div><h3>目录</h3><div id='content_toc'></div>");
  76. let article_list = JSON.parse(result.article_list);
  77. render_article_list(article_list);
  78. render_article_list_in_content(article_list);
  79. $("#content_toc").fancytree("getRootNode").visit(function(node){
  80. node.setExpanded(true);
  81. });
  82. Like();
  83. }
  84. } catch (e) {
  85. console.error(e);
  86. }
  87. } else {
  88. console.error("ajex error");
  89. }
  90. }
  91. );
  92. }
  93. function articel_load_article_list(articleId,collectionId) {
  94. $.get(
  95. "../article/collect_get.php",
  96. {
  97. id: collectionId,
  98. setting: "",
  99. },
  100. function (data, status) {
  101. if (status == "success") {
  102. try {
  103. let result = JSON.parse(data);
  104. if (result) {
  105. let article_list = JSON.parse(result.article_list);
  106. render_article_list(article_list,collectionId,articleId);
  107. let strTitle = "<a href='../article/?view=collection&collection=" + result.id + "'>" + result.title + "</a> / ";
  108. for (const iterator of tocActivePath) {
  109. strTitle += "<a href='../article/?view=article&id="+iterator.key+"&collection=" + result.id + "'>" + iterator.title + "</a> / ";
  110. }
  111. $("#article_path").html(strTitle);
  112. }
  113. } catch (e) {
  114. console.error(e);
  115. }
  116. } else {
  117. console.error("ajex error");
  118. }
  119. }
  120. );
  121. }
  122. //在collect 中 的article列表
  123. function render_article_list(article_list,collectId="",articleId="") {
  124. $("#toc_content").fancytree({
  125. autoScroll: true,
  126. source: tocGetTreeData(article_list,articleId),
  127. activate: function(e, data) {
  128. gotoArticle(data.node.key,collectId);
  129. return false;
  130. }
  131. });
  132. }
  133. //在 正文中的目录
  134. function render_article_list_in_content(article_list,collectId="",articleId="") {
  135. $("#content_toc").fancytree({
  136. autoScroll: true,
  137. source: tocGetTreeData(article_list,articleId),
  138. activate: function(e, data) {
  139. gotoArticle(data.node.key,collectId);
  140. return false;
  141. }
  142. });
  143. }
  144. function set_channal(channalid) {
  145. let url = "../article/index.php?";
  146. if (_view != "") {
  147. url += "view=" + _view;
  148. }
  149. if (_id != "") {
  150. url += "&id=" + _id;
  151. }
  152. if (_book != 0) {
  153. url += "&book=" + _book;
  154. }
  155. if (_par != 0) {
  156. url += "&par=" + _par;
  157. }
  158. if (_start != 0) {
  159. url += "&start=" + _start;
  160. }
  161. if (_end != 0) {
  162. url += "&end=" + _end;
  163. }
  164. if (_collection_id != "") {
  165. url += "&collection=" + _collection_id;
  166. }
  167. if (channalid != "") {
  168. url += "&channal=" + channalid;
  169. }
  170. if (_display != "") {
  171. url += "&display=" + _display;
  172. }
  173. if (_mode != "") {
  174. url += "&mode=" + _mode;
  175. }
  176. if (_direction != "") {
  177. url += "&direction=" + _direction;
  178. }
  179. location.assign(url);
  180. }
  181. function setMode(mode = "read") {
  182. let url = "../article/index.php?";
  183. if (_view != "") {
  184. url += "view=" + _view;
  185. }
  186. if (_id != "") {
  187. url += "&id=" + _id;
  188. }
  189. if (_book != 0) {
  190. url += "&book=" + _book;
  191. }
  192. if (_par != 0) {
  193. url += "&par=" + _par;
  194. }
  195. if (_start != 0) {
  196. url += "&start=" + _start;
  197. }
  198. if (_end != 0) {
  199. url += "&end=" + _end;
  200. }
  201. if (_collection_id != "") {
  202. url += "&collection=" + _collection_id;
  203. }
  204. if (_channal != "") {
  205. url += "&channal=" + _channal;
  206. }
  207. if (_display != "") {
  208. if (mode == "read") {
  209. url += "&display=" + _display;
  210. } else {
  211. url += "&display=sent";
  212. }
  213. }
  214. if (mode != "") {
  215. url += "&mode=" + mode;
  216. }
  217. if (_direction != "") {
  218. url += "&direction=" + _direction;
  219. }
  220. location.assign(url);
  221. }
  222. //跳转到另外一个文章
  223. function gotoArticle(articleId) {
  224. let url = "../article/index.php?view=article&id=" + articleId;
  225. if (_collection_id != "") {
  226. url += "&collection=" + _collection_id;
  227. }
  228. if (_channal != "") {
  229. url += "&channal=" + _channal;
  230. }
  231. if (_display != "") {
  232. url += "&display=" + _display;
  233. }
  234. if (_mode != "") {
  235. url += "&mode=" + _mode;
  236. }
  237. if (_direction != "") {
  238. url += "&direction=" + _direction;
  239. }
  240. location.assign(url);
  241. }
  242. function palicanon_load() {
  243. let param;
  244. switch (_view) {
  245. case "sent":
  246. case "para":
  247. case "chapter":
  248. param = {
  249. view: _view,
  250. book: _book,
  251. par: _par,
  252. start: _start,
  253. end: _end,
  254. }
  255. break;
  256. case "simsent":
  257. case "sim":
  258. param = {view: _view,id:_id};
  259. break;
  260. default:
  261. break;
  262. }
  263. $.get(
  264. "../reader/get_para1.php",
  265. param,
  266. function (data, status) {
  267. if (status == "success") {
  268. try {
  269. let result = JSON.parse(data);
  270. if (result) {
  271. _sent_data=result;
  272. $("#article_title").html(result.title);
  273. $("#article_path_title").html(result.title);
  274. $("#page_title").text(result.title);
  275. $("#article_subtitle").html(result.subtitle);
  276. $("#article_author").html(result.username.nickname + "@" + result.username.username);
  277. $("#contents").html(note_init(result.content));
  278. note_refresh_new(function () {
  279. document.querySelector("#para_focus").scrollIntoView({
  280. block: "end",
  281. behavior: "smooth",
  282. });
  283. });
  284. reader_draw_para_menu();
  285. guide_init();
  286. }
  287. } catch (e) {
  288. console.error(e);
  289. }
  290. } else {
  291. console.error("ajex error");
  292. }
  293. }
  294. );
  295. }
  296. function reader_get_path() {
  297. $.get(
  298. "../reader/get_path.php",
  299. {
  300. book: _book,
  301. para: _par,
  302. },
  303. function (data) {
  304. $("#article_path").html(data);
  305. var bookTitle = $("chapter").first().html();
  306. let suttaTitle = $("chapter").last().html();
  307. $("#pali_pedia").html(bookTitle);
  308. $("#article_title").html(suttaTitle);
  309. $("#page_title").text(suttaTitle);
  310. }
  311. );
  312. }
  313. function reader_draw_para_menu() {
  314. $(".page_number").each(function () {
  315. let strPara = $(this).text();
  316. $(this).addClass("case_dropdown");
  317. let html = "<a name='para_" + strPara + "'></a>";
  318. html += "<div class='case_dropdown-content para_menu'>";
  319. if (typeof _view != "undefined" && _view != "para") {
  320. html += "<a onclick=\"junp_to_para('" + _book + "','" + strPara + "')\">仅显示此段</a>";
  321. }
  322. html += "<a onclick=\"edit_wbw('" + _book + "','" + strPara + "')\">" + gLocal.gui.edit_now + "</a>";
  323. html += "<a onclick='goto_nissaya(" + _book + "," + strPara + ")'>" + gLocal.gui.show_nissaya + "</a>";
  324. html +=
  325. "<a onclick=\"copy_para_ref('" + _book + "','" + strPara + "')\">" + gLocal.gui.copy_link + "</a>";
  326. html +=
  327. "<a onclick=\"copy_text('" +
  328. _book +
  329. "','" +
  330. strPara +
  331. "')\">" +
  332. gLocal.gui.copy +
  333. "“" +
  334. gLocal.gui.pāli +
  335. "”</a>";
  336. html +=
  337. "<a onclick=\"add_to_list('" +
  338. _book +
  339. "','" +
  340. strPara +
  341. "')\">" +
  342. gLocal.gui.add_to_edit_list +
  343. "</a>";
  344. html += "</div>";
  345. $(this).append(html);
  346. });
  347. }
  348. function junp_to_para(book, para) {
  349. let url = "../article/?view=para&book=" + book + "&par=" + para + "&display=sent";
  350. location.assign(url);
  351. }
  352. function copy_para_ref(book, para) {
  353. let output = "";
  354. for (const iterator of _sent_data.sent_list) {
  355. if (iterator.book == book && iterator.paragraph == para) {
  356. output += "{{" + book + "-" + para + "-" + iterator.begin + "-" + iterator.end + "}}\n";
  357. }
  358. }
  359. output += "\n";
  360. copy_to_clipboard(output);
  361. }
  362. function edit_wbw(book, para) {
  363. wbw_channal_list_open(book, [para]);
  364. }
  365. function to_article(){
  366. article_add_dlg_show({
  367. title:_sent_data.title,
  368. content:_sent_data.content,
  369. });
  370. }
  371. function render_toc(){
  372. $.getJSON(
  373. "../api/pali_text.php",
  374. {
  375. _method:"index",
  376. view:"toc",
  377. book: _book,
  378. par: _par,
  379. }
  380. ).done(function (data) {
  381. let arrToc = new Array();
  382. for (const it of data.data) {
  383. arrToc.push({article:it.paragraph,title:it.toc,level:it.level});
  384. }
  385. $("#toc_content").fancytree({
  386. autoScroll: true,
  387. source: tocGetTreeData(arrToc,_par),
  388. activate: function(e, data) {
  389. gotoChapter(data.node.key);
  390. return false;
  391. }
  392. });
  393. });
  394. }
  395. //跳转到另外一个文章
  396. function gotoChapter(paragraph) {
  397. let url = "../article/index.php?view=chapter";
  398. url += "&book=" + _book;
  399. url += "&par=" + paragraph;
  400. if (_channal != "") {
  401. url += "&channal=" + _channal;
  402. }
  403. if (_display != "") {
  404. url += "&display=" + _display;
  405. }
  406. if (_mode != "") {
  407. url += "&mode=" + _mode;
  408. }
  409. if (_direction != "") {
  410. url += "&direction=" + _direction;
  411. }
  412. location.assign(url);
  413. }