article.js 15 KB

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