note.js 26 KB

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