article.js 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  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. param = {view: _view,id:_id};
  258. break;
  259. default:
  260. break;
  261. }
  262. $.get(
  263. "../reader/get_para1.php",
  264. param,
  265. function (data, status) {
  266. if (status == "success") {
  267. try {
  268. let result = JSON.parse(data);
  269. if (result) {
  270. _sent_data=result;
  271. $("#article_title").html(result.title);
  272. $("#article_path_title").html(result.title);
  273. $("#page_title").text(result.title);
  274. $("#article_subtitle").html(result.subtitle);
  275. $("#article_author").html(result.username.nickname + "@" + result.username.username);
  276. $("#contents").html(note_init(result.content));
  277. note_refresh_new(function () {
  278. document.querySelector("#para_focus").scrollIntoView({
  279. block: "end",
  280. behavior: "smooth",
  281. });
  282. });
  283. reader_draw_para_menu();
  284. guide_init();
  285. }
  286. } catch (e) {
  287. console.error(e);
  288. }
  289. } else {
  290. console.error("ajex error");
  291. }
  292. }
  293. );
  294. }
  295. function reader_get_path() {
  296. $.get(
  297. "../reader/get_path.php",
  298. {
  299. book: _book,
  300. para: _par,
  301. },
  302. function (data) {
  303. $("#article_path").html(data);
  304. var bookTitle = $("chapter").first().html();
  305. let suttaTitle = $("chapter").last().html();
  306. $("#pali_pedia").html(bookTitle);
  307. $("#article_title").html(suttaTitle);
  308. $("#page_title").text(suttaTitle);
  309. }
  310. );
  311. }
  312. function reader_draw_para_menu() {
  313. $(".page_number").each(function () {
  314. let strPara = $(this).text();
  315. $(this).addClass("case_dropdown");
  316. let html = "<a name='para_" + strPara + "'></a>";
  317. html += "<div class='case_dropdown-content para_menu'>";
  318. if (typeof _view != "undefined" && _view != "para") {
  319. html += "<a onclick=\"junp_to_para('" + _book + "','" + strPara + "')\">仅显示此段</a>";
  320. }
  321. html += "<a onclick=\"edit_wbw('" + _book + "','" + strPara + "')\">" + gLocal.gui.edit_now + "</a>";
  322. html += "<a onclick='goto_nissaya(" + _book + "," + strPara + ")'>" + gLocal.gui.show_nissaya + "</a>";
  323. html +=
  324. "<a onclick=\"copy_para_ref('" + _book + "','" + strPara + "')\">" + gLocal.gui.copy_link + "</a>";
  325. html +=
  326. "<a onclick=\"copy_text('" +
  327. _book +
  328. "','" +
  329. strPara +
  330. "')\">" +
  331. gLocal.gui.copy +
  332. "“" +
  333. gLocal.gui.pāli +
  334. "”</a>";
  335. html +=
  336. "<a onclick=\"add_to_list('" +
  337. _book +
  338. "','" +
  339. strPara +
  340. "')\">" +
  341. gLocal.gui.add_to_edit_list +
  342. "</a>";
  343. html += "</div>";
  344. $(this).append(html);
  345. });
  346. }
  347. function junp_to_para(book, para) {
  348. let url = "../article/?view=para&book=" + book + "&par=" + para + "&display=sent";
  349. location.assign(url);
  350. }
  351. function copy_para_ref(book, para) {
  352. let output = "";
  353. for (const iterator of _sent_data.sent_list) {
  354. if (iterator.book == book && iterator.paragraph == para) {
  355. output += "{{" + book + "-" + para + "-" + iterator.begin + "-" + iterator.end + "}}\n";
  356. }
  357. }
  358. output += "\n";
  359. copy_to_clipboard(output);
  360. }
  361. function edit_wbw(book, para) {
  362. wbw_channal_list_open(book, [para]);
  363. }
  364. function to_article(){
  365. article_add_dlg_show({
  366. title:_sent_data.title,
  367. content:_sent_data.content,
  368. });
  369. }
  370. function render_toc(){
  371. $.getJSON(
  372. "../api/pali_text.php",
  373. {
  374. _method:"index",
  375. view:"toc",
  376. book: _book,
  377. par: _par,
  378. }
  379. ).done(function (data) {
  380. let arrToc = new Array();
  381. for (const it of data.data) {
  382. arrToc.push({article:it.paragraph,title:it.toc,level:it.level});
  383. }
  384. $("#toc_content").fancytree({
  385. autoScroll: true,
  386. source: tocGetTreeData(arrToc,_par),
  387. activate: function(e, data) {
  388. gotoChapter(data.node.key);
  389. return false;
  390. }
  391. });
  392. });
  393. }
  394. //跳转到另外一个文章
  395. function gotoChapter(paragraph) {
  396. let url = "../article/index.php?view=chapter";
  397. url += "&book=" + _book;
  398. url += "&par=" + paragraph;
  399. if (_channal != "") {
  400. url += "&channal=" + _channal;
  401. }
  402. if (_display != "") {
  403. url += "&display=" + _display;
  404. }
  405. if (_mode != "") {
  406. url += "&mode=" + _mode;
  407. }
  408. if (_direction != "") {
  409. url += "&direction=" + _direction;
  410. }
  411. location.assign(url);
  412. }