palicanon.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  1. var main_tag = "";
  2. var list_tag = new Array();
  3. var currTagLevel0 = new Array();
  4. var allTags = new Array();
  5. var arrMyTerm = new Array();
  6. palicanon_load_term();
  7. function palicanon_onload() {
  8. $("span[tag]").click(function () {
  9. $(this).siblings().removeClass("select");
  10. $(this).addClass("select");
  11. main_tag = $(this).attr("tag");
  12. list_tag = new Array();
  13. tag_changed();
  14. render_tag_list();
  15. });
  16. $("#tag_input").keypress(function () {
  17. tag_render_others();
  18. });
  19. }
  20. function palicanon_load_term() {
  21. $.post(
  22. "../term/get_term_index.php",
  23. {
  24. lang: getCookie("language"),
  25. },
  26. function (data) {
  27. let result = JSON.parse(data);
  28. if (result.status == 0) {
  29. arrMyTerm = result.data;
  30. render_main_tag();
  31. } else {
  32. alert(result.error);
  33. }
  34. }
  35. );
  36. }
  37. function render_main_tag() {
  38. $("#main_tag")
  39. .children()
  40. .each(function () {
  41. $(this).html(tag_get_local_word($(this).attr("tag")));
  42. });
  43. }
  44. function tag_changed() {
  45. let strTags = "";
  46. if (list_tag.length > 0) {
  47. strTags = main_tag + "," + list_tag.join();
  48. } else {
  49. strTags = main_tag;
  50. }
  51. console.log(strTags);
  52. let lang = getCookie("language");
  53. if (lang == "zh-cn") {
  54. lang = "zh-hans";
  55. } else if (lang == "zh-tw") {
  56. lang = "zh-hant";
  57. } else if (lang == "") {
  58. lang = "en";
  59. }
  60. $.get(
  61. "book_tag.php",
  62. {
  63. tag: strTags,
  64. lang: lang,
  65. },
  66. function (data, status) {
  67. let arrBookList = JSON.parse(data);
  68. let html = "";
  69. allTags = new Array();
  70. let arrChapter = new Array();
  71. for (const iterator of arrBookList) {
  72. let tag0 = "";
  73. let tags = iterator.tag.split("::");
  74. let currTag = new Array();
  75. currTag[main_tag] = 1;
  76. for (const scondTag of list_tag) {
  77. currTag[scondTag] = 1;
  78. }
  79. for (let tag of tags) {
  80. if (tag.slice(0, 1) == ":") {
  81. tag = tag.slice(1);
  82. }
  83. if (tag.slice(-1) == ":") {
  84. tag = tag.slice(0, -1);
  85. }
  86. if (currTagLevel0.hasOwnProperty(tag)) {
  87. tag0 = tag;
  88. }
  89. if (!currTag.hasOwnProperty(tag)) {
  90. if (allTags.hasOwnProperty(tag)) {
  91. allTags[tag] += 1;
  92. } else {
  93. allTags[tag] = 1;
  94. }
  95. }
  96. }
  97. if (arrBookList.length < 100 || (arrBookList.length > 100 && iterator.level == 1)) {
  98. arrChapter.push(iterator);
  99. }
  100. }
  101. let newTags = new Array();
  102. for (const oneTag in allTags) {
  103. if (allTags[oneTag] < arrBookList.length) {
  104. newTags[oneTag] = allTags[oneTag];
  105. }
  106. }
  107. allTags = newTags;
  108. allTags.sort(sortNumber);
  109. tag_render_others();
  110. palicanon_chapter_list_apply(0);
  111. $("#list-1").html(render_chapter_list(arrChapter));
  112. }
  113. );
  114. }
  115. function palicanon_load_chapter(book, para, div_index = 1) {
  116. let lang = getCookie("language");
  117. if (lang == "zh-cn") {
  118. lang = "zh-hans";
  119. } else if (lang == "zh-tw") {
  120. lang = "zh-hant";
  121. } else if (lang == "") {
  122. lang = "en";
  123. }
  124. $.get(
  125. "get_chapter_info.php",
  126. {
  127. book: book,
  128. para: para,
  129. lang: lang,
  130. },
  131. function (data, status) {
  132. palicanon_chapter_list_apply(div_index);
  133. let arrChapterInfo = JSON.parse(data);
  134. let html = render_chapter_head(arrChapterInfo, div_index);
  135. $("#chapter_head_" + (parseInt(div_index) + 1)).html(html);
  136. let lang = getCookie("language");
  137. if (lang == "zh-cn") {
  138. lang = "zh-hans";
  139. } else if (lang == "zh-tw") {
  140. lang = "zh-hant";
  141. } else if (lang == "") {
  142. lang = "en";
  143. }
  144. $.get(
  145. "get_chapter_children.php",
  146. {
  147. book: book,
  148. para: para,
  149. lang: lang,
  150. },
  151. function (data, status) {
  152. let arrChapterList = JSON.parse(data);
  153. $("#list-" + (parseInt(div_index) + 1)).html(render_chapter_list(arrChapterList));
  154. //palicanon_chapter_list_apply(arrChapterList, div_index);
  155. }
  156. );
  157. }
  158. );
  159. }
  160. function render_chapter_head(chapter_info, parent) {
  161. let html = "";
  162. html = "<div class='chapter_head_tool_bar'>";
  163. html +=
  164. "<div><span class='chapter_back_button' id='chapter_back_" +
  165. (parent + 1) +
  166. "' onclick=\"chapter_back('" +
  167. parent +
  168. "')\">back</span></div>";
  169. html +=
  170. "<div><span class='chapter_close_button' id='chapter_close_" +
  171. (parent + 1) +
  172. "' onclick=\"chapter_back('" +
  173. parent +
  174. "')\">back</span></div>";
  175. html += "</div>";
  176. let link = "../reader/?view=chapter&book=" + chapter_info.book + "&para=" + chapter_info.paragraph;
  177. html += "<div class='title'>";
  178. if (typeof chapter_info.trans_title == "undefined") {
  179. html += " <div class='title_1'><a href='" + link + "' target='_blank'>" + chapter_info.text + "</a></div>";
  180. } else {
  181. html +=
  182. " <div class='title_1'><a href='" + link + "' target='_blank'>" + chapter_info.trans_title + "</a></div>";
  183. }
  184. html += "<div class='title_2'>" + chapter_info.text + "</div>";
  185. html += "</div>";
  186. html += "<div class='res res_more'>";
  187. html += "<h2>译文</h2>";
  188. html += "<div class='progress'>";
  189. if (chapter_info.progress && chapter_info.progress.length > 0) {
  190. let r = 12;
  191. let perimeter = 2 * Math.PI * r;
  192. for (const iterator of chapter_info.progress) {
  193. let stroke1 = parseInt(perimeter * iterator.all_trans);
  194. let stroke2 = perimeter - stroke1;
  195. html += ' <div class="item">';
  196. html += '<svg class="progress_circle" width="30" height="30" viewbox="0,0,30,30">';
  197. html += '<circle class="progress_bg" cx="15" cy="15" r="12" stroke-width="5" fill="none"></circle>';
  198. html +=
  199. '<circle class="progress_color" cx="15" cy="15" r="12" stroke-width="5" fill="none" stroke-dasharray="' +
  200. stroke1 +
  201. " " +
  202. stroke2 +
  203. '"></circle>';
  204. html += "</svg>";
  205. html += "<div class='lang'>" + iterator.lang + "-" + parseInt(iterator.all_trans * 100) + "%</div>";
  206. html += " </div>";
  207. }
  208. } else {
  209. html += "无译文";
  210. }
  211. html += "</div>";
  212. html += "</div>";
  213. return html;
  214. }
  215. function render_chapter_list(chapterList) {
  216. let html = "";
  217. for (const iterator of chapterList) {
  218. html += palicanon_render_chapter_row(iterator);
  219. }
  220. return html;
  221. }
  222. function palicanon_chapter_list_apply(div_index) {
  223. let iDiv = parseInt(div_index);
  224. let html = "";
  225. html += "<div id='chapter_head_" + (iDiv + 1) + "' class='chapter_head'></div>";
  226. html += "<ul id='list-" + (iDiv + 1) + "' class='grid' level='" + (iDiv + 1) + "'>";
  227. /*
  228. for (const iterator of chapterList) {
  229. html += palicanon_render_chapter_row(iterator);
  230. }
  231. */
  232. html += "</ul>";
  233. $("#list_shell_" + (iDiv + 1)).html(html);
  234. $("#list_shell_" + (iDiv + 1)).removeClass();
  235. $("#list_shell_" + (iDiv + 1)).addClass("show");
  236. //隐藏之后的列表
  237. for (let index = iDiv + 2; index <= 8; index++) {
  238. $("#list_shell_" + index).removeClass();
  239. $("#list_shell_" + index).addClass("hidden");
  240. }
  241. //收缩当前的
  242. $("#list-" + iDiv).removeClass();
  243. $("#list-" + iDiv).addClass("list");
  244. $("#list_shell_" + iDiv).removeClass();
  245. $("#list_shell_" + iDiv).addClass("list");
  246. }
  247. function chapter_onclick(obj) {
  248. let book = $(obj).attr("book");
  249. let para = $(obj).attr("para");
  250. let level = $(obj).parent().attr("level");
  251. $(obj).siblings().removeClass("selected");
  252. $(obj).addClass("selected");
  253. $("#tag_list").slideUp();
  254. palicanon_load_chapter(book, para, level);
  255. }
  256. function palicanon_render_chapter_row(chapter) {
  257. let html = "";
  258. let levelClass = "";
  259. if (chapter.level == 1) {
  260. levelClass = " level_1";
  261. }
  262. html +=
  263. '<li class="' +
  264. levelClass +
  265. '" book="' +
  266. chapter.book +
  267. '" para="' +
  268. chapter.para +
  269. '" onclick="chapter_onclick(this)">';
  270. html += '<div class="title">';
  271. if (typeof chapter.trans_title == "undefined") {
  272. html += " <div class='title_1'>" + chapter.title + "</div>";
  273. } else {
  274. html += " <div class='title_1'>" + chapter.trans_title + "</div>";
  275. }
  276. html += ' <div class="title_2" lang="pali">' + chapter.title + "</div>";
  277. html += "</div>";
  278. html += '<div class="resource">';
  279. if (chapter.progress) {
  280. let r = 12;
  281. let perimeter = 2 * Math.PI * r;
  282. let stroke1 = parseInt(perimeter * chapter.progress.all_trans);
  283. let stroke2 = perimeter - stroke1;
  284. html += '<svg class="progress_circle" width="30" height="30" viewbox="0,0,30,30">';
  285. html += '<circle class="progress_bg" cx="15" cy="15" r="12" stroke-width="5" fill="none"></circle>';
  286. html +=
  287. '<circle class="progress_color" cx="15" cy="15" r="12" stroke-width="5" fill="none" stroke-dasharray="' +
  288. stroke1 +
  289. " " +
  290. stroke2 +
  291. '"></circle>';
  292. html += "</svg>";
  293. }
  294. html += '<div class="res_more">';
  295. html += " ";
  296. html += " </div>";
  297. html += "</div>";
  298. html += "</li>";
  299. return html;
  300. }
  301. function tag_get_local_word(word) {
  302. let termKey = term_lookup_my(word, "", getCookie("userid"), getCookie("language"));
  303. if (termKey) {
  304. return termKey.meaning;
  305. } else {
  306. return word;
  307. }
  308. }
  309. function tag_render_others() {
  310. let strOthersTag = "";
  311. currTagLevel0 = new Array();
  312. $(".tag_others").html("");
  313. document.getElementById("main_tag").style.margin = 1 + "em";
  314. document.getElementById("main_tag").style.fontSize = 100 + "%";
  315. for (const key in allTags) {
  316. if (allTags.hasOwnProperty(key)) {
  317. if ($("#tag_input").val().length > 0) {
  318. if (key.indexOf($("#tag_input").val()) >= 0) {
  319. strOthersTag =
  320. '<button class="canon-tag" onclick ="tag_click(\'' + key + "')\" >" + key + "</button>";
  321. }
  322. } else {
  323. let keyname = tag_get_local_word(key);
  324. strOthersTag =
  325. '<button class="canon-tag" title="' +
  326. key +
  327. '" onclick ="tag_click(\'' +
  328. key +
  329. "')\" >" +
  330. keyname +
  331. "</button>";
  332. }
  333. let thisLevel = 100;
  334. if (tag_level.hasOwnProperty(key)) {
  335. thisLevel = tag_level[key].level;
  336. if (tag_level[key].level == 0) {
  337. currTagLevel0[key] = 1;
  338. }
  339. }
  340. $(".tag_others[level='" + thisLevel + "']").html(
  341. $(".tag_others[level='" + thisLevel + "']").html() + strOthersTag
  342. );
  343. }
  344. }
  345. }
  346. function tag_click(tag) {
  347. list_tag.push(tag);
  348. render_tag_list();
  349. tag_changed();
  350. }
  351. function render_tag_list() {
  352. $("#tag_list").slideDown();
  353. let strListTag = gLocal.gui.selected + ":";
  354. for (const iterator of list_tag) {
  355. strListTag += '<tag><span class="textt" title="' + iterator + '">' + tag_get_local_word(iterator) + "</span>";
  356. strListTag += '<span class="tag-delete" onclick ="tag_remove(\'' + iterator + "')\">✕</span></tag>";
  357. }
  358. strListTag +=
  359. "<div style='display:inline-block;width:20em;'>" +
  360. "<input id='tag_input' type='input' placeholder='tag' size='20' />" +
  361. "</div>";
  362. $("#tag_selected").html(strListTag);
  363. }
  364. function tag_remove(tag) {
  365. for (let i = 0; i < list_tag.length; i++) {
  366. if (list_tag[i] == tag) {
  367. list_tag.splice(i, 1);
  368. }
  369. }
  370. render_tag_list();
  371. tag_changed();
  372. }
  373. function sortNumber(a, b) {
  374. return b - a;
  375. }
  376. function tag_list_slide_toggle(element) {
  377. if($(element).html().indexOf("⮟")!= -1){
  378. $(element).html("⮝")
  379. }
  380. else{
  381. $(element).html("⮟")
  382. }
  383. $("#tag_list").slideToggle();
  384. }
  385. function chapter_back(parent) {
  386. let curr = parseInt(parent) + 1;
  387. let prt = parseInt(parent);
  388. //隐藏当前的
  389. $("#list_shell_" + curr).removeClass();
  390. $("#list_shell_" + curr).addClass("hidden");
  391. //展开上一个
  392. $("#list-" + prt).removeClass();
  393. $("#list-" + prt).addClass("grid");
  394. $("#list_shell_" + prt).removeClass();
  395. $("#list_shell_" + prt).addClass("show");
  396. }