article.js 16 KB

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