note.js 24 KB

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