article.js 12 KB

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