article.js 14 KB

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