article.js 14 KB

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