note.js 26 KB

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