article.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605
  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. articleFillFootNavButton(article_list,articleId);
  108. let strTitle = "<a href='../article/?view=collection&collection=" + result.id + "'>" + result.title + "</a> / ";
  109. for (const iterator of tocActivePath) {
  110. strTitle += "<a href='../article/?view=article&id="+iterator.key+"&collection=" + result.id + "'>" + iterator.title + "</a> / ";
  111. }
  112. $("#article_path").html(strTitle);
  113. }
  114. } catch (e) {
  115. console.error(e);
  116. }
  117. } else {
  118. console.error("ajex error");
  119. }
  120. }
  121. );
  122. }
  123. var prevArticle=0,nextArticle=0;
  124. function articleFillFootNavButton(article_list,curr_article){
  125. for (let index = 0; index < article_list.length; index++) {
  126. const element = article_list[index];
  127. if(element.article==curr_article){
  128. if(index!=0){
  129. $("#contents_nav_left_inner").html(article_list[index-1].title);
  130. prevArticle = article_list[index-1].article;
  131. }else{
  132. $("#contents_nav_left_inner").html("无");
  133. }
  134. if(index!=article_list.length-1){
  135. $("#contents_nav_right_inner").html(article_list[index+1].title);
  136. nextArticle = article_list[index+1].article;
  137. }else{
  138. $("#contents_nav_right_inner").html("无");
  139. }
  140. }
  141. }
  142. }
  143. function goto_prev() {
  144. switch (_view) {
  145. case "article":
  146. if(prevArticle==0){
  147. alert("已经到达开始");
  148. }else{
  149. gotoArticle(prevArticle);
  150. }
  151. break;
  152. case "collection":
  153. break;
  154. case "sent":
  155. case "para":
  156. gotoPara(_par-1);
  157. case "chapter":
  158. if(prevChapter>0){
  159. gotoChapter(prevChapter);
  160. }else{
  161. alert("已经到达开始");
  162. }
  163. break;
  164. case "book":
  165. case "series":
  166. break;
  167. case "simsent":
  168. case "sim":
  169. break;
  170. default:
  171. break;
  172. }
  173. }
  174. function goto_next() {
  175. switch (_view) {
  176. case "article":
  177. if(nextArticle==0){
  178. alert("已经到达最后");
  179. }else{
  180. gotoArticle(nextArticle);
  181. }
  182. break;
  183. case "collection":
  184. break;
  185. case "sent":
  186. case "para":
  187. gotoPara(_par+1);
  188. break;
  189. case "chapter":
  190. if(nextChapter>0){
  191. gotoChapter(nextChapter);
  192. }else{
  193. alert("已经到达最后");
  194. }
  195. break;
  196. case "book":
  197. case "series":
  198. break;
  199. case "simsent":
  200. case "sim":
  201. break;
  202. default:
  203. break;
  204. }
  205. }
  206. //在collect 中 的article列表
  207. function render_article_list(article_list,collectId="",articleId="") {
  208. $("#toc_content").fancytree({
  209. autoScroll: true,
  210. source: tocGetTreeData(article_list,articleId),
  211. activate: function(e, data) {
  212. gotoArticle(data.node.key,collectId);
  213. return false;
  214. }
  215. });
  216. }
  217. //在 正文中的目录
  218. function render_article_list_in_content(article_list,collectId="",articleId="") {
  219. $("#content_toc").fancytree({
  220. autoScroll: true,
  221. source: tocGetTreeData(article_list,articleId),
  222. activate: function(e, data) {
  223. gotoArticle(data.node.key,collectId);
  224. return false;
  225. }
  226. });
  227. }
  228. function set_channal(channalid) {
  229. let url = "../article/index.php?";
  230. if (_view != "") {
  231. url += "view=" + _view;
  232. }
  233. if (_id != "") {
  234. url += "&id=" + _id;
  235. }
  236. if (_book != 0) {
  237. url += "&book=" + _book;
  238. }
  239. if (_par != 0) {
  240. url += "&par=" + _par;
  241. }
  242. if (_start != 0) {
  243. url += "&start=" + _start;
  244. }
  245. if (_end != 0) {
  246. url += "&end=" + _end;
  247. }
  248. if (_collection_id != "") {
  249. url += "&collection=" + _collection_id;
  250. }
  251. if (channalid != "") {
  252. url += "&channal=" + channalid;
  253. }
  254. if (_display != "") {
  255. url += "&display=" + _display;
  256. }
  257. if (_mode != "") {
  258. url += "&mode=" + _mode;
  259. }
  260. if (_direction != "") {
  261. url += "&direction=" + _direction;
  262. }
  263. location.assign(url);
  264. }
  265. function setMode(mode = "read") {
  266. let url = "../article/index.php?";
  267. if (_view != "") {
  268. url += "view=" + _view;
  269. }
  270. if (_id != "") {
  271. url += "&id=" + _id;
  272. }
  273. if (_book != 0) {
  274. url += "&book=" + _book;
  275. }
  276. if (_par != 0) {
  277. url += "&par=" + _par;
  278. }
  279. if (_start != 0) {
  280. url += "&start=" + _start;
  281. }
  282. if (_end != 0) {
  283. url += "&end=" + _end;
  284. }
  285. if (_collection_id != "") {
  286. url += "&collection=" + _collection_id;
  287. }
  288. if (_channal != "") {
  289. url += "&channal=" + _channal;
  290. }
  291. if (_display != "") {
  292. if (mode == "read") {
  293. url += "&display=" + _display;
  294. } else {
  295. url += "&display=sent";
  296. }
  297. }
  298. if (mode != "") {
  299. url += "&mode=" + mode;
  300. }
  301. if (_direction != "") {
  302. url += "&direction=" + _direction;
  303. }
  304. location.assign(url);
  305. }
  306. //跳转到另外一个文章
  307. function gotoArticle(articleId) {
  308. let url = "../article/index.php?view=article&id=" + articleId;
  309. if (_collection_id != "") {
  310. url += "&collection=" + _collection_id;
  311. }
  312. if (_channal != "") {
  313. url += "&channal=" + _channal;
  314. }
  315. if (_display != "") {
  316. url += "&display=" + _display;
  317. }
  318. if (_mode != "") {
  319. url += "&mode=" + _mode;
  320. }
  321. if (_direction != "") {
  322. url += "&direction=" + _direction;
  323. }
  324. location.assign(url);
  325. }
  326. function palicanon_load() {
  327. let param;
  328. switch (_view) {
  329. case "sent":
  330. case "para":
  331. case "chapter":
  332. param = {
  333. view: _view,
  334. book: _book,
  335. par: _par,
  336. start: _start,
  337. end: _end,
  338. }
  339. break;
  340. case "simsent":
  341. case "sim":
  342. param = {view: _view,id:_id};
  343. break;
  344. default:
  345. break;
  346. }
  347. $.get(
  348. "../reader/get_para1.php",
  349. param,
  350. function (data, status) {
  351. if (status == "success") {
  352. try {
  353. let result = JSON.parse(data);
  354. if (result) {
  355. _sent_data=result;
  356. $("#article_title").html(result.title);
  357. $("#article_path_title").html(result.title);
  358. $("#page_title").text(result.title);
  359. $("#article_subtitle").html(result.subtitle);
  360. $("#article_author").html(result.username.nickname + "@" + result.username.username);
  361. $("#contents").html(note_init(result.content));
  362. note_refresh_new(function () {
  363. document.querySelector("#para_focus").scrollIntoView({
  364. block: "end",
  365. behavior: "smooth",
  366. });
  367. });
  368. reader_draw_para_menu();
  369. guide_init();
  370. }
  371. } catch (e) {
  372. console.error(e);
  373. }
  374. } else {
  375. console.error("ajex error");
  376. }
  377. }
  378. );
  379. }
  380. function reader_get_path() {
  381. $.get(
  382. "../reader/get_path.php",
  383. {
  384. book: _book,
  385. para: _par,
  386. },
  387. function (data) {
  388. $("#article_path").html(data);
  389. var bookTitle = $("chapter").first().html();
  390. let suttaTitle = $("chapter").last().html();
  391. $("#pali_pedia").html(bookTitle);
  392. $("#article_title").html(suttaTitle);
  393. $("#page_title").text(suttaTitle);
  394. }
  395. );
  396. }
  397. function reader_draw_para_menu() {
  398. $(".page_number").each(function () {
  399. let strPara = $(this).text();
  400. $(this).addClass("case_dropdown");
  401. let html = "<a name='para_" + strPara + "'></a>";
  402. html += "<div class='case_dropdown-content para_menu'>";
  403. if (typeof _view != "undefined" && _view != "para") {
  404. html += "<a onclick=\"junp_to_para('" + _book + "','" + strPara + "')\">仅显示此段</a>";
  405. }
  406. html += "<a onclick=\"edit_wbw('" + _book + "','" + strPara + "')\">" + gLocal.gui.edit_now + "</a>";
  407. html += "<a onclick='goto_nissaya(" + _book + "," + strPara + ")'>" + gLocal.gui.show_nissaya + "</a>";
  408. html +=
  409. "<a onclick=\"copy_para_ref('" + _book + "','" + strPara + "')\">" + gLocal.gui.copy_link + "</a>";
  410. html +=
  411. "<a onclick=\"copy_text('" +
  412. _book +
  413. "','" +
  414. strPara +
  415. "')\">" +
  416. gLocal.gui.copy +
  417. "“" +
  418. gLocal.gui.pāli +
  419. "”</a>";
  420. html +=
  421. "<a onclick=\"add_to_list('" +
  422. _book +
  423. "','" +
  424. strPara +
  425. "')\">" +
  426. gLocal.gui.add_to_edit_list +
  427. "</a>";
  428. html += "</div>";
  429. $(this).append(html);
  430. });
  431. }
  432. function junp_to_para(book, para) {
  433. let url = "../article/?view=para&book=" + book + "&par=" + para + "&display=sent";
  434. location.assign(url);
  435. }
  436. function copy_para_ref(book, para) {
  437. let output = "";
  438. for (const iterator of _sent_data.sent_list) {
  439. if (iterator.book == book && iterator.paragraph == para) {
  440. output += "{{" + book + "-" + para + "-" + iterator.begin + "-" + iterator.end + "}}\n";
  441. }
  442. }
  443. output += "\n";
  444. copy_to_clipboard(output);
  445. }
  446. function edit_wbw(book, para) {
  447. wbw_channal_list_open(book, [para]);
  448. }
  449. function to_article(){
  450. article_add_dlg_show({
  451. title:_sent_data.title,
  452. content:_sent_data.content,
  453. });
  454. }
  455. var prevChapter=0,nextChapter=0;
  456. var strPrevChapter,strNextChapter;
  457. function render_toc(){
  458. $.getJSON(
  459. "../api/pali_text.php",
  460. {
  461. _method:"index",
  462. view:"toc",
  463. book: _book,
  464. par: _par,
  465. }
  466. ).done(function (data) {
  467. let arrToc = new Array();
  468. for (const it of data.data) {
  469. if(_par==it.paragraph){
  470. nextChapter = it.next_chapter;
  471. prevChapter = it.prev_chapter;
  472. }
  473. arrToc.push({article:it.paragraph,title:it.toc,level:it.level});
  474. }
  475. $("#toc_content").fancytree({
  476. autoScroll: true,
  477. source: tocGetTreeData(arrToc,_par),
  478. activate: function(e, data) {
  479. gotoChapter(data.node.key);
  480. return false;
  481. }
  482. });
  483. switch (_view) {
  484. case "chapter":
  485. fill_chapter_nav();
  486. break;
  487. case "para":
  488. fill_para_nav();
  489. break;
  490. case "sent":
  491. fill_sent_nav();
  492. default:
  493. fill_default_nav();
  494. break;
  495. }
  496. });
  497. }
  498. function fill_sent_nav(){
  499. $("#contents_nav_left").hide();
  500. $("#contents_nav_right").hide();
  501. }
  502. function fill_sent_nav(){
  503. $("#contents_nav_left_inner").html("");
  504. $("#contents_nav_right_inner").html("");
  505. }
  506. function fill_para_nav(){
  507. $("#contents_nav_left_inner").html(_par-1);
  508. $("#contents_nav_right_inner").html(_par+1);
  509. }
  510. function fill_chapter_nav(){
  511. if(prevChapter>0){
  512. $.getJSON(
  513. "../api/pali_text.php",
  514. {
  515. _method:"show",
  516. view:"toc",
  517. book: _book,
  518. par: prevChapter,
  519. }
  520. ).done(function (data) {
  521. $("#contents_nav_left_inner").html(data.data.toc);
  522. });
  523. }else{
  524. $("#contents_nav_left_inner").html("无");
  525. }
  526. if(nextChapter>0){
  527. $.getJSON(
  528. "../api/pali_text.php",
  529. {
  530. _method:"show",
  531. view:"toc",
  532. book: _book,
  533. par: nextChapter,
  534. }
  535. ).done(function (data) {
  536. $("#contents_nav_right_inner").html(data.data.toc);
  537. });
  538. }else{
  539. $("#contents_nav_right_inner").html("无");
  540. }
  541. }
  542. //跳转到另外一个章节
  543. function gotoChapter(paragraph) {
  544. let url = "../article/index.php?view=chapter";
  545. url += "&book=" + _book;
  546. url += "&par=" + paragraph;
  547. if (_channal != "") {
  548. url += "&channal=" + _channal;
  549. }
  550. if (_display != "") {
  551. url += "&display=" + _display;
  552. }
  553. if (_mode != "") {
  554. url += "&mode=" + _mode;
  555. }
  556. if (_direction != "") {
  557. url += "&direction=" + _direction;
  558. }
  559. location.assign(url);
  560. }
  561. //跳转到另外一个章节
  562. function gotoPara(paragraph) {
  563. let url = "../article/index.php?view=para";
  564. url += "&book=" + _book;
  565. url += "&par=" + paragraph;
  566. if (_channal != "") {
  567. url += "&channal=" + _channal;
  568. }
  569. if (_display != "") {
  570. url += "&display=" + _display;
  571. }
  572. if (_mode != "") {
  573. url += "&mode=" + _mode;
  574. }
  575. if (_direction != "") {
  576. url += "&direction=" + _direction;
  577. }
  578. location.assign(url);
  579. }