note.js 26 KB

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