note.js 25 KB

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