article.js 13 KB

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