note.js 27 KB

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