note.js 27 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048
  1. var _display = "";
  2. var _word = "";
  3. var _channal = "";
  4. var _lang = "";
  5. var _author = "";
  6. var _arrData = new Array();
  7. var _channalData;
  8. var MAX_NOTE_NEST = 2;
  9. var gBuildinDictIsOpen = false;
  10. /*
  11. {{203-1654-23-45@11@en@*}}
  12. <note>203-1654-23-45@11@en@*</note>
  13. <note id=guid book=203 para=1654 begin=23 end=45 author=11 lang=en tag=*></note>
  14. <note id=guid book=203 para=1654 begin=23 end=45 author=11 lang=en tag=*>
  15. <div class=text>
  16. pali text
  17. </div>
  18. <tran>
  19. </tran>
  20. <ref>
  21. </ref>
  22. </note>
  23. */
  24. /*
  25. 解析百科字符串
  26. {{203-1654-23-45@11@en@*}}
  27. <note id=12345 info="203-1654-23-45@11@en@*"><note>
  28. <note id="guid" book=203 para=1654 begin=23 end=45 author=11 lang=en tag=*></note>
  29. */
  30. function note_create() {
  31. wbw_channal_list_init();
  32. note_sent_edit_dlg_init();
  33. term_edit_dlg_init();
  34. pali_sim_dlg_init();
  35. related_para_dlg_init();
  36. }
  37. function note_sent_edit_dlg_init() {
  38. $("body").append(
  39. '<div id="note_sent_edit_dlg" title="' +
  40. gLocal.gui.edit +
  41. '"><guide gid="markdown_guide"></guide><div id="edit_dialog_content"></div></div>'
  42. );
  43. guide_init();
  44. $("#note_sent_edit_dlg").dialog({
  45. autoOpen: false,
  46. width: 550,
  47. buttons: [
  48. {
  49. text: gLocal.gui.save,
  50. click: function () {
  51. note_sent_save();
  52. $(this).dialog("close");
  53. },
  54. },
  55. {
  56. text: gLocal.gui.cancel,
  57. click: function () {
  58. $(this).dialog("close");
  59. },
  60. },
  61. ],
  62. });
  63. }
  64. function note_init(input) {
  65. if (input) {
  66. let newString = input.replace(/\{\{/g, '<div class="note_shell"><note info="');
  67. newString = newString.replace(/\}\}/g, '" ></note></div>');
  68. let output = "<div>";
  69. output += marked(newString);
  70. output += "</div>";
  71. return output;
  72. } else {
  73. return "";
  74. }
  75. }
  76. function note_update_background_style() {
  77. var mSentsBook = new Array();
  78. var mBgIndex = 1;
  79. $("note[info]").each(function () {
  80. let info = $(this).attr("info").split("-");
  81. if (info.length >= 2) {
  82. let book = info[0];
  83. $(this).attr("book", book);
  84. if (!mSentsBook[book]) {
  85. mSentsBook[book] = mBgIndex;
  86. mBgIndex++;
  87. }
  88. $(this).addClass("bg_color_" + mSentsBook[book]);
  89. }
  90. });
  91. }
  92. //
  93. function note_refresh_new() {
  94. note_update_background_style();
  95. let objNotes = document.querySelectorAll("note");
  96. let arrSentInfo = new Array();
  97. for (const iterator of objNotes) {
  98. let id = iterator.id;
  99. if (id == null || id == "") {
  100. //查看这个节点是第几层note嵌套。大于预定层数退出。
  101. let layout = 1;
  102. let parent = iterator.parentNode;
  103. while (parent.nodeType == 1) {
  104. if (parent.nodeName == "NOTE") {
  105. layout++;
  106. if (layout > MAX_NOTE_NEST) {
  107. return false;
  108. }
  109. } else if (parent.nodeName == "BODY") {
  110. break;
  111. }
  112. parent = parent.parentNode;
  113. }
  114. id = com_guid();
  115. iterator.id = id;
  116. if (iterator.hasAttribute("info")) {
  117. let info = iterator.getAttribute("info");
  118. if (info != null || info != "") {
  119. /*
  120. let arrInfo = info.split("-");
  121. if (arrInfo.length >= 2) {
  122. let book = arrInfo[0];
  123. let para = arrInfo[1];
  124. }
  125. */
  126. arrSentInfo.push({ id: id, data: info });
  127. }
  128. }
  129. }
  130. }
  131. if (arrSentInfo.length > 0) {
  132. let setting = new Object();
  133. setting.lang = "";
  134. setting.channal = _channal;
  135. $.post(
  136. "../term/note.php",
  137. {
  138. setting: JSON.stringify(setting),
  139. data: JSON.stringify(arrSentInfo),
  140. },
  141. function (data, status) {
  142. if (status == "success") {
  143. try {
  144. let sentData = JSON.parse(data);
  145. for (const iterator of sentData) {
  146. let id = iterator.id;
  147. let strHtml = "<a name='" + id + "'></a>";
  148. if (_display && _display == "para") {
  149. //段落模式
  150. let strPalitext =
  151. "<pali book='" +
  152. iterator.book +
  153. "' para='" +
  154. iterator.para +
  155. "' begin='" +
  156. iterator.begin +
  157. "' end='" +
  158. iterator.end +
  159. "' >" +
  160. iterator.palitext +
  161. "</pali>";
  162. let divPali = $("#" + id)
  163. .parent()
  164. .children(".palitext");
  165. if (divPali.length == 0) {
  166. if (_channal != "") {
  167. let arrChannal = _channal.split(",");
  168. for (let index = arrChannal.length - 1; index >= 0; index--) {
  169. const iChannal = arrChannal[index];
  170. $("#" + id)
  171. .parent()
  172. .prepend("<div class='tran_div' channal='" + iChannal + "'></div>");
  173. }
  174. }
  175. $("#" + id)
  176. .parent()
  177. .prepend("<div class='palitext'></div>");
  178. }
  179. $("#" + id)
  180. .parent()
  181. .children(".palitext")
  182. .first()
  183. .append(strPalitext);
  184. let htmlTran = "";
  185. for (const oneTran of iterator.translation) {
  186. let html =
  187. "<span class='tran' lang='" +
  188. oneTran.lang +
  189. "' channal='" +
  190. oneTran.channal +
  191. "'>";
  192. html += marked(
  193. term_std_str_to_tran(
  194. oneTran.text,
  195. oneTran.channal,
  196. oneTran.editor,
  197. oneTran.lang
  198. )
  199. );
  200. html += "</span>";
  201. if (_channal == "") {
  202. htmlTran += html;
  203. } else {
  204. $("#" + id)
  205. .siblings(".tran_div[channal='" + oneTran.channal + "']")
  206. .append(html);
  207. }
  208. }
  209. $("#" + id).html(htmlTran);
  210. } else {
  211. //句子模式
  212. strHtml += note_json_html(iterator);
  213. $("#" + id).html(strHtml);
  214. }
  215. }
  216. //处理<code>标签作为气泡注释
  217. popup_init();
  218. //刷新句子链接递归,有加层数限制。
  219. //note_refresh_new();
  220. //将新的数据添加到数据总表
  221. _arrData = _arrData.concat(sentData);
  222. note_ref_init();
  223. //获取术语字典
  224. term_get_dict();
  225. //刷新channel列表
  226. note_channal_list();
  227. //显示不同的巴利语脚本
  228. refresh_pali_script();
  229. //把巴利语单词用<w>分隔用于点词查询等
  230. splite_pali_word();
  231. } catch (e) {
  232. console.error(e);
  233. }
  234. }
  235. }
  236. );
  237. } else {
  238. //term_get_dict();
  239. }
  240. }
  241. //生成channel列表
  242. function note_channal_list() {
  243. console.log("note_channal_list start");
  244. let arrSentInfo = new Array();
  245. $("note").each(function () {
  246. let info = $(this).attr("info");
  247. if (info && info != "") {
  248. arrSentInfo.push({ id: "", data: info });
  249. }
  250. });
  251. if (arrSentInfo.length > 0) {
  252. $.post(
  253. "../term/channal_list.php",
  254. {
  255. setting: "",
  256. data: JSON.stringify(arrSentInfo),
  257. },
  258. function (data, status) {
  259. if (status == "success") {
  260. try {
  261. let active = JSON.parse(data);
  262. _channalData = active;
  263. for (const iterator of _my_channal) {
  264. let found = false;
  265. for (const one of active) {
  266. if (iterator.id == one.id) {
  267. found = true;
  268. break;
  269. }
  270. }
  271. if (found == false) {
  272. _channalData.push(iterator);
  273. }
  274. }
  275. let strHtml = "";
  276. for (const iterator of _channalData) {
  277. if (_channal.indexOf(iterator.id) >= 0) {
  278. strHtml += render_channal_list(iterator);
  279. }
  280. }
  281. for (const iterator of _channalData) {
  282. if (_channal.indexOf(iterator.id) == -1) {
  283. strHtml += render_channal_list(iterator);
  284. }
  285. }
  286. $("#channal_list").html(strHtml);
  287. set_more_button_display();
  288. } catch (e) {
  289. console.error(e);
  290. }
  291. }
  292. }
  293. );
  294. }
  295. }
  296. function find_channal(id) {
  297. for (const iterator of _channalData) {
  298. if (id == iterator.id) {
  299. return iterator;
  300. }
  301. }
  302. return false;
  303. }
  304. function render_channal_list(channalinfo) {
  305. let output = "";
  306. let checked = "";
  307. let selected = "noselect";
  308. if (_channal.indexOf(channalinfo.id) >= 0) {
  309. checked = "checked";
  310. selected = "selected";
  311. }
  312. output += "<div class='list_with_head " + selected + "'>";
  313. output +=
  314. '<div class="channel_select"><input type="checkbox" ' + checked + " channal_id='" + channalinfo.id + "'></div>";
  315. output += "<div class='head'>";
  316. output += "<span class='head_img'>";
  317. if (channalinfo.nickname == "_you_") {
  318. output += gLocal.gui.your.slice(0, 1);
  319. } else {
  320. output += channalinfo.nickname.slice(0, 1);
  321. }
  322. output += "</span>";
  323. output += "</div>";
  324. output += "<div style='width: 100%;overflow-x: hidden;'>";
  325. output += "<div class='channal_list' >";
  326. // output += "<a href='../wiki/wiki.php?word=" + _word;
  327. // output += "&channal=" + channalinfo.id + "' >";
  328. output += "<a onclick=\"set_channal('" + channalinfo.id + "')\">";
  329. output += channalinfo["name"];
  330. output += "</a>";
  331. if (channalinfo.nickname == "_you_") {
  332. output += "@" + gLocal.gui.your;
  333. } else {
  334. output += "@" + channalinfo["nickname"];
  335. }
  336. output += "</div>";
  337. output += "<div class='userinfo_channal'>";
  338. output += channalinfo["username"];
  339. output += "</div>";
  340. if (channalinfo["final"]) {
  341. //进度
  342. output += "<div>";
  343. let article_len = channalinfo["article_len"];
  344. let svg_width = article_len;
  345. let svg_height = parseInt(article_len / 10);
  346. output += '<svg viewBox="0 0 ' + svg_width + " " + svg_height + '" width="100%" >';
  347. let curr_x = 0;
  348. let allFinal = 0;
  349. for (const iterator of channalinfo["final"]) {
  350. let stroke_width = parseInt(iterator.len);
  351. output += "<rect ";
  352. output += ' x="' + curr_x + '"';
  353. output += ' y="0"';
  354. output += ' height="' + svg_height + '"';
  355. output += ' width="' + stroke_width + '"';
  356. if (iterator.final == true) {
  357. allFinal += stroke_width;
  358. output += ' class="progress_bar_done" ';
  359. } else {
  360. output += ' class="progress_bar_undone" ';
  361. }
  362. output += "/>";
  363. curr_x += stroke_width;
  364. }
  365. output +=
  366. "<rect x='0' y='0' width='" + svg_width + "' height='" + svg_height / 5 + "' class='progress_bar_bg' />";
  367. output +=
  368. "<rect x='0' y='0' width='" +
  369. allFinal +
  370. "' height='" +
  371. svg_height / 5 +
  372. "' class='progress_bar_percent' style='stroke-width: 0; fill: rgb(100, 228, 100);'/>";
  373. output += '<text x="0" y="' + svg_height + '" font-size="' + svg_height * 0.8 + '">';
  374. output += channalinfo["count"] + "/" + channalinfo["all"];
  375. output += "</text>";
  376. output += "<svg>";
  377. output += "</div>";
  378. //进度结束
  379. }
  380. output += "</div>";
  381. output += "</div>";
  382. return output;
  383. }
  384. function onChannelMultiSelectStart() {
  385. $(".channel_select").show();
  386. }
  387. function onChannelMultiSelectCancel() {
  388. $(".channel_select").hide();
  389. }
  390. function onChannelChange() {
  391. let channal_list = new Array();
  392. $("[channal_id]").each(function () {
  393. if (this.checked) {
  394. channal_list.push($(this).attr("channal_id"));
  395. }
  396. });
  397. set_channal(channal_list.join());
  398. }
  399. //点击引用 需要响应的事件
  400. function note_ref_init() {
  401. $("chapter").click(function () {
  402. let bookid = $(this).attr("book");
  403. let para = $(this).attr("para");
  404. window.open("../reader/?view=chapter&book=" + bookid + "&para=" + para, "_blank");
  405. });
  406. $("para").click(function () {
  407. let bookid = $(this).attr("book");
  408. let para = $(this).attr("para");
  409. window.open("../reader/?view=para&book=" + bookid + "&para=" + para, "_blank");
  410. });
  411. }
  412. /*
  413. id
  414. palitext
  415. tran
  416. ref
  417. */
  418. function note_json_html(in_json) {
  419. let output = "";
  420. output += '<div class="note_tool_bar" style=" position: relative;">';
  421. output += '<div class="case_dropdown note_tool_context" >';
  422. output += "<svg class='icon' >";
  423. output += "<use xlink:href='../studio/svg/icon.svg#ic_more'></use>";
  424. output += "</svg>";
  425. output += "<div class='case_dropdown-content sent_menu'>";
  426. if (typeof _reader_view != "undefined" && _reader_view != "sent") {
  427. output += "<a onclick='junp_to(this)'>" + gLocal.gui.jump_to_this_sent + "</a>";
  428. }
  429. output +=
  430. "<a onclick='related_para_dlg_open(" +
  431. in_json.book +
  432. "," +
  433. in_json.para +
  434. ")'>" +
  435. gLocal.gui.related_para +
  436. "</a>";
  437. output +=
  438. "<a onclick='goto_nissaya(" +
  439. in_json.book +
  440. "," +
  441. in_json.para +
  442. "," +
  443. in_json.begin +
  444. "," +
  445. in_json.end +
  446. ")'>" +
  447. gLocal.gui.show_nissaya +
  448. "</a>";
  449. output +=
  450. "<a onclick=\"copy_ref('" +
  451. in_json.book +
  452. "','" +
  453. in_json.para +
  454. "','" +
  455. in_json.begin +
  456. "','" +
  457. in_json.end +
  458. "')\">" +
  459. gLocal.gui.copy_link +
  460. "</a>";
  461. output += "<a onclick='copy_text(this)'>" + gLocal.gui.copy + "“" + gLocal.gui.pāli + "”</a>";
  462. output +=
  463. "<a onclick=\"edit_in_studio('" +
  464. in_json.book +
  465. "','" +
  466. in_json.para +
  467. "','" +
  468. in_json.begin +
  469. "','" +
  470. in_json.end +
  471. "')\">" +
  472. gLocal.gui.edit_now +
  473. "</a>";
  474. output += "<a onclick='add_to_list()'>" + gLocal.gui.add_to_edit_list + "</a>";
  475. output += "<a onclick='slider_show(this)'>Slider Show</a>";
  476. output += "</div>";
  477. output += "</div>";
  478. output += " </div>";
  479. output += "<div class='palitext palitext_roma'>" + in_json.palitext + "</div>";
  480. output += "<div class='palitext palitext1'></div>";
  481. output += "<div class='palitext palitext2'></div>";
  482. //output += "<div id='translation_div'>";
  483. for (const iterator of in_json.translation) {
  484. output += render_one_sent_tran(in_json.book, in_json.para, in_json.begin, in_json.end, iterator);
  485. }
  486. //所选全部译文结束
  487. //output += "</div>";
  488. //未选择的其他译文开始
  489. output += "<div class='other_tran_div' sent='";
  490. output += in_json.book + "-" + in_json.para + "-" + in_json.begin + "-" + in_json.end + "' >";
  491. output += "<div class='tool_bar' sent='";
  492. output += in_json.book + "-" + in_json.para + "-" + in_json.begin + "-" + in_json.end + "' >";
  493. output += "<span class='more_tran icon_expand'></span>";
  494. //其他译文工具条
  495. output += "<span class='other_bar' >";
  496. output += "<span class='other_tran_span' >" + gLocal.gui.other + gLocal.gui.translation + "</span>";
  497. output += "<span class='other_tran_num'></span>";
  498. output += "</span>";
  499. output += "<span class='separate_line'></span>";
  500. //相似句工具条
  501. output += "<span class='other_bar' >";
  502. output +=
  503. "<span class='similar_sent_span' onclick=\"note_show_pali_sim('" +
  504. in_json.pali_sent_id +
  505. "')\">" +
  506. gLocal.gui.similar_sentences +
  507. "</span>";
  508. output += "<span class='similar_sent_num'>" + in_json.sim + "</span>";
  509. output += "</span>";
  510. output += "</div>";
  511. output += "<div class='other_tran'>";
  512. output += "</div>";
  513. output += "</div>";
  514. //未选择的其他译文开始
  515. //新增译文按钮开始
  516. output += "<div class='add_new icon_add' ";
  517. output += "book='" + in_json.book + "' ";
  518. output += "para='" + in_json.para + "' ";
  519. output += "begin='" + in_json.begin + "' ";
  520. output += "end='" + in_json.end + "' ";
  521. output += " >";
  522. output += "<div class='icon_add' onclick='add_new_tran_button_click(this)'></div>";
  523. output += "<div class='tran_text_tool_bar'>";
  524. output += "</div>";
  525. output += "</div>";
  526. //新增译文按钮结束
  527. //出处路径开始
  528. output += "<div class='ref'>" + in_json.ref;
  529. output +=
  530. "<span class='sent_no'>" +
  531. in_json.book +
  532. "-" +
  533. in_json.para +
  534. "-" +
  535. in_json.begin +
  536. "-" +
  537. in_json.end +
  538. "<span>" +
  539. "</div>";
  540. //出处路径结束
  541. return output;
  542. }
  543. function render_one_sent_tran(book, para, begin, end, iterator) {
  544. let output = "";
  545. output += "<div class='tran' lang='" + iterator.lang + "' style='display:flex;'>";
  546. //译文工具按钮开始
  547. output += "<div class='tran_text_tool_botton' onclick='tool_bar_show(this)'>";
  548. output +=
  549. "<div class='icon_expand' style='width: 0.8em;height: 0.8em;min-width: 0.8em;min-height: 0.8em;transition: transform 0.5s ease;'></div>";
  550. //译文工具栏开始
  551. output += "<div class='tran_text_tool_bar'>";
  552. output += "<div style='border-right: solid 1px;margin: 0.3em 0;'><li class = 'tip_buttom' ";
  553. output +=
  554. " onclick=\"note_edit_sentence('" +
  555. book +
  556. "' ,'" +
  557. para +
  558. "' ,'" +
  559. begin +
  560. "' ,'" +
  561. end +
  562. "' ,'" +
  563. iterator.channal +
  564. "')\"";
  565. output +=
  566. ">" +
  567. '<svg class="icon" ><use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#ic_mode_edit"></use></svg>';
  568. output += gLocal.gui.edit + "</li>";
  569. output += "<li class = 'tip_buttom' ";
  570. output += " onclick=\"history_show('" + iterator.id + "')\"";
  571. output +=
  572. ">" +
  573. '<svg class="icon" ><use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#recent_scan"></use></svg>';
  574. output += gLocal.gui.timeline + "</li>";
  575. output +=
  576. "<li class = 'tip_buttom'>" +
  577. '<svg class="icon" ><use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#copy"></use></svg>';
  578. output += gLocal.gui.copy + "</li></div>";
  579. output +=
  580. "<div style='border-right: solid 1px;margin: 0.3em 0;'><li class = 'tip_buttom'>" +
  581. '<svg class="icon" ><use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#like"></use></svg>';
  582. output += gLocal.gui.like + "</li>";
  583. output +=
  584. "<li class = 'tip_buttom'>" +
  585. '<svg class="icon" ><use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#comment"></use></svg>';
  586. output += gLocal.gui.comment + "</li>";
  587. output +=
  588. "<li class = 'tip_buttom'>" +
  589. '<svg class="icon" ><use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#ic_shopping_cart"></use></svg>';
  590. output += gLocal.gui.digest + "</li></div>";
  591. output +=
  592. "<div style='margin: 0.3em 0;'><li class = 'tip_buttom'>" +
  593. '<svg class="icon" ><use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#share_to"></use></svg>';
  594. output += gLocal.gui.share_to + "</li>";
  595. output += "</div></div>";
  596. //译文工具栏结束
  597. output += "</div>";
  598. //译文工具按钮结束
  599. //译文正文开始
  600. output +=
  601. "<div class='text' id='tran_text_" +
  602. book +
  603. "_" +
  604. para +
  605. "_" +
  606. begin +
  607. "_" +
  608. end +
  609. "_" +
  610. iterator.channal +
  611. "'>";
  612. if (iterator.text == "") {
  613. output +=
  614. "<span style='color:var(--border-line-color);'>" +
  615. iterator.channalinfo.name +
  616. "-" +
  617. iterator.channalinfo.lang +
  618. "</span>";
  619. } else {
  620. //note_init处理句子链接
  621. output += note_init(term_std_str_to_tran(iterator.text, iterator.channal, iterator.editor, iterator.lang));
  622. }
  623. output += "</div>";
  624. //译文正文结束
  625. output += "</div>";
  626. //单个channal译文框结束
  627. return output;
  628. }
  629. function add_new_tran_button_click(obj) {
  630. let html = "<ul>";
  631. for (const iterator of _my_channal) {
  632. if (_channal.indexOf(iterator.id) < 0) {
  633. html += '<li onclick="';
  634. html +=
  635. "new_sentence('" +
  636. $(obj).parent().attr("book") +
  637. "' ,'" +
  638. $(obj).parent().attr("para") +
  639. "' ,'" +
  640. $(obj).parent().attr("begin") +
  641. "' ,'" +
  642. $(obj).parent().attr("end") +
  643. "' ,'" +
  644. iterator.id +
  645. "',this)";
  646. html += '">' + iterator.name;
  647. if (parseInt(iterator.power) < 20) {
  648. html += "(建议)";
  649. }
  650. html += "</li>";
  651. }
  652. }
  653. html += "</ul>";
  654. $(obj).parent().children(".tran_text_tool_bar").first().html(html);
  655. if ($(obj).parent().children(".tran_text_tool_bar").css("display") == "block") {
  656. $(obj).parent().children(".tran_text_tool_bar").first().hide();
  657. } else {
  658. $(obj).parent().children(".tran_text_tool_bar").first().show();
  659. $(obj).parent().show();
  660. }
  661. }
  662. function new_sentence(book, para, begin, end, channel, obj) {
  663. let newsent = { id: "", text: "", lang: "", channal: channel };
  664. for (let iterator of _arrData) {
  665. if (iterator.book == book && iterator.para == para && iterator.begin == begin && iterator.end == end) {
  666. let found = false;
  667. for (const tran of iterator.translation) {
  668. if (tran.channal == channel) {
  669. found = true;
  670. break;
  671. }
  672. }
  673. if (!found) {
  674. iterator.translation.push(newsent);
  675. }
  676. }
  677. }
  678. if ($(obj).parent().parent().css("display") == "block") {
  679. $(obj).parent().parent().hide();
  680. }
  681. note_edit_sentence(book, para, begin, end, channel);
  682. }
  683. //显示更多译文按钮动作
  684. function set_more_button_display() {
  685. $(".other_tran_div").each(function () {
  686. const sentid = $(this).attr("sent").split("-");
  687. const book = sentid[0];
  688. const para = sentid[1];
  689. const begin = sentid[2];
  690. const end = sentid[3];
  691. let count = 0;
  692. for (const iterator of _channalData) {
  693. if (iterator.final) {
  694. for (const onesent of iterator.final) {
  695. let id = onesent.id.split("-");
  696. if (book == id[0] && para == id[1] && begin == id[2] && end == id[3] && onesent.final) {
  697. if (_channal.indexOf(iterator.id) == -1) {
  698. count++;
  699. }
  700. }
  701. }
  702. }
  703. }
  704. if (count > 0) {
  705. $(this).find(".other_tran_num").html(count);
  706. $(this).find(".other_tran_num").attr("style", "display:inline-flex;");
  707. $(this)
  708. .find(".other_bar")
  709. .click(function () {
  710. const sentid = $(this).parent().attr("sent").split("-");
  711. const book = sentid[0];
  712. const para = sentid[1];
  713. const begin = sentid[2];
  714. const end = sentid[3];
  715. let sentId = book + "-" + para + "-" + begin + "-" + end;
  716. if ($(this).parent().siblings(".other_tran").first().css("display") == "none") {
  717. $(".other_tran_div[sent='" + sentId + "']")
  718. .children(".other_tran")
  719. .slideDown();
  720. $(this).siblings(".more_tran ").css("transform", "unset");
  721. $.get(
  722. "../usent/get.php",
  723. {
  724. book: book,
  725. para: para,
  726. begin: begin,
  727. end: end,
  728. },
  729. function (data, status) {
  730. let arrSent = JSON.parse(data);
  731. let html = "";
  732. for (const iterator of arrSent) {
  733. if (_channal.indexOf(iterator.channal) == -1) {
  734. html += "<div>" + marked(iterator.text) + "</div>";
  735. }
  736. }
  737. let sentId =
  738. arrSent[0].book +
  739. "-" +
  740. arrSent[0].paragraph +
  741. "-" +
  742. arrSent[0].begin +
  743. "-" +
  744. arrSent[0].end;
  745. $(".other_tran_div[sent='" + sentId + "']")
  746. .children(".other_tran")
  747. .html(html);
  748. }
  749. );
  750. } else {
  751. $(".other_tran_div[sent='" + sentId + "']")
  752. .children(".other_tran")
  753. .slideUp();
  754. $(this).siblings(".more_tran ").css("transform", "rotate(-90deg)");
  755. }
  756. });
  757. } else {
  758. //隐藏自己
  759. //$(this).hide();
  760. $(this)
  761. .find(".other_tran_span")
  762. .html(gLocal.gui.no + gLocal.gui.other + gLocal.gui.translation);
  763. //$(this).find(".more_tran").hide();
  764. }
  765. });
  766. }
  767. function note_edit_sentence(book, para, begin, end, channal) {
  768. let channalInfo;
  769. for (const iterator of _channalData) {
  770. if (iterator.id == channal) {
  771. channalInfo = iterator;
  772. break;
  773. }
  774. }
  775. for (const iterator of _arrData) {
  776. if (iterator.book == book && iterator.para == para && iterator.begin == begin && iterator.end == end) {
  777. for (const tran of iterator.translation) {
  778. if (tran.channal == channal) {
  779. let html = "";
  780. html += "<div style='color:blue;'>" + channalInfo.name + "@" + channalInfo.nickname + "</div>";
  781. html +=
  782. "<textarea id='edit_dialog_text' sent_id='" +
  783. tran.id +
  784. "' book='" +
  785. book +
  786. "' para='" +
  787. para +
  788. "' begin='" +
  789. begin +
  790. "' end='" +
  791. end +
  792. "' channal='" +
  793. channal +
  794. "' style='width:100%;min-height:260px;'>" +
  795. tran.text +
  796. "</textarea>";
  797. $("#edit_dialog_content").html(html);
  798. $("#note_sent_edit_dlg").dialog("open");
  799. return;
  800. }
  801. }
  802. }
  803. }
  804. alert("未找到句子");
  805. }
  806. function note_sent_save() {
  807. let id = $("#edit_dialog_text").attr("sent_id");
  808. let book = $("#edit_dialog_text").attr("book");
  809. let para = $("#edit_dialog_text").attr("para");
  810. let begin = $("#edit_dialog_text").attr("begin");
  811. let end = $("#edit_dialog_text").attr("end");
  812. let channal = $("#edit_dialog_text").attr("channal");
  813. let text = $("#edit_dialog_text").val();
  814. $.post(
  815. "../usent/sent_post.php",
  816. {
  817. id: id,
  818. book: book,
  819. para: para,
  820. begin: begin,
  821. end: end,
  822. channal: channal,
  823. text: text,
  824. lang: "zh",
  825. },
  826. function (data) {
  827. let result = JSON.parse(data);
  828. if (result.status > 0) {
  829. alert("error" + result.message);
  830. } else {
  831. ntf_show("success");
  832. if (result.text == "") {
  833. let channel_info = "Empty";
  834. let thisChannel = find_channal(result.channal);
  835. if (thisChannel) {
  836. channel_info = thisChannel.name + "-" + thisChannel.nickname;
  837. }
  838. $(
  839. "#tran_text_" +
  840. result.book +
  841. "_" +
  842. result.para +
  843. "_" +
  844. result.begin +
  845. "_" +
  846. result.end +
  847. "_" +
  848. result.channal
  849. ).html("<span style='color:var(--border-line-color);'>" + channel_info + "</span>");
  850. } else {
  851. $(
  852. "#tran_text_" +
  853. result.book +
  854. "_" +
  855. result.para +
  856. "_" +
  857. result.begin +
  858. "_" +
  859. result.end +
  860. "_" +
  861. result.channal
  862. ).html(marked(term_std_str_to_tran(result.text, result.channal, result.editor, result.lang)));
  863. term_updata_translation();
  864. for (const iterator of _arrData) {
  865. if (
  866. iterator.book == result.book &&
  867. iterator.para == result.para &&
  868. iterator.begin == result.begin &&
  869. iterator.end == result.end
  870. ) {
  871. for (const tran of iterator.translation) {
  872. if (tran.channal == result.channal) {
  873. tran.text = result.text;
  874. break;
  875. }
  876. }
  877. }
  878. }
  879. }
  880. }
  881. }
  882. );
  883. }
  884. function copy_ref(book, para, begin, end) {
  885. let strRef = "{{" + book + "-" + para + "-" + begin + "-" + end + "}}";
  886. copy_to_clipboard(strRef);
  887. }
  888. function goto_nissaya(book, para, begin = 0, end = 0) {
  889. window.open("../nissaya/index.php?book=" + book + "&para=" + para + "&begin=" + begin + "&end=" + end, "nissaya");
  890. }
  891. function edit_in_studio(book, para, begin, end) {
  892. wbw_channal_list_open(book, [para]);
  893. }
  894. function tool_bar_show(element) {
  895. if ($(element).find(".tran_text_tool_bar").css("display") == "none") {
  896. $(element).find(".tran_text_tool_bar").css("display", "flex");
  897. $(element).find(".icon_expand").css("transform", "rotate(-180deg)");
  898. $(element).css("background-color", "var(--btn-bg-color)");
  899. $(element).css("visibility", "visible");
  900. $(document).one("click", function () {
  901. $(element).find(".tran_text_tool_bar").hide();
  902. $(element).css("background-color", "var(--nocolor)");
  903. $(element).find(".icon_expand").css("transform", "unset");
  904. $(element).css("visibility", "");
  905. });
  906. event.stopPropagation();
  907. } else {
  908. $(element).find(".tran_text_tool_bar").hide();
  909. $(element).css("background-color", "var(--nocolor)");
  910. $(element).find(".icon_expand").css("transform", "unset");
  911. $(element).css("visibility", "");
  912. }
  913. }
  914. function setVisibility(key, value) {
  915. switch (key) {
  916. case "palitext":
  917. if ($(value).is(":checked")) {
  918. $(".palitext").show();
  919. } else {
  920. $(".palitext").hide();
  921. }
  922. break;
  923. default:
  924. break;
  925. }
  926. }
  927. function note_show_pali_sim(SentId) {
  928. pali_sim_dlg_open(SentId, 0, 20);
  929. }
  930. function set_pali_script(pos, script) {
  931. if (script == "none") {
  932. $(".palitext" + pos).html("");
  933. } else {
  934. $(".palitext" + pos).each(function () {
  935. let html = $(this).siblings(".palitext_roma").first().html();
  936. $(this).html(html);
  937. });
  938. $(".palitext" + pos)
  939. .find("*")
  940. .contents()
  941. .filter(function () {
  942. return this.nodeType != 1;
  943. })
  944. .wrap("<pl" + pos + "></pl" + pos + ">");
  945. $(".palitext" + pos)
  946. .contents()
  947. .filter(function () {
  948. return this.nodeType != 1;
  949. })
  950. .wrap("<pl" + pos + "></pl" + pos + ">");
  951. $("pl" + pos).html(function (index, oldcontent) {
  952. return roman_to_my(oldcontent);
  953. });
  954. }
  955. }
  956. function splite_pali_word() {
  957. $("pali")
  958. .contents()
  959. .filter(function () {
  960. return this.nodeType != 1;
  961. })
  962. .wrap("<pl></pl>");
  963. $("pl").each(function () {
  964. let html = $(this).html();
  965. $(this).html("<w>" + html.replace(/\s/g, "</w> <w>") + "</w>");
  966. });
  967. $("w").click(function () {
  968. let word = com_getPaliReal($(this).text());
  969. if (gBuildinDictIsOpen) {
  970. window.open("../dict/index.php?builtin=true&key=" + word, "dict");
  971. }
  972. });
  973. }
  974. function refresh_pali_script() {
  975. if (_display && _display == "para") {
  976. //段落模式
  977. } else {
  978. //句子模式
  979. setting_get("lib.second_script", set_second_scrip);
  980. }
  981. }
  982. function set_second_scrip(value) {
  983. set_pali_script(2, value);
  984. }
  985. function slider_show(obj) {
  986. $(obj).parent().parent().parent().parent().parent().toggleClass("slider_show_shell");
  987. }