note.js 27 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055
  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. //将新的数据添加到数据总表
  221. _arrData = _arrData.concat(sentData);
  222. note_ref_init();
  223. //获取术语字典
  224. term_get_dict();
  225. //刷新channel列表
  226. note_channal_list();
  227. //显示不同的巴利语脚本
  228. refresh_pali_script();
  229. //把巴利语单词用<w>分隔用于点词查询等
  230. splite_pali_word();
  231. } catch (e) {
  232. console.error(e);
  233. }
  234. }
  235. }
  236. );
  237. } else {
  238. //term_get_dict();
  239. }
  240. }
  241. //生成channel列表
  242. function note_channal_list() {
  243. console.log("note_channal_list start");
  244. let arrSentInfo = new Array();
  245. $("note").each(function () {
  246. let info = $(this).attr("info");
  247. if (info && info != "") {
  248. arrSentInfo.push({ id: "", data: info });
  249. }
  250. });
  251. if (arrSentInfo.length > 0) {
  252. $.post(
  253. "../term/channal_list.php",
  254. {
  255. setting: "",
  256. data: JSON.stringify(arrSentInfo),
  257. },
  258. function (data, status) {
  259. if (status == "success") {
  260. try {
  261. let active = JSON.parse(data);
  262. _channalData = active;
  263. for (const iterator of _my_channal) {
  264. let found = false;
  265. for (const one of active) {
  266. if (iterator.id == one.id) {
  267. found = true;
  268. break;
  269. }
  270. }
  271. if (found == false) {
  272. _channalData.push(iterator);
  273. }
  274. }
  275. let strHtml = "";
  276. for (const iterator of _channalData) {
  277. if (_channal.indexOf(iterator.id) >= 0) {
  278. strHtml += render_channal_list(iterator);
  279. }
  280. }
  281. for (const iterator of _channalData) {
  282. if (_channal.indexOf(iterator.id) == -1) {
  283. strHtml += render_channal_list(iterator);
  284. }
  285. }
  286. $("#channal_list").html(strHtml);
  287. set_more_button_display();
  288. } catch (e) {
  289. console.error(e);
  290. }
  291. }
  292. }
  293. );
  294. }
  295. }
  296. function find_channal(id) {
  297. for (const iterator of _channalData) {
  298. if (id == iterator.id) {
  299. return iterator;
  300. }
  301. }
  302. return false;
  303. }
  304. function render_channal_list(channalinfo) {
  305. let output = "";
  306. let checked = "";
  307. let selected = "noselect";
  308. if (_channal.indexOf(channalinfo.id) >= 0) {
  309. checked = "checked";
  310. selected = "selected";
  311. }
  312. output += "<div class='list_with_head " + selected + "'>";
  313. output +=
  314. '<div class="channel_select"><input type="checkbox" ' + checked + " channal_id='" + channalinfo.id + "'></div>";
  315. output += "<div class='head'>";
  316. output += "<span class='head_img'>";
  317. if (parseInt(channalinfo.power) == 30) {
  318. output += gLocal.gui.your.slice(0, 1);
  319. } else {
  320. output += channalinfo.nickname.slice(0, 1);
  321. }
  322. output += "</span>";
  323. output += "</div>";
  324. output += "<div style='width: 100%;overflow-x: hidden;'>";
  325. output += "<div class='channal_list' >";
  326. // output += "<a href='../wiki/wiki.php?word=" + _word;
  327. // output += "&channal=" + channalinfo.id + "' >";
  328. if (parseInt(channalinfo.power) >= 20) {
  329. if (parseInt(channalinfo.power) != 30) {
  330. output += "[写]";
  331. }
  332. } else {
  333. output += "[读]";
  334. }
  335. output += "<a onclick=\"set_channal('" + channalinfo.id + "')\">";
  336. output += channalinfo["name"];
  337. output += "</a>";
  338. if (parseInt(channalinfo.power) == 30) {
  339. output += "@" + gLocal.gui.your;
  340. } else {
  341. output += "@" + channalinfo["nickname"];
  342. }
  343. output += "</div>";
  344. output += "<div class='userinfo_channal'>";
  345. output += channalinfo["username"];
  346. output += "</div>";
  347. if (channalinfo["final"]) {
  348. //进度
  349. output += "<div>";
  350. let article_len = channalinfo["article_len"];
  351. let svg_width = article_len;
  352. let svg_height = parseInt(article_len / 10);
  353. output += '<svg viewBox="0 0 ' + svg_width + " " + svg_height + '" width="100%" >';
  354. let curr_x = 0;
  355. let allFinal = 0;
  356. for (const iterator of channalinfo["final"]) {
  357. let stroke_width = parseInt(iterator.len);
  358. output += "<rect ";
  359. output += ' x="' + curr_x + '"';
  360. output += ' y="0"';
  361. output += ' height="' + svg_height + '"';
  362. output += ' width="' + stroke_width + '"';
  363. if (iterator.final == true) {
  364. allFinal += stroke_width;
  365. output += ' class="progress_bar_done" ';
  366. } else {
  367. output += ' class="progress_bar_undone" ';
  368. }
  369. output += "/>";
  370. curr_x += stroke_width;
  371. }
  372. output +=
  373. "<rect x='0' y='0' width='" + svg_width + "' height='" + svg_height / 5 + "' class='progress_bar_bg' />";
  374. output +=
  375. "<rect x='0' y='0' width='" +
  376. allFinal +
  377. "' height='" +
  378. svg_height / 5 +
  379. "' class='progress_bar_percent' style='stroke-width: 0; fill: rgb(100, 228, 100);'/>";
  380. output += '<text x="0" y="' + svg_height + '" font-size="' + svg_height * 0.8 + '">';
  381. output += channalinfo["count"] + "/" + channalinfo["all"];
  382. output += "</text>";
  383. output += "<svg>";
  384. output += "</div>";
  385. //进度结束
  386. }
  387. output += "</div>";
  388. output += "</div>";
  389. return output;
  390. }
  391. function onChannelMultiSelectStart() {
  392. $(".channel_select").show();
  393. }
  394. function onChannelMultiSelectCancel() {
  395. $(".channel_select").hide();
  396. }
  397. function onChannelChange() {
  398. let channal_list = new Array();
  399. $("[channal_id]").each(function () {
  400. if (this.checked) {
  401. channal_list.push($(this).attr("channal_id"));
  402. }
  403. });
  404. set_channal(channal_list.join());
  405. }
  406. //点击引用 需要响应的事件
  407. function note_ref_init() {
  408. $("chapter").click(function () {
  409. let bookid = $(this).attr("book");
  410. let para = $(this).attr("para");
  411. window.open("../reader/?view=chapter&book=" + bookid + "&para=" + para, "_blank");
  412. });
  413. $("para").click(function () {
  414. let bookid = $(this).attr("book");
  415. let para = $(this).attr("para");
  416. window.open("../reader/?view=para&book=" + bookid + "&para=" + para, "_blank");
  417. });
  418. }
  419. /*
  420. id
  421. palitext
  422. tran
  423. ref
  424. */
  425. function note_json_html(in_json) {
  426. let output = "";
  427. output += '<div class="note_tool_bar" style=" position: relative;">';
  428. output += '<div class="case_dropdown note_tool_context" >';
  429. output += "<svg class='icon' >";
  430. output += "<use xlink:href='../studio/svg/icon.svg#ic_more'></use>";
  431. output += "</svg>";
  432. output += "<div class='case_dropdown-content sent_menu'>";
  433. if (typeof _reader_view != "undefined" && _reader_view != "sent") {
  434. output += "<a onclick='junp_to(this)'>" + gLocal.gui.jump_to_this_sent + "</a>";
  435. }
  436. output +=
  437. "<a onclick='related_para_dlg_open(" +
  438. in_json.book +
  439. "," +
  440. in_json.para +
  441. ")'>" +
  442. gLocal.gui.related_para +
  443. "</a>";
  444. output +=
  445. "<a onclick='goto_nissaya(" +
  446. in_json.book +
  447. "," +
  448. in_json.para +
  449. "," +
  450. in_json.begin +
  451. "," +
  452. in_json.end +
  453. ")'>" +
  454. gLocal.gui.show_nissaya +
  455. "</a>";
  456. output +=
  457. "<a onclick=\"copy_ref('" +
  458. in_json.book +
  459. "','" +
  460. in_json.para +
  461. "','" +
  462. in_json.begin +
  463. "','" +
  464. in_json.end +
  465. "')\">" +
  466. gLocal.gui.copy_link +
  467. "</a>";
  468. output += "<a onclick='copy_text(this)'>" + gLocal.gui.copy + "“" + gLocal.gui.pāli + "”</a>";
  469. output +=
  470. "<a onclick=\"edit_in_studio('" +
  471. in_json.book +
  472. "','" +
  473. in_json.para +
  474. "','" +
  475. in_json.begin +
  476. "','" +
  477. in_json.end +
  478. "')\">" +
  479. gLocal.gui.edit_now +
  480. "</a>";
  481. output += "<a onclick='add_to_list()'>" + gLocal.gui.add_to_edit_list + "</a>";
  482. output += "<a onclick='slider_show(this)'>Slider Show</a>";
  483. output += "</div>";
  484. output += "</div>";
  485. output += " </div>";
  486. output += "<div class='palitext palitext_roma'>" + in_json.palitext + "</div>";
  487. output += "<div class='palitext palitext1'></div>";
  488. output += "<div class='palitext palitext2'></div>";
  489. //output += "<div id='translation_div'>";
  490. for (const iterator of in_json.translation) {
  491. output += render_one_sent_tran(in_json.book, in_json.para, in_json.begin, in_json.end, iterator);
  492. }
  493. //所选全部译文结束
  494. //output += "</div>";
  495. //未选择的其他译文开始
  496. output += "<div class='other_tran_div' sent='";
  497. output += in_json.book + "-" + in_json.para + "-" + in_json.begin + "-" + in_json.end + "' >";
  498. output += "<div class='tool_bar' sent='";
  499. output += in_json.book + "-" + in_json.para + "-" + in_json.begin + "-" + in_json.end + "' >";
  500. output += "<span class='more_tran icon_expand'></span>";
  501. //其他译文工具条
  502. output += "<span class='other_bar' >";
  503. output += "<span class='other_tran_span' >" + gLocal.gui.other + gLocal.gui.translation + "</span>";
  504. output += "<span class='other_tran_num'></span>";
  505. output += "</span>";
  506. output += "<span class='separate_line'></span>";
  507. //相似句工具条
  508. output += "<span class='other_bar' >";
  509. output +=
  510. "<span class='similar_sent_span' onclick=\"note_show_pali_sim('" +
  511. in_json.pali_sent_id +
  512. "')\">" +
  513. gLocal.gui.similar_sentences +
  514. "</span>";
  515. output += "<span class='similar_sent_num'>" + in_json.sim + "</span>";
  516. output += "</span>";
  517. output += "</div>";
  518. output += "<div class='other_tran'>";
  519. output += "</div>";
  520. output += "</div>";
  521. //未选择的其他译文开始
  522. //新增译文按钮开始
  523. output += "<div class='add_new icon_add' ";
  524. output += "book='" + in_json.book + "' ";
  525. output += "para='" + in_json.para + "' ";
  526. output += "begin='" + in_json.begin + "' ";
  527. output += "end='" + in_json.end + "' ";
  528. output += " >";
  529. output += "<div class='icon_add' onclick='add_new_tran_button_click(this)'></div>";
  530. output += "<div class='tran_text_tool_bar'>";
  531. output += "</div>";
  532. output += "</div>";
  533. //新增译文按钮结束
  534. //出处路径开始
  535. output += "<div class='ref'>" + in_json.ref;
  536. output +=
  537. "<span class='sent_no'>" +
  538. in_json.book +
  539. "-" +
  540. in_json.para +
  541. "-" +
  542. in_json.begin +
  543. "-" +
  544. in_json.end +
  545. "<span>" +
  546. "</div>";
  547. //出处路径结束
  548. return output;
  549. }
  550. function render_one_sent_tran(book, para, begin, end, iterator) {
  551. let output = "";
  552. output += "<div class='tran' lang='" + iterator.lang + "' style='display:flex;'>";
  553. //译文工具按钮开始
  554. output += "<div class='tran_text_tool_botton' onclick='tool_bar_show(this)'>";
  555. output +=
  556. "<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>";
  557. //译文工具栏开始
  558. output += "<div class='tran_text_tool_bar'>";
  559. output += "<div style='border-right: solid 1px;margin: 0.3em 0;'><li class = 'tip_buttom' ";
  560. output +=
  561. " onclick=\"note_edit_sentence('" +
  562. book +
  563. "' ,'" +
  564. para +
  565. "' ,'" +
  566. begin +
  567. "' ,'" +
  568. end +
  569. "' ,'" +
  570. iterator.channal +
  571. "')\"";
  572. output +=
  573. ">" +
  574. '<svg class="icon" ><use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#ic_mode_edit"></use></svg>';
  575. output += gLocal.gui.edit + "</li>";
  576. output += "<li class = 'tip_buttom' ";
  577. output += " onclick=\"history_show('" + iterator.id + "')\"";
  578. output +=
  579. ">" +
  580. '<svg class="icon" ><use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#recent_scan"></use></svg>';
  581. output += gLocal.gui.timeline + "</li>";
  582. output +=
  583. "<li class = 'tip_buttom'>" +
  584. '<svg class="icon" ><use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#copy"></use></svg>';
  585. output += gLocal.gui.copy + "</li></div>";
  586. output +=
  587. "<div style='border-right: solid 1px;margin: 0.3em 0;'><li class = 'tip_buttom'>" +
  588. '<svg class="icon" ><use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#like"></use></svg>';
  589. output += gLocal.gui.like + "</li>";
  590. output +=
  591. "<li class = 'tip_buttom'>" +
  592. '<svg class="icon" ><use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#comment"></use></svg>';
  593. output += gLocal.gui.comment + "</li>";
  594. output +=
  595. "<li class = 'tip_buttom'>" +
  596. '<svg class="icon" ><use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#ic_shopping_cart"></use></svg>';
  597. output += gLocal.gui.digest + "</li></div>";
  598. output +=
  599. "<div style='margin: 0.3em 0;'><li class = 'tip_buttom'>" +
  600. '<svg class="icon" ><use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#share_to"></use></svg>';
  601. output += gLocal.gui.share_to + "</li>";
  602. output += "</div></div>";
  603. //译文工具栏结束
  604. output += "</div>";
  605. //译文工具按钮结束
  606. //译文正文开始
  607. output +=
  608. "<div class='text' id='tran_text_" +
  609. book +
  610. "_" +
  611. para +
  612. "_" +
  613. begin +
  614. "_" +
  615. end +
  616. "_" +
  617. iterator.channal +
  618. "'>";
  619. if (iterator.text == "") {
  620. output +=
  621. "<span style='color:var(--border-line-color);'>" +
  622. iterator.channalinfo.name +
  623. "-" +
  624. iterator.channalinfo.lang +
  625. "</span>";
  626. } else {
  627. //note_init处理句子链接
  628. output += note_init(term_std_str_to_tran(iterator.text, iterator.channal, iterator.editor, iterator.lang));
  629. }
  630. output += "</div>";
  631. //译文正文结束
  632. output += "</div>";
  633. //单个channal译文框结束
  634. return output;
  635. }
  636. function add_new_tran_button_click(obj) {
  637. let html = "<ul>";
  638. for (const iterator of _my_channal) {
  639. if (_channal.indexOf(iterator.id) < 0) {
  640. html += '<li onclick="';
  641. html +=
  642. "new_sentence('" +
  643. $(obj).parent().attr("book") +
  644. "' ,'" +
  645. $(obj).parent().attr("para") +
  646. "' ,'" +
  647. $(obj).parent().attr("begin") +
  648. "' ,'" +
  649. $(obj).parent().attr("end") +
  650. "' ,'" +
  651. iterator.id +
  652. "',this)";
  653. html += '">' + iterator.name;
  654. if (parseInt(iterator.power) < 20) {
  655. html += "(建议)";
  656. }
  657. html += "</li>";
  658. }
  659. }
  660. html += "</ul>";
  661. $(obj).parent().children(".tran_text_tool_bar").first().html(html);
  662. if ($(obj).parent().children(".tran_text_tool_bar").css("display") == "block") {
  663. $(obj).parent().children(".tran_text_tool_bar").first().hide();
  664. } else {
  665. $(obj).parent().children(".tran_text_tool_bar").first().show();
  666. $(obj).parent().show();
  667. }
  668. }
  669. function new_sentence(book, para, begin, end, channel, obj) {
  670. let newsent = { id: "", text: "", lang: "", channal: channel };
  671. for (let iterator of _arrData) {
  672. if (iterator.book == book && iterator.para == para && iterator.begin == begin && iterator.end == end) {
  673. let found = false;
  674. for (const tran of iterator.translation) {
  675. if (tran.channal == channel) {
  676. found = true;
  677. break;
  678. }
  679. }
  680. if (!found) {
  681. iterator.translation.push(newsent);
  682. }
  683. }
  684. }
  685. if ($(obj).parent().parent().css("display") == "block") {
  686. $(obj).parent().parent().hide();
  687. }
  688. note_edit_sentence(book, para, begin, end, channel);
  689. }
  690. //显示更多译文按钮动作
  691. function set_more_button_display() {
  692. $(".other_tran_div").each(function () {
  693. const sentid = $(this).attr("sent").split("-");
  694. const book = sentid[0];
  695. const para = sentid[1];
  696. const begin = sentid[2];
  697. const end = sentid[3];
  698. let count = 0;
  699. for (const iterator of _channalData) {
  700. if (iterator.final) {
  701. for (const onesent of iterator.final) {
  702. let id = onesent.id.split("-");
  703. if (book == id[0] && para == id[1] && begin == id[2] && end == id[3] && onesent.final) {
  704. if (_channal.indexOf(iterator.id) == -1) {
  705. count++;
  706. }
  707. }
  708. }
  709. }
  710. }
  711. if (count > 0) {
  712. $(this).find(".other_tran_num").html(count);
  713. $(this).find(".other_tran_num").attr("style", "display:inline-flex;");
  714. $(this)
  715. .find(".other_bar")
  716. .click(function () {
  717. const sentid = $(this).parent().attr("sent").split("-");
  718. const book = sentid[0];
  719. const para = sentid[1];
  720. const begin = sentid[2];
  721. const end = sentid[3];
  722. let sentId = book + "-" + para + "-" + begin + "-" + end;
  723. if ($(this).parent().siblings(".other_tran").first().css("display") == "none") {
  724. $(".other_tran_div[sent='" + sentId + "']")
  725. .children(".other_tran")
  726. .slideDown();
  727. $(this).siblings(".more_tran ").css("transform", "unset");
  728. $.get(
  729. "../usent/get.php",
  730. {
  731. book: book,
  732. para: para,
  733. begin: begin,
  734. end: end,
  735. },
  736. function (data, status) {
  737. let arrSent = JSON.parse(data);
  738. let html = "";
  739. for (const iterator of arrSent) {
  740. if (_channal.indexOf(iterator.channal) == -1) {
  741. html += "<div>" + marked(iterator.text) + "</div>";
  742. }
  743. }
  744. let sentId =
  745. arrSent[0].book +
  746. "-" +
  747. arrSent[0].paragraph +
  748. "-" +
  749. arrSent[0].begin +
  750. "-" +
  751. arrSent[0].end;
  752. $(".other_tran_div[sent='" + sentId + "']")
  753. .children(".other_tran")
  754. .html(html);
  755. }
  756. );
  757. } else {
  758. $(".other_tran_div[sent='" + sentId + "']")
  759. .children(".other_tran")
  760. .slideUp();
  761. $(this).siblings(".more_tran ").css("transform", "rotate(-90deg)");
  762. }
  763. });
  764. } else {
  765. //隐藏自己
  766. //$(this).hide();
  767. $(this)
  768. .find(".other_tran_span")
  769. .html(gLocal.gui.no + gLocal.gui.other + gLocal.gui.translation);
  770. //$(this).find(".more_tran").hide();
  771. }
  772. });
  773. }
  774. function note_edit_sentence(book, para, begin, end, channal) {
  775. let channalInfo;
  776. for (const iterator of _channalData) {
  777. if (iterator.id == channal) {
  778. channalInfo = iterator;
  779. break;
  780. }
  781. }
  782. for (const iterator of _arrData) {
  783. if (iterator.book == book && iterator.para == para && iterator.begin == begin && iterator.end == end) {
  784. for (const tran of iterator.translation) {
  785. if (tran.channal == channal) {
  786. let html = "";
  787. html += "<div style='color:blue;'>" + channalInfo.name + "@" + channalInfo.nickname + "</div>";
  788. html +=
  789. "<textarea id='edit_dialog_text' sent_id='" +
  790. tran.id +
  791. "' book='" +
  792. book +
  793. "' para='" +
  794. para +
  795. "' begin='" +
  796. begin +
  797. "' end='" +
  798. end +
  799. "' channal='" +
  800. channal +
  801. "' style='width:100%;min-height:260px;'>" +
  802. tran.text +
  803. "</textarea>";
  804. $("#edit_dialog_content").html(html);
  805. $("#note_sent_edit_dlg").dialog("open");
  806. return;
  807. }
  808. }
  809. }
  810. }
  811. alert("未找到句子");
  812. }
  813. function note_sent_save() {
  814. let id = $("#edit_dialog_text").attr("sent_id");
  815. let book = $("#edit_dialog_text").attr("book");
  816. let para = $("#edit_dialog_text").attr("para");
  817. let begin = $("#edit_dialog_text").attr("begin");
  818. let end = $("#edit_dialog_text").attr("end");
  819. let channal = $("#edit_dialog_text").attr("channal");
  820. let text = $("#edit_dialog_text").val();
  821. $.post(
  822. "../usent/sent_post.php",
  823. {
  824. id: id,
  825. book: book,
  826. para: para,
  827. begin: begin,
  828. end: end,
  829. channal: channal,
  830. text: text,
  831. lang: "zh",
  832. },
  833. function (data) {
  834. let result = JSON.parse(data);
  835. if (result.status > 0) {
  836. alert("error" + result.message);
  837. } else {
  838. ntf_show("success");
  839. if (result.text == "") {
  840. let channel_info = "Empty";
  841. let thisChannel = find_channal(result.channal);
  842. if (thisChannel) {
  843. channel_info = thisChannel.name + "-" + thisChannel.nickname;
  844. }
  845. $(
  846. "#tran_text_" +
  847. result.book +
  848. "_" +
  849. result.para +
  850. "_" +
  851. result.begin +
  852. "_" +
  853. result.end +
  854. "_" +
  855. result.channal
  856. ).html("<span style='color:var(--border-line-color);'>" + channel_info + "</span>");
  857. } else {
  858. $(
  859. "#tran_text_" +
  860. result.book +
  861. "_" +
  862. result.para +
  863. "_" +
  864. result.begin +
  865. "_" +
  866. result.end +
  867. "_" +
  868. result.channal
  869. ).html(marked(term_std_str_to_tran(result.text, result.channal, result.editor, result.lang)));
  870. term_updata_translation();
  871. for (const iterator of _arrData) {
  872. if (
  873. iterator.book == result.book &&
  874. iterator.para == result.para &&
  875. iterator.begin == result.begin &&
  876. iterator.end == result.end
  877. ) {
  878. for (const tran of iterator.translation) {
  879. if (tran.channal == result.channal) {
  880. tran.text = result.text;
  881. break;
  882. }
  883. }
  884. }
  885. }
  886. }
  887. }
  888. }
  889. );
  890. }
  891. function copy_ref(book, para, begin, end) {
  892. let strRef = "{{" + book + "-" + para + "-" + begin + "-" + end + "}}";
  893. copy_to_clipboard(strRef);
  894. }
  895. function goto_nissaya(book, para, begin = 0, end = 0) {
  896. window.open("../nissaya/index.php?book=" + book + "&para=" + para + "&begin=" + begin + "&end=" + end, "nissaya");
  897. }
  898. function edit_in_studio(book, para, begin, end) {
  899. wbw_channal_list_open(book, [para]);
  900. }
  901. function tool_bar_show(element) {
  902. if ($(element).find(".tran_text_tool_bar").css("display") == "none") {
  903. $(element).find(".tran_text_tool_bar").css("display", "flex");
  904. $(element).find(".icon_expand").css("transform", "rotate(-180deg)");
  905. $(element).css("background-color", "var(--btn-bg-color)");
  906. $(element).css("visibility", "visible");
  907. $(document).one("click", function () {
  908. $(element).find(".tran_text_tool_bar").hide();
  909. $(element).css("background-color", "var(--nocolor)");
  910. $(element).find(".icon_expand").css("transform", "unset");
  911. $(element).css("visibility", "");
  912. });
  913. event.stopPropagation();
  914. } else {
  915. $(element).find(".tran_text_tool_bar").hide();
  916. $(element).css("background-color", "var(--nocolor)");
  917. $(element).find(".icon_expand").css("transform", "unset");
  918. $(element).css("visibility", "");
  919. }
  920. }
  921. function setVisibility(key, value) {
  922. switch (key) {
  923. case "palitext":
  924. if ($(value).is(":checked")) {
  925. $(".palitext").show();
  926. } else {
  927. $(".palitext").hide();
  928. }
  929. break;
  930. default:
  931. break;
  932. }
  933. }
  934. function note_show_pali_sim(SentId) {
  935. pali_sim_dlg_open(SentId, 0, 20);
  936. }
  937. function set_pali_script(pos, script) {
  938. if (script == "none") {
  939. $(".palitext" + pos).html("");
  940. } else {
  941. $(".palitext" + pos).each(function () {
  942. let html = $(this).siblings(".palitext_roma").first().html();
  943. $(this).html(html);
  944. });
  945. $(".palitext" + pos)
  946. .find("*")
  947. .contents()
  948. .filter(function () {
  949. return this.nodeType != 1;
  950. })
  951. .wrap("<pl" + pos + "></pl" + pos + ">");
  952. $(".palitext" + pos)
  953. .contents()
  954. .filter(function () {
  955. return this.nodeType != 1;
  956. })
  957. .wrap("<pl" + pos + "></pl" + pos + ">");
  958. $("pl" + pos).html(function (index, oldcontent) {
  959. return roman_to_my(oldcontent);
  960. });
  961. }
  962. }
  963. function splite_pali_word() {
  964. $("pali")
  965. .contents()
  966. .filter(function () {
  967. return this.nodeType != 1;
  968. })
  969. .wrap("<pl></pl>");
  970. $("pl").each(function () {
  971. let html = $(this).html();
  972. $(this).html("<w>" + html.replace(/\s/g, "</w> <w>") + "</w>");
  973. });
  974. $("w").click(function () {
  975. let word = com_getPaliReal($(this).text());
  976. if (gBuildinDictIsOpen) {
  977. window.open("../dict/index.php?builtin=true&key=" + word, "dict");
  978. }
  979. });
  980. }
  981. function refresh_pali_script() {
  982. if (_display && _display == "para") {
  983. //段落模式
  984. } else {
  985. //句子模式
  986. setting_get("lib.second_script", set_second_scrip);
  987. }
  988. }
  989. function set_second_scrip(value) {
  990. set_pali_script(2, value);
  991. }
  992. function slider_show(obj) {
  993. $(obj).parent().parent().parent().parent().parent().toggleClass("slider_show_shell");
  994. }