note.js 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843
  1. var _display = "";
  2. var _mode = "read";
  3. var _word = "";
  4. var _channal = "";
  5. var _lang = "";
  6. var _author = "";
  7. var _arrData = new Array();
  8. var _channalData;
  9. var MAX_NOTE_NEST = 2;
  10. var gBuildinDictIsOpen = false;
  11. /*
  12. {{203-1654-23-45@11@en@*}}
  13. <note>203-1654-23-45@11@en@*</note>
  14. <note id=guid book=203 para=1654 begin=23 end=45 author=11 lang=en tag=*></note>
  15. <note id=guid book=203 para=1654 begin=23 end=45 author=11 lang=en tag=*>
  16. <div class=text>
  17. pali text
  18. </div>
  19. <tran>
  20. </tran>
  21. <ref>
  22. </ref>
  23. </note>
  24. */
  25. /*
  26. 解析百科字符串
  27. {{203-1654-23-45@11@en@*}}
  28. <note id=12345 info="203-1654-23-45@11@en@*"><note>
  29. <note id="guid" book=203 para=1654 begin=23 end=45 author=11 lang=en tag=*></note>
  30. */
  31. function note_create() {
  32. wbw_channal_list_init();
  33. note_sent_edit_dlg_init();
  34. term_edit_dlg_init();
  35. pali_sim_dlg_init();
  36. related_para_dlg_init();
  37. }
  38. function note_sent_edit_dlg_init() {
  39. $("body").append(
  40. '<div id="note_sent_edit_dlg" title="' +
  41. gLocal.gui.edit +
  42. '"><guide gid="markdown_guide"></guide><div id="edit_dialog_content"></div></div>'
  43. );
  44. guide_init();
  45. $("#note_sent_edit_dlg").dialog({
  46. autoOpen: false,
  47. width: 550,
  48. buttons: [
  49. {
  50. text: gLocal.gui.save,
  51. click: function () {
  52. note_sent_save();
  53. $(this).dialog("close");
  54. },
  55. },
  56. {
  57. text: gLocal.gui.cancel,
  58. click: function () {
  59. $(this).dialog("close");
  60. },
  61. },
  62. ],
  63. });
  64. }
  65. function note_init(input) {
  66. if (input) {
  67. let output = "<div>";
  68. output += marked(input);
  69. output += "</div>";
  70. let newString = output.replace(/\{\{/g, '<span class="note_shell"><note info="');
  71. newString = newString.replace(/\}\}/g, '" ></note></span>');
  72. return newString;
  73. } else {
  74. return "";
  75. }
  76. }
  77. function note_update_background_style() {
  78. var mSentsBook = new Array();
  79. var mBgIndex = 1;
  80. $("note[info]").each(function () {
  81. let info = $(this).attr("info").split("-");
  82. if (info.length >= 2) {
  83. let book = info[0];
  84. $(this).attr("book", book);
  85. if (!mSentsBook[book]) {
  86. mSentsBook[book] = mBgIndex;
  87. mBgIndex++;
  88. }
  89. $(this).addClass("bg_color_" + mSentsBook[book]);
  90. }
  91. });
  92. }
  93. //
  94. function note_refresh_new() {
  95. note_update_background_style();
  96. let objNotes = document.querySelectorAll("note");
  97. let arrSentInfo = new Array();
  98. for (const iterator of objNotes) {
  99. let id = iterator.id;
  100. if (id == null || id == "") {
  101. //查看这个节点是第几层note嵌套。大于预定层数退出。
  102. let layout = 1;
  103. let parent = iterator.parentNode;
  104. while (parent.nodeType == 1) {
  105. if (parent.nodeName == "NOTE") {
  106. layout++;
  107. if (layout > MAX_NOTE_NEST) {
  108. return false;
  109. }
  110. } else if (parent.nodeName == "BODY") {
  111. break;
  112. }
  113. parent = parent.parentNode;
  114. }
  115. id = com_guid();
  116. iterator.id = id;
  117. if (iterator.hasAttribute("info")) {
  118. let info = iterator.getAttribute("info");
  119. if (info != null || info != "") {
  120. /*
  121. let arrInfo = info.split("-");
  122. if (arrInfo.length >= 2) {
  123. let book = arrInfo[0];
  124. let para = arrInfo[1];
  125. }
  126. */
  127. arrSentInfo.push({ id: id, data: info });
  128. }
  129. }
  130. }
  131. }
  132. if (arrSentInfo.length > 0) {
  133. let setting = new Object();
  134. setting.lang = "";
  135. setting.channal = _channal;
  136. $.post(
  137. "../term/note.php",
  138. {
  139. setting: JSON.stringify(setting),
  140. data: JSON.stringify(arrSentInfo),
  141. },
  142. function (data, status) {
  143. if (status == "success") {
  144. try {
  145. let sentData = JSON.parse(data);
  146. for (const iterator of sentData) {
  147. let id = iterator.id;
  148. let strHtml = "<a name='" + id + "'></a>";
  149. if (_mode && _mode == "read") {
  150. //阅读模式
  151. strHtml += render_read_mode_sent(iterator);
  152. $("#" + id).html(strHtml);
  153. } else {
  154. //编辑模式
  155. strHtml += note_json_html(iterator);
  156. $("#" + id).html(strHtml);
  157. }
  158. }
  159. //处理<code>标签作为气泡注释
  160. popup_init();
  161. //刷新句子链接递归,有加层数限制。
  162. //note_refresh_new();
  163. //将新的数据添加到数据总表
  164. _arrData = _arrData.concat(sentData);
  165. note_ref_init();
  166. //获取术语字典
  167. term_get_dict();
  168. //刷新channel列表
  169. note_channal_list();
  170. //显示不同的巴利语脚本
  171. refresh_pali_script();
  172. //把巴利语单词用<w>分隔用于点词查询等
  173. splite_pali_word();
  174. //处理编辑框消息
  175. tran_sent_textarea_event_init();
  176. } catch (e) {
  177. console.error(e);
  178. }
  179. }
  180. }
  181. );
  182. } else {
  183. //term_get_dict();
  184. }
  185. }
  186. //渲染阅读模式句子
  187. function render_read_mode_sent(iterator) {
  188. let id = iterator.id;
  189. let strPalitext =
  190. "<pali book='" +
  191. iterator.book +
  192. "' para='" +
  193. iterator.para +
  194. "' begin='" +
  195. iterator.begin +
  196. "' end='" +
  197. iterator.end +
  198. "' >" +
  199. iterator.palitext +
  200. "</pali>";
  201. if (
  202. $("#" + id)
  203. .parent()
  204. .parent()
  205. .children(".para_div").length == 0
  206. ) {
  207. let tranDivHtml = "";
  208. if (_channal != "") {
  209. let arrChannal = _channal.split(",");
  210. for (let index = arrChannal.length - 1; index >= 0; index--) {
  211. const iChannal = arrChannal[index];
  212. tranDivHtml += "<div class='tran_div_channel' channal='" + iChannal + "'></div>";
  213. }
  214. } else {
  215. tranDivHtml = "<div class='tran_div_channel' channal='0'></div>";
  216. }
  217. $("#" + id)
  218. .parent()
  219. .parent()
  220. .prepend(
  221. "<div class='para_div'><div class='palitext_div'><div class='palitext palitext1'></div><div class='palitext palitext2'></div></div><div class='para_tran_div'>" +
  222. tranDivHtml +
  223. "</div></div>"
  224. );
  225. }
  226. $("#" + id)
  227. .parent()
  228. .parent()
  229. .children(".para_div")
  230. .find(".palitext")
  231. .first()
  232. .append(strPalitext);
  233. let htmlSent = "";
  234. htmlSent += "<div class='note_body'>";
  235. htmlSent += "<div class='palitext_div'>";
  236. htmlSent += "<div class='palitext palitext1'>" + strPalitext + "</div>";
  237. htmlSent += "<div class='palitext palitext2'></div>";
  238. htmlSent += "</div>";
  239. htmlSent += "<div class='sent_tran_div'>";
  240. for (const oneTran of iterator.translation) {
  241. let html = "<span class='tran_sent' lang='" + oneTran.lang + "' channal='" + oneTran.channal + "'>";
  242. html += marked(term_std_str_to_tran(oneTran.text, oneTran.channal, oneTran.editor, oneTran.lang));
  243. html += "</span>";
  244. htmlSent += html;
  245. let channelId = "0";
  246. if (_channal != "") {
  247. channelId = oneTran.channal;
  248. }
  249. $("#" + id)
  250. .parent()
  251. .parent()
  252. .find(".tran_div_channel[channal='" + channelId + "']")
  253. .append(html);
  254. }
  255. htmlSent += "</div>";
  256. htmlSent += "</div>";
  257. return htmlSent;
  258. }
  259. //生成channel列表
  260. function note_channal_list() {
  261. console.log("note_channal_list start");
  262. let arrSentInfo = new Array();
  263. $("note").each(function () {
  264. let info = $(this).attr("info");
  265. if (info && info != "") {
  266. arrSentInfo.push({ id: "", data: info });
  267. }
  268. });
  269. if (arrSentInfo.length > 0) {
  270. $.post(
  271. "../term/channal_list.php",
  272. {
  273. setting: "",
  274. data: JSON.stringify(arrSentInfo),
  275. },
  276. function (data, status) {
  277. if (status == "success") {
  278. try {
  279. let active = JSON.parse(data);
  280. _channalData = active;
  281. for (const iterator of _my_channal) {
  282. let found = false;
  283. for (const one of active) {
  284. if (iterator.id == one.id) {
  285. found = true;
  286. break;
  287. }
  288. }
  289. if (found == false) {
  290. _channalData.push(iterator);
  291. }
  292. }
  293. let strHtml = "";
  294. for (const iterator of _channalData) {
  295. if (_channal.indexOf(iterator.id) >= 0) {
  296. strHtml += render_channal_list(iterator);
  297. }
  298. }
  299. for (const iterator of _channalData) {
  300. if (_channal.indexOf(iterator.id) == -1) {
  301. strHtml += render_channal_list(iterator);
  302. }
  303. }
  304. $("#channal_list").html(strHtml);
  305. set_more_button_display();
  306. } catch (e) {
  307. console.error(e);
  308. }
  309. }
  310. }
  311. );
  312. }
  313. }
  314. function find_channal(id) {
  315. for (const iterator of _channalData) {
  316. if (id == iterator.id) {
  317. return iterator;
  318. }
  319. }
  320. return false;
  321. }
  322. function render_channal_list(channalinfo) {
  323. let output = "";
  324. let checked = "";
  325. let selected = "noselect";
  326. if (_channal.indexOf(channalinfo.id) >= 0) {
  327. checked = "checked";
  328. selected = "selected";
  329. }
  330. output += "<div class='list_with_head " + selected + "'>";
  331. output +=
  332. '<div class="channel_select"><input type="checkbox" ' + checked + " channal_id='" + channalinfo.id + "'></div>";
  333. output += "<div class='head'>";
  334. output += "<span class='head_img'>";
  335. if (parseInt(channalinfo.power) == 30) {
  336. output += gLocal.gui.your.slice(0, 1);
  337. } else {
  338. output += channalinfo.nickname.slice(0, 1);
  339. }
  340. output += "</span>";
  341. output += "</div>";
  342. output += "<div style='width: 100%;overflow-x: hidden;'>";
  343. output += "<div class='channal_list' >";
  344. // output += "<a href='../wiki/wiki.php?word=" + _word;
  345. // output += "&channal=" + channalinfo.id + "' >";
  346. switch (parseInt(channalinfo.status)) {
  347. case 10:
  348. output += "🔐";
  349. break;
  350. case 20:
  351. output += "🌐";
  352. break;
  353. case 30:
  354. output += "🌐";
  355. break;
  356. default:
  357. break;
  358. }
  359. if (parseInt(channalinfo.power) >= 20) {
  360. //if (parseInt(channalinfo.power) != 30)
  361. {
  362. output += "✏️";
  363. }
  364. }
  365. //✋
  366. output += "<a onclick=\"set_channal('" + channalinfo.id + "')\">";
  367. output += channalinfo["name"];
  368. output += "</a>";
  369. if (parseInt(channalinfo.power) == 30) {
  370. output += "@" + gLocal.gui.your;
  371. } else {
  372. output += "@" + channalinfo["nickname"];
  373. }
  374. output += "</div>";
  375. output += "<div class='userinfo_channal'>";
  376. output += channalinfo["username"];
  377. output += "</div>";
  378. //绘制句子进度
  379. if (channalinfo["final"]) {
  380. //进度
  381. output += "<div>";
  382. let article_len = channalinfo["article_len"];
  383. let svg_width = article_len;
  384. let svg_height = parseInt(article_len / 15);
  385. output += '<svg viewBox="0 0 ' + svg_width + " " + svg_height + '" width="100%" >';
  386. let curr_x = 0;
  387. let allFinal = 0;
  388. for (const iterator of channalinfo["final"]) {
  389. let stroke_width = parseInt(iterator.len);
  390. output += "<rect ";
  391. output += ' x="' + curr_x + '"';
  392. output += ' y="0"';
  393. output += ' height="' + svg_height + '"';
  394. output += ' width="' + stroke_width + '"';
  395. if (iterator.final == true) {
  396. allFinal += stroke_width;
  397. output += ' class="progress_bar_done" ';
  398. } else {
  399. output += ' class="progress_bar_undone" ';
  400. }
  401. output += "/>";
  402. curr_x += stroke_width;
  403. }
  404. output +=
  405. "<rect x='0' y='0' width='" + svg_width + "' height='" + svg_height / 5 + "' class='progress_bar_bg' />";
  406. output +=
  407. "<rect x='0' y='0' width='" +
  408. allFinal +
  409. "' height='" +
  410. svg_height / 5 +
  411. "' class='progress_bar_percent' style='stroke-width: 0; fill: rgb(100, 228, 100);'/>";
  412. output += '<text x="0" y="' + svg_height + '" font-size="' + svg_height * 0.8 + '">';
  413. output += channalinfo["count"] + "/" + channalinfo["all"] + "@" + curr_x;
  414. output += "</text>";
  415. output += "<svg>";
  416. output += "</div>";
  417. //进度结束
  418. }
  419. output += "</div>";
  420. output += "</div>";
  421. return output;
  422. }
  423. function onChannelMultiSelectStart() {
  424. $(".channel_select").show();
  425. }
  426. function onChannelMultiSelectCancel() {
  427. $(".channel_select").hide();
  428. }
  429. function onChannelChange() {
  430. let channal_list = new Array();
  431. $("[channal_id]").each(function () {
  432. if (this.checked) {
  433. channal_list.push($(this).attr("channal_id"));
  434. }
  435. });
  436. set_channal(channal_list.join());
  437. }
  438. //点击引用 需要响应的事件
  439. function note_ref_init() {
  440. $("chapter").click(function () {
  441. let bookid = $(this).attr("book");
  442. let para = $(this).attr("para");
  443. window.open("../reader/?view=chapter&book=" + bookid + "&para=" + para, "_blank");
  444. });
  445. $("para").click(function () {
  446. let bookid = $(this).attr("book");
  447. let para = $(this).attr("para");
  448. window.open("../reader/?view=para&book=" + bookid + "&para=" + para, "_blank");
  449. });
  450. }
  451. /*
  452. 生成编辑模式句子块
  453. id
  454. palitext
  455. tran
  456. ref
  457. */
  458. function note_json_html(in_json) {
  459. let output = "";
  460. output += '<div class="note_tool_bar" style=" position: relative;">';
  461. output += '<div class="case_dropdown note_tool_context" >';
  462. output += "<svg class='icon' >";
  463. output += "<use xlink:href='../studio/svg/icon.svg#ic_more'></use>";
  464. output += "</svg>";
  465. output += "<div class='case_dropdown-content sent_menu'>";
  466. if (typeof _reader_view != "undefined" && _reader_view != "sent") {
  467. output += "<a onclick='junp_to(this)'>" + gLocal.gui.jump_to_this_sent + "</a>";
  468. }
  469. output +=
  470. "<a onclick='related_para_dlg_open(" +
  471. in_json.book +
  472. "," +
  473. in_json.para +
  474. ")'>" +
  475. gLocal.gui.related_para +
  476. "</a>";
  477. output +=
  478. "<a onclick='goto_nissaya(" +
  479. in_json.book +
  480. "," +
  481. in_json.para +
  482. "," +
  483. in_json.begin +
  484. "," +
  485. in_json.end +
  486. ")'>" +
  487. gLocal.gui.show_nissaya +
  488. "</a>";
  489. output +=
  490. "<a onclick=\"copy_ref('" +
  491. in_json.book +
  492. "','" +
  493. in_json.para +
  494. "','" +
  495. in_json.begin +
  496. "','" +
  497. in_json.end +
  498. "')\">" +
  499. gLocal.gui.copy_link +
  500. "</a>";
  501. output += "<a onclick='copy_text(this)'>" + gLocal.gui.copy + "“" + gLocal.gui.pāli + "”</a>";
  502. output +=
  503. "<a onclick=\"edit_in_studio('" +
  504. in_json.book +
  505. "','" +
  506. in_json.para +
  507. "','" +
  508. in_json.begin +
  509. "','" +
  510. in_json.end +
  511. "')\">" +
  512. gLocal.gui.edit_now +
  513. "</a>";
  514. output += "<a onclick='add_to_list()'>" + gLocal.gui.add_to_edit_list + "</a>";
  515. output += "<a onclick='slider_show(this)'>Slider Show</a>";
  516. output += "</div>";
  517. output += "</div>";
  518. output += " </div>";
  519. let strPalitext =
  520. "<pali book='" +
  521. in_json.book +
  522. "' para='" +
  523. in_json.para +
  524. "' begin='" +
  525. in_json.begin +
  526. "' end='" +
  527. in_json.end +
  528. "' >" +
  529. in_json.palitext +
  530. "</pali>";
  531. output += "<div class='note_body'>";
  532. output += "<div class='palitext_div'>";
  533. output += "<div class='palitext palitext_roma'>" + strPalitext + "</div>";
  534. output += "<div class='palitext palitext1'></div>";
  535. output += "<div class='palitext palitext2'></div>";
  536. output += "</div>";
  537. //译文开始
  538. output += "<div class='sent_tran_div'>";
  539. for (const iterator of in_json.translation) {
  540. output += render_one_sent_tran_a(iterator);
  541. }
  542. output += "</div>";
  543. //译文结束
  544. output += "</div>"; /**note_body end */
  545. //工具栏开始
  546. output += "<div class='other_tran_div' sent='";
  547. output += in_json.book + "-" + in_json.para + "-" + in_json.begin + "-" + in_json.end + "' >";
  548. output += "<div class='tool_bar' sent='";
  549. output += in_json.book + "-" + in_json.para + "-" + in_json.begin + "-" + in_json.end + "' >";
  550. output += "<span class='tool_left'>";
  551. //第一个按钮
  552. //新增译文按钮开始
  553. output += "<span class='' ";
  554. output += "book='" + in_json.book + "' ";
  555. output += "para='" + in_json.para + "' ";
  556. output += "begin='" + in_json.begin + "' ";
  557. output += "end='" + in_json.end + "' ";
  558. output += " >";
  559. output += "<span class='' onclick='add_new_tran_button_click(this)' title='" + gLocal.gui.add_tran + "'>➕</span>";
  560. output += "<div class='tran_text_tool_bar'>";
  561. output += "</div>";
  562. output += "</span>";
  563. //新增译文按钮结束
  564. output += "<span class='separate_line'></span>";
  565. //第二个按钮
  566. output += "<span class='more_tran icon_expand'></span>";
  567. //其他译文工具条
  568. output += "<span class='other_bar' >";
  569. output +=
  570. "<span class='other_tran_span' title='🧲" +
  571. gLocal.gui.other +
  572. gLocal.gui.translation +
  573. "'><svg class='icon' style='fill: var(--box-bg-color1)'><use xlink:href=\"../studio/svg/icon.svg#more_tran\"></svg>" +gLocal.gui.translation +
  574. "</span>";
  575. output += "<span class='other_tran_num'></span>";
  576. output += "</span>";
  577. output += "<span class='separate_line'></span>";
  578. //手工义注
  579. output += "<span class='other_bar'>";
  580. output +=
  581. "<span class='other_tran_span commentray' title='📔" +
  582. gLocal.gui.vannana +
  583. "'>🪔" +
  584. gLocal.gui.commentary +
  585. "</span>";
  586. output += "<span class='other_tran_num'></span>";
  587. output += "</span>";
  588. output += "<span class='separate_line'></span>";
  589. //第三个按钮 相似句
  590. if (parseInt(in_json.sim) > 0) {
  591. output += "<span class='other_bar' >";
  592. output +=
  593. "<span class='similar_sent_span' onclick=\"note_show_pali_sim('" +
  594. in_json.pali_sent_id +
  595. "')\" title='" +
  596. gLocal.gui.similar_sentences +
  597. "'>🧬" +
  598. gLocal.gui.similar +
  599. "</span>";
  600. output += "<span class='similar_sent_num'>" + in_json.sim + "</span>";
  601. output += "</span>";
  602. output += "<span class='separate_line'></span>";
  603. }
  604. //第三个按钮 相似句结束
  605. output += "</span>";
  606. output += "<span class='tool_right'>";
  607. //出处路径开始
  608. output += "<span class='ref'>";
  609. output += "<span class='book_name tooltip'>" + in_json.booktitle;
  610. output += "<span class='tooltiptext tooltip-bottom'>";
  611. output += in_json.ref;
  612. output += "</span>";
  613. output += "<span class='sent_no'>";
  614. output += in_json.book + "-" + in_json.para + "-" + in_json.begin + "-" + in_json.end;
  615. output += "<span>";
  616. output += "</span>";
  617. output += "</span>";
  618. //出处路径结束
  619. output += "</span>";
  620. output += "</div>";
  621. //工具栏结束
  622. //未选择的其他译文开始
  623. output += "<div class='other_tran'>";
  624. output += "</div>";
  625. output += "</div>";
  626. return output;
  627. }
  628. //设置取消输入框的编辑模式
  629. function sent_tran_set_edit_mode(obj, isEditMode) {
  630. $(".sent_tran").removeClass("edit_mode");
  631. if (isEditMode) {
  632. let jqObj = $(obj);
  633. while (!jqObj.hasClass("sent_tran")) {
  634. jqObj = jqObj.parent();
  635. if (!jqObj) {
  636. return;
  637. }
  638. }
  639. jqObj.addClass("edit_mode");
  640. }
  641. }
  642. function sent_tran_edit(obj) {
  643. let jqObj = $(obj);
  644. while (!jqObj.hasClass("sent_tran")) {
  645. jqObj = jqObj.parent();
  646. if (!jqObj) {
  647. return;
  648. }
  649. }
  650. if (jqObj.hasClass("edit_mode")) {
  651. jqObj.removeClass("edit_mode");
  652. } else {
  653. $(".sent_tran").removeClass("edit_mode");
  654. jqObj.addClass("edit_mode");
  655. }
  656. }
  657. function sent_pr_merge(id) {
  658. $.post(
  659. "../usent/sent_pr_merge.php",
  660. {
  661. id: id,
  662. },
  663. function (data) {
  664. let result = JSON.parse(data);
  665. if (result.status > 0) {
  666. alert("error" + result.message);
  667. } else {
  668. ntf_show("成功采纳");
  669. }
  670. }
  671. );
  672. }
  673. function sent_commit(src, id) {
  674. commit_init({
  675. src: src,
  676. sent: [id],
  677. express: true,
  678. });
  679. }
  680. function render_one_sent_tran_a(iterator) {
  681. let mChannel = get_channel_by_id(iterator.channal);
  682. let tranText;
  683. let sid = iterator.book + "-" + iterator.para + "-" + iterator.begin + "-" + iterator.end;
  684. if (iterator.text == "") {
  685. if (typeof iterator.channalinfo == "undefined") {
  686. tranText =
  687. "<span style='color:var(--border-line-color);'>" +
  688. "空" +
  689. "@" +
  690. iterator.editor_name.nickname +
  691. "</span>";
  692. } else {
  693. tranText =
  694. "<span style='color:var(--border-line-color);'>" +
  695. iterator.channalinfo.name +
  696. "-" +
  697. iterator.channalinfo.lang +
  698. "</span>";
  699. }
  700. } else {
  701. //note_init处理句子链接
  702. tranText = note_init(term_std_str_to_tran(iterator.text, iterator.channal, iterator.editor, iterator.lang));
  703. }
  704. let html = "";
  705. html += "<div class='sent_tran ";
  706. if (typeof iterator.is_pr != "undefined" && iterator.is_pr == true) {
  707. html += " pr ";
  708. }
  709. html += "' dbid='" + iterator.id + "' channel='" + iterator.channal + "' sid='" + sid + "'>";
  710. html += "<div class='sent_tran_inner'>";
  711. html += '<div class="tool_bar">';
  712. html += ' <div class="right">';
  713. //句子菜单
  714. html += '<div class="pop_menu">';
  715. if (typeof iterator.is_pr != "undefined" && iterator.is_pr == true) {
  716. //在pr 列表中的译文
  717. if (typeof iterator.is_pr_editor != "undefined" && iterator.is_pr_editor == true) {
  718. //提交人
  719. //修改按钮
  720. html += "<button class='icon_btn tooltip' onclick='sent_tran_edit(this)'>";
  721. html += '<svg class="icon" >';
  722. html += '<use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#ic_mode_edit"></use>';
  723. html += "</svg>";
  724. html += "<span class='tooltiptext tooltip-top'>";
  725. html += gLocal.gui.modify;
  726. html += "</span>";
  727. html += "</button>";
  728. //删除按钮
  729. html += "<button class='icon_btn tooltip' onclick='sent_pr_del(this)'>";
  730. html += '<svg class="icon" >';
  731. html += '<use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#ic_delete"></use>';
  732. html += "</svg>";
  733. html += "<span class='tooltiptext tooltip-top'>";
  734. html += gLocal.gui.delete;
  735. html += "</span>";
  736. html += "</button>";
  737. } else {
  738. //非提交人
  739. if (parseInt(iterator.mypower) >= 20) {
  740. //有权限 采纳按钮
  741. html += "<button class='icon_btn tooltip' onclick=\"sent_pr_merge('" + iterator.id + "')\">";
  742. html += '<svg class="icon" >';
  743. html += '<use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#accept_copy"></use>';
  744. html += "</svg>";
  745. html += "<span class='tooltiptext tooltip-top'>";
  746. html += gLocal.gui.accept_copy;
  747. html += "</span>";
  748. html += "</button>";
  749. }
  750. //点赞按钮
  751. html += "<button class='icon_btn tooltip' onclick='sent_pr_like(this)'>";
  752. html += '<svg class="icon" >';
  753. html += '<use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#like"></use>';
  754. html += "</svg>";
  755. html += "<span class='tooltiptext tooltip-top'>";
  756. html += gLocal.gui.like;
  757. html += "</span>";
  758. html += "</button>";
  759. }
  760. } else {
  761. //非pr列表里的句子
  762. //编辑按钮
  763. html += "<button class='icon_btn tooltip' onclick='sent_tran_edit(this)'>";
  764. html += '<svg class="icon" >';
  765. if (parseInt(iterator.mypower) < 20) {
  766. html += '<use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#my_idea"></use>';
  767. } else {
  768. html += '<use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#ic_mode_edit"></use>';
  769. }
  770. html += "</svg>";
  771. html += "<span class='tooltiptext tooltip-top'>";
  772. if (parseInt(iterator.mypower) < 20) {
  773. html += gLocal.gui.suggest;
  774. } else {
  775. html += gLocal.gui.edit;
  776. }
  777. html += "</span>";
  778. html += "</button>";
  779. //推送按钮
  780. let commitIcon = "";
  781. let commitTipText = "";
  782. if (parseInt(iterator.mypower) >= 30 && parseInt(iterator.status) < 30) {
  783. //我的私有资源 公开发布
  784. commitIcon = "publish";
  785. commitTipText = gLocal.gui.publish;
  786. } else {
  787. if (parseInt(iterator.mypower) < 20) {
  788. //只读资源 采纳
  789. commitIcon = "accept_copy";
  790. commitTipText = gLocal.gui.accept_copy;
  791. } else {
  792. //其他资源 复制到
  793. commitIcon = "copy";
  794. commitTipText = gLocal.gui.copy_to;
  795. }
  796. }
  797. html += "<button class='icon_btn tooltip' ";
  798. html += " onclick=\"sent_commit('" + iterator.channal + "','" + sid + "')\">";
  799. html += '<svg class="icon" >';
  800. html += '<use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#' + commitIcon + '"></use>';
  801. html += "</svg>";
  802. html += "<span class='tooltiptext tooltip-top'>";
  803. html += commitTipText;
  804. html += "</span>";
  805. html += "</button>";
  806. //推送按钮结束
  807. //更多按钮
  808. html += '<div class="case_dropdown">';
  809. html += "<button class='icon_btn'>";
  810. html += '<svg class="icon" >';
  811. html += '<use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#ic_more"></use>';
  812. html += "</svg>";
  813. html += "</button>";
  814. html += '<div class="case_dropdown-content menu_space_between" style="right:0;">';
  815. //时间线
  816. html += "<a onclick=\"history_show('" + iterator.id + "')\">";
  817. html += "<span>" + gLocal.gui.timeline + "</span>";
  818. html += '<svg class="icon" >';
  819. html += '<use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#recent_scan"></use>';
  820. html += "</svg>";
  821. html += "</a>";
  822. //复制
  823. html += "<a onclick=\"history_show('" + iterator.id + "')\">";
  824. html += "<span>" + gLocal.gui.copy + "</span>";
  825. html += '<svg class="icon" >';
  826. html += '<use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#copy"></use>';
  827. html += "</svg>";
  828. html += "</a>";
  829. //点赞
  830. html += "<a onclick=\"history_show('" + iterator.id + "')\">";
  831. html += "<span>" + gLocal.gui.like + "</span>";
  832. html += '<svg class="icon" >';
  833. html += '<use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#like"></use>';
  834. html += "</svg>";
  835. html += "</a>";
  836. //分享
  837. html += "<a onclick=\"history_show('" + iterator.id + "')\">";
  838. html += "<span>" + gLocal.gui.share_to + "</span>";
  839. html += '<svg class="icon" >';
  840. html += '<use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#share_to"></use>';
  841. html += "</svg>";
  842. html += "</a>";
  843. html += "</div>";
  844. html += "</div>";
  845. //更多按钮结束
  846. }
  847. html += "</div>";
  848. //句子菜单结束
  849. html += "</div>";
  850. html += "</div>";
  851. //tool_bar 结束
  852. html += '<div class="left_bar" >';
  853. html += ' <div class="face">';
  854. if (iterator.id != "") {
  855. html += '<span class="head_img">' + iterator.editor_name.nickname.slice(0, 1) + "</span>";
  856. }
  857. html += "</div>";
  858. html +=
  859. '<div class="date" title="' +
  860. getFullDataTime(iterator.update_time) +
  861. '">' +
  862. getDataTime(iterator.update_time) +
  863. "</div>";
  864. html += "</div>";
  865. html += '<div class="body">';
  866. html += '<div class="head_bar">';
  867. html += '<div class="info">';
  868. html += '<span class="name">' + iterator.editor_name.nickname + "</span>";
  869. html += '<span class="date">' + getPassDataTime(iterator.update_time) + "</span>";
  870. html += "</div>";
  871. html += "<div class='preview'>" + tranText + "</div>";
  872. html += "</div>";
  873. html += '<div class="edit">';
  874. html += '<div class="input">';
  875. html += "<textarea class='tran_sent_textarea' dbid='" + iterator.id + "' ";
  876. html += "sid='" + sid + "' ";
  877. html += "channel='" + iterator.channal + "' ";
  878. if (typeof iterator.is_pr != "undefined" && iterator.is_pr == true) {
  879. html += ' is_pr="true" onchange1="note_pr_save(this)"';
  880. } else {
  881. html += 'is_pr="false" onchange1="note_sent_save_a(this)"';
  882. }
  883. html += ">" + iterator.text + "</textarea>";
  884. html += "</div>";
  885. html += '<div class="edit_tool">';
  886. if (parseInt(iterator.mypower) < 20) {
  887. html += "提交<b>修改建议</b> ";
  888. }
  889. html +=
  890. "Esc <a onclick='tran_sent_edit_cancel(this)'>"+gLocal.gui.cancel+"</a>shift+按回车<a onclick='tran_sent_save(this)'>" +
  891. gLocal.gui.save +
  892. "</a> 按回车换行 支持markdown语法";
  893. html += "</div>";
  894. html += "</div>";
  895. html += '<div class="foot_bar">';
  896. html += '<div class="info">';
  897. if (iterator.id != "") {
  898. html += '<span class="date"> ' + getPassDataTime(iterator.update_time) + "</span>";
  899. }
  900. if (iterator.id != "") {
  901. html += '<span class="name">' + iterator.editor_name.nickname + "</span>";
  902. }
  903. if (iterator.id != "") {
  904. html += '<span class="channel">' + gLocal.gui.updated + " @";
  905. if (typeof iterator.channalinfo == "undefined") {
  906. html += "unkown";
  907. } else {
  908. html += iterator.channalinfo.name;
  909. }
  910. html += "</span>";
  911. } else {
  912. html += '<span class="channel">' + gLocal.gui.no_updated + " @";
  913. if (typeof iterator.channalinfo == "undefined") {
  914. html += "unkown";
  915. } else {
  916. html += iterator.channalinfo.name;
  917. }
  918. html += "</span>";
  919. }
  920. html += '<ul class="tag_list">';
  921. if (iterator.pr_all && parseInt(iterator.pr_all) > 0) {
  922. html +=
  923. "<li onclick=\"note_pr_show('" +
  924. iterator.channal +
  925. "','" +
  926. sid +
  927. "')\"><span class='icon'>✋</span><span class='num'>" +
  928. iterator.pr_new +
  929. "/" +
  930. iterator.pr_all +
  931. "</span></li>";
  932. }
  933. html += "</ul>";
  934. html += "</div>"; //end of info
  935. html += "</div>"; //end of foot bar
  936. html += "</div>";
  937. html += "</div>";
  938. //sent_tran_inner结束
  939. html += '<div class="pr_content"></div>';
  940. html += "</div>";
  941. return html;
  942. }
  943. function tran_sent_textarea_event_init() {
  944. let textarea = document.querySelectorAll(".tran_sent_textarea");
  945. for (let iterator of textarea) {
  946. iterator.onkeydown = function (e) {
  947. let menu = document.querySelector("#menu");
  948. switch (e.key) {
  949. case "Enter":
  950. if (menu && menu.style.display == "block") {
  951. let value = textarea.value;
  952. let selectionStart = textarea.selectionStart;
  953. let str1 = value.slice(0, selectionStart);
  954. let str2 = value.slice(selectionStart);
  955. textarea.value = str1 + data[menuFocusIndex] + "]]" + str2;
  956. menu.style.display = "none";
  957. return false;
  958. } else {
  959. if (e.shiftKey) {
  960. //回车存盘
  961. tran_sent_save(e.currentTarget);
  962. return false;
  963. }
  964. }
  965. break;
  966. case "Escape":
  967. tran_sent_edit_cancel(e.currentTarget);
  968. break;
  969. default:
  970. break;
  971. }
  972. };
  973. }
  974. }
  975. function render_one_sent_tran(book, para, begin, end, iterator) {
  976. let output = "";
  977. output += "<div class='tran' lang='" + iterator.lang + "' style='display:flex;'>";
  978. //译文工具按钮开始
  979. output += "<div class='tran_text_tool_botton' onclick='tool_bar_show(this)'>";
  980. output +=
  981. "<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>";
  982. //译文工具栏开始
  983. output += "<div class='tran_text_tool_bar'>";
  984. output += "<div style='border-right: solid 1px;margin: 0.3em 0;'><li class = 'tip_buttom' ";
  985. output +=
  986. " onclick=\"note_edit_sentence('" +
  987. book +
  988. "' ,'" +
  989. para +
  990. "' ,'" +
  991. begin +
  992. "' ,'" +
  993. end +
  994. "' ,'" +
  995. iterator.channal +
  996. "')\"";
  997. output +=
  998. ">" +
  999. '<svg class="icon" ><use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#ic_mode_edit"></use></svg>';
  1000. output += gLocal.gui.edit + "</li>";
  1001. output += "<li class = 'tip_buttom' ";
  1002. output += " onclick=\"history_show('" + iterator.id + "')\" >";
  1003. output +=
  1004. '<svg class="icon" ><use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#recent_scan"></use></svg>';
  1005. output += gLocal.gui.timeline + "</li>";
  1006. output +=
  1007. "<li class = 'tip_buttom'>" +
  1008. '<svg class="icon" ><use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#copy"></use></svg>';
  1009. output += gLocal.gui.copy + "</li></div>";
  1010. output +=
  1011. "<div style='border-right: solid 1px;margin: 0.3em 0;'><li class = 'tip_buttom'>" +
  1012. '<svg class="icon" ><use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#like"></use></svg>';
  1013. output += gLocal.gui.like + "</li>";
  1014. output +=
  1015. "<li class = 'tip_buttom'>" +
  1016. '<svg class="icon" ><use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#comment"></use></svg>';
  1017. output += gLocal.gui.comment + "</li>";
  1018. output +=
  1019. "<li class = 'tip_buttom'>" +
  1020. '<svg class="icon" ><use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#ic_shopping_cart"></use></svg>';
  1021. output += gLocal.gui.digest + "</li></div>";
  1022. output +=
  1023. "<div style='margin: 0.3em 0;'><li class = 'tip_buttom'>" +
  1024. '<svg class="icon" ><use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#share_to"></use></svg>';
  1025. output += gLocal.gui.share_to + "</li>";
  1026. output += "</div></div>";
  1027. //译文工具栏结束
  1028. output += "</div>";
  1029. //译文工具按钮结束
  1030. //译文正文开始
  1031. output +=
  1032. "<div class='text' id='tran_text_" +
  1033. book +
  1034. "_" +
  1035. para +
  1036. "_" +
  1037. begin +
  1038. "_" +
  1039. end +
  1040. "_" +
  1041. iterator.channal +
  1042. "'>";
  1043. if (iterator.text == "") {
  1044. output +=
  1045. "<span style='color:var(--border-line-color);'>" +
  1046. iterator.channalinfo.name +
  1047. "-" +
  1048. iterator.channalinfo.lang +
  1049. "</span>";
  1050. } else {
  1051. //note_init处理句子链接
  1052. output += note_init(term_std_str_to_tran(iterator.text, iterator.channal, iterator.editor, iterator.lang));
  1053. }
  1054. output += "</div>";
  1055. //译文正文结束
  1056. output += "</div>";
  1057. //单个channal译文框结束
  1058. return output;
  1059. }
  1060. function add_new_tran_button_click(obj) {
  1061. let html = "<div style='display:flex; max-width: 40vw; white-space: normal;'>"
  1062. var first_lang = ""
  1063. for (const iterator of _my_channal) {
  1064. if(iterator.lang){
  1065. first_lang=iterator.lang
  1066. break;
  1067. }
  1068. }
  1069. html += "<ul class='channel_list lang_0' >";
  1070. html += '<li>';
  1071. html += first_lang;
  1072. html += "</li>";
  1073. for (const iterator of _my_channal) {
  1074. if (iterator.status > 0 && first_lang.indexOf(iterator.lang)!=-1 && iterator.lang!=0) {
  1075. if (_channal.indexOf(iterator.id) < 0) {
  1076. html += '<li class="channel_name" onclick="';
  1077. html +=
  1078. "new_sentence('" +
  1079. $(obj).parent().attr("book") +
  1080. "' ,'" +
  1081. $(obj).parent().attr("para") +
  1082. "' ,'" +
  1083. $(obj).parent().attr("begin") +
  1084. "' ,'" +
  1085. $(obj).parent().attr("end") +
  1086. "' ,'" +
  1087. iterator.id +
  1088. "',this)";
  1089. html += '" title="'+iterator.nickname
  1090. html += '">' + iterator.name;
  1091. if (parseInt(iterator.power) < 20) {
  1092. html += "(建议)";
  1093. }
  1094. html += "</li>";
  1095. }
  1096. }
  1097. }
  1098. html += "</ul>";
  1099. html+="<ul class='channel_list lang_1'>";
  1100. html += '<li>';
  1101. html += gLocal.gui.other;
  1102. html += "</li>";
  1103. for (const iterator of _my_channal) {
  1104. if (iterator.status > 0 && first_lang.indexOf(iterator.lang)==-1 && iterator.lang!=0) {
  1105. if (_channal.indexOf(iterator.id) < 0) {
  1106. html += '<li class="channel_name" onclick="';
  1107. html +=
  1108. "new_sentence('" +
  1109. $(obj).parent().attr("book") +
  1110. "' ,'" +
  1111. $(obj).parent().attr("para") +
  1112. "' ,'" +
  1113. $(obj).parent().attr("begin") +
  1114. "' ,'" +
  1115. $(obj).parent().attr("end") +
  1116. "' ,'" +
  1117. iterator.id +
  1118. "',this)";
  1119. html += '" title="'+iterator.nickname
  1120. html += '">' + iterator.name;
  1121. if (parseInt(iterator.power) < 20) {
  1122. html += "(建议)";
  1123. }
  1124. html += "</li>";
  1125. }
  1126. }
  1127. }
  1128. html += "</ul>";
  1129. html+="<ul class='channel_list lang_2'>";
  1130. html += '<li>';
  1131. html += gLocal.gui.collaborate;
  1132. html += "</li>";
  1133. for (const iterator of _my_channal) {
  1134. if (iterator.status > 0 && iterator.lang==0) {
  1135. if (_channal.indexOf(iterator.id) < 0) {
  1136. html += '<li class="channel_name" onclick="';
  1137. html +=
  1138. "new_sentence('" +
  1139. $(obj).parent().attr("book") +
  1140. "' ,'" +
  1141. $(obj).parent().attr("para") +
  1142. "' ,'" +
  1143. $(obj).parent().attr("begin") +
  1144. "' ,'" +
  1145. $(obj).parent().attr("end") +
  1146. "' ,'" +
  1147. iterator.id +
  1148. "',this)";
  1149. html += '" title="'+iterator.nickname
  1150. html += '">' + iterator.name;
  1151. if (parseInt(iterator.power) < 20) {
  1152. html += "(建议)";
  1153. }
  1154. html += "</li>";
  1155. }
  1156. }
  1157. }
  1158. html += "</ul>";
  1159. html += "</div>";
  1160. $(obj).parent().children(".tran_text_tool_bar").first().html(html);
  1161. if ($(obj).parent().children(".tran_text_tool_bar").css("display") == "block") {
  1162. $(obj).parent().children(".tran_text_tool_bar").first().hide();
  1163. } else {
  1164. $(obj).parent().children(".tran_text_tool_bar").first().show();
  1165. $(document).one("click", function () {
  1166. $(obj).parent().children(".tran_text_tool_bar").first().hide();
  1167. });
  1168. event.stopPropagation();
  1169. $(obj).parent().show();
  1170. }
  1171. }
  1172. function tool_bar_show(element) {
  1173. if ($(element).find(".tran_text_tool_bar").css("display") == "none") {
  1174. $(element).find(".tran_text_tool_bar").css("display", "flex");
  1175. $(element).find(".icon_expand").css("transform", "rotate(-180deg)");
  1176. $(element).css("background-color", "var(--btn-bg-color)");
  1177. $(element).css("visibility", "visible");
  1178. $(document).one("click", function () {
  1179. $(element).find(".tran_text_tool_bar").hide();
  1180. $(element).css("background-color", "var(--nocolor)");
  1181. $(element).find(".icon_expand").css("transform", "unset");
  1182. $(element).css("visibility", "");
  1183. });
  1184. event.stopPropagation();
  1185. } else {
  1186. $(element).find(".tran_text_tool_bar").hide();
  1187. $(element).css("background-color", "var(--nocolor)");
  1188. $(element).find(".icon_expand").css("transform", "unset");
  1189. $(element).css("visibility", "");
  1190. }
  1191. }
  1192. function new_sentence(book, para, begin, end, channel, obj) {
  1193. let newsent = { id: "", text: "", lang: "", channal: channel };
  1194. for (let iterator of _arrData) {
  1195. if (iterator.book == book && iterator.para == para && iterator.begin == begin && iterator.end == end) {
  1196. let found = false;
  1197. for (const tran of iterator.translation) {
  1198. if (tran.channal == channel) {
  1199. found = true;
  1200. break;
  1201. }
  1202. }
  1203. if (!found) {
  1204. iterator.translation.push(newsent);
  1205. }
  1206. }
  1207. }
  1208. if ($(obj).parent().parent().css("display") == "block") {
  1209. $(obj).parent().parent().hide();
  1210. }
  1211. note_edit_sentence(book, para, begin, end, channel);
  1212. }
  1213. //显示更多译文按钮动作
  1214. function set_more_button_display() {
  1215. $(".other_tran_div").each(function () {
  1216. const sentid = $(this).attr("sent").split("-");
  1217. const book = sentid[0];
  1218. const para = sentid[1];
  1219. const begin = sentid[2];
  1220. const end = sentid[3];
  1221. let count = 0;
  1222. for (const iterator of _channalData) {
  1223. if (iterator.final) {
  1224. for (const onesent of iterator.final) {
  1225. let id = onesent.id.split("-");
  1226. if (book == id[0] && para == id[1] && begin == id[2] && end == id[3] && onesent.final) {
  1227. if (_channal.indexOf(iterator.id) == -1) {
  1228. count++;
  1229. }
  1230. }
  1231. }
  1232. }
  1233. }
  1234. if (count > 0) {
  1235. $(this).find(".other_tran_num").html(count);
  1236. $(this).find(".other_tran_num").attr("style", "display:inline-flex;");
  1237. $(this)
  1238. .find(".other_bar")
  1239. .click(function () {
  1240. const sentid = $(this).parent().parent().attr("sent").split("-");
  1241. const book = sentid[0];
  1242. const para = sentid[1];
  1243. const begin = sentid[2];
  1244. const end = sentid[3];
  1245. let sentId = $(this).parent().parent().attr("sent");
  1246. if ($(this).parent().parent().siblings(".other_tran").first().css("display") == "none") {
  1247. $(".other_tran_div[sent='" + sentId + "']")
  1248. .children(".other_tran")
  1249. .slideDown();
  1250. $(this).siblings(".more_tran ").css("transform", "unset");
  1251. $.get(
  1252. "../usent/get.php",
  1253. {
  1254. book: book,
  1255. para: para,
  1256. begin: begin,
  1257. end: end,
  1258. },
  1259. function (data, status) {
  1260. let arrSent = JSON.parse(data);
  1261. let html = "<div class='compact'>";
  1262. for (const iterator of arrSent) {
  1263. if (_channal.indexOf(iterator.channal) == -1) {
  1264. html += render_one_sent_tran_a(iterator);
  1265. }
  1266. }
  1267. html += "</div>";
  1268. let sentId =
  1269. arrSent[0].book +
  1270. "-" +
  1271. arrSent[0].paragraph +
  1272. "-" +
  1273. arrSent[0].begin +
  1274. "-" +
  1275. arrSent[0].end;
  1276. $(".other_tran_div[sent='" + sentId + "']")
  1277. .children(".other_tran")
  1278. .html(html);
  1279. }
  1280. );
  1281. } else {
  1282. $(".other_tran_div[sent='" + sentId + "']")
  1283. .children(".other_tran")
  1284. .slideUp();
  1285. $(this).siblings(".more_tran ").css("transform", "rotate(-90deg)");
  1286. }
  1287. });
  1288. } else {
  1289. //隐藏自己
  1290. //$(this).hide();
  1291. $(this).find(".other_tran_span").addClass("disable"); //gLocal.gui.no + gLocal.gui.other + gLocal.gui.translation
  1292. //$(this).find(".more_tran").hide();
  1293. }
  1294. });
  1295. }
  1296. function note_edit_sentence(book, para, begin, end, channal) {
  1297. let channalInfo;
  1298. for (const iterator of _channalData) {
  1299. if (iterator.id == channal) {
  1300. channalInfo = iterator;
  1301. break;
  1302. }
  1303. }
  1304. for (const iterator of _arrData) {
  1305. if (iterator.book == book && iterator.para == para && iterator.begin == begin && iterator.end == end) {
  1306. for (const tran of iterator.translation) {
  1307. if (tran.channal == channal) {
  1308. let html = "";
  1309. html += "<div style='color:blue;'>" + channalInfo.name + "@" + channalInfo.nickname + "</div>";
  1310. html +=
  1311. "<textarea id='edit_dialog_text' sent_id='" +
  1312. tran.id +
  1313. "' book='" +
  1314. book +
  1315. "' para='" +
  1316. para +
  1317. "' begin='" +
  1318. begin +
  1319. "' end='" +
  1320. end +
  1321. "' channal='" +
  1322. channal +
  1323. "' style='width:100%;min-height:260px;'>" +
  1324. tran.text +
  1325. "</textarea>";
  1326. $("#edit_dialog_content").html(html);
  1327. $("#note_sent_edit_dlg").dialog("open");
  1328. return;
  1329. }
  1330. }
  1331. }
  1332. }
  1333. alert("未找到句子");
  1334. }
  1335. function tran_sent_edit_cancel(obj) {
  1336. sent_tran_set_edit_mode(obj, false);
  1337. }
  1338. function tran_sent_save(obj) {
  1339. let sentDiv = find_sent_tran_div(obj);
  1340. if (sentDiv) {
  1341. let textarea = $(sentDiv).children().find(".tran_sent_textarea").first();
  1342. let isPr = $(textarea).attr("is_pr");
  1343. if (isPr == "true") {
  1344. note_pr_save(textarea);
  1345. } else {
  1346. note_sent_save_a(textarea);
  1347. }
  1348. sent_tran_set_edit_mode(textarea, false);
  1349. } else {
  1350. console.error("sent div not found");
  1351. }
  1352. }
  1353. //保存pr句子 新
  1354. function note_pr_save(obj) {
  1355. let id = $(obj).attr("dbid");
  1356. let sid = $(obj).attr("sid").split("-");
  1357. let book = sid[0];
  1358. let para = sid[1];
  1359. let begin = sid[2];
  1360. let end = sid[3];
  1361. let channel = $(obj).attr("channel");
  1362. let text = $(obj).val();
  1363. let sent_tran_div = find_sent_tran_div(obj);
  1364. $.post(
  1365. "../usent/pr_post.php",
  1366. {
  1367. id: id,
  1368. book: book,
  1369. para: para,
  1370. begin: begin,
  1371. end: end,
  1372. channel: channel,
  1373. text: text,
  1374. },
  1375. sent_save_callback
  1376. );
  1377. if (sent_tran_div) {
  1378. $(sent_tran_div).find(".preview").addClass("loading");
  1379. }
  1380. }
  1381. //保存译文句子 新
  1382. function note_sent_save_a(obj) {
  1383. let id = $(obj).attr("dbid");
  1384. let sid = $(obj).attr("sid").split("-");
  1385. let book = sid[0];
  1386. let para = sid[1];
  1387. let begin = sid[2];
  1388. let end = sid[3];
  1389. let channal = $(obj).attr("channel");
  1390. let text = $(obj).val();
  1391. let sent_tran_div = find_sent_tran_div(obj);
  1392. $.post(
  1393. "../usent/sent_post.php",
  1394. {
  1395. id: id,
  1396. book: book,
  1397. para: para,
  1398. begin: begin,
  1399. end: end,
  1400. channal: channal,
  1401. text: text,
  1402. lang: "zh",
  1403. },
  1404. sent_save_callback
  1405. );
  1406. if (sent_tran_div) {
  1407. $(sent_tran_div).find(".preview").addClass("loading");
  1408. }
  1409. }
  1410. function update_sent_tran(sentData) {}
  1411. function sent_save_callback(data) {
  1412. let result = JSON.parse(data);
  1413. if (result.status > 0) {
  1414. alert("error" + result.message);
  1415. } else {
  1416. let sid = result.book + "-" + result.para + "-" + result.begin + "-" + result.end;
  1417. let sent_tran_div = $(
  1418. ".sent_tran[dbid='" + result.id + "'][channel='" + result.channal + "'][sid='" + sid + "']"
  1419. );
  1420. if (result.commit_type == 1 || result.commit_type == 2) {
  1421. ntf_show("成功修改");
  1422. if (sent_tran_div) {
  1423. let divPreview = sent_tran_div.find(".preview").first();
  1424. if (result.text == "") {
  1425. let channel_info = "Empty";
  1426. let thisChannel = find_channal(result.channal);
  1427. if (thisChannel) {
  1428. channel_info = thisChannel.name + "-" + thisChannel.nickname;
  1429. }
  1430. divPreview.html("<span style='color:var(--border-line-color);'>" + channel_info + "</span>");
  1431. } else {
  1432. divPreview.html(
  1433. marked(term_std_str_to_tran(result.text, result.channal, result.editor, result.lang))
  1434. );
  1435. term_updata_translation();
  1436. popup_init();
  1437. for (const iterator of _arrData) {
  1438. if (
  1439. iterator.book == result.book &&
  1440. iterator.para == result.para &&
  1441. iterator.begin == result.begin &&
  1442. iterator.end == result.end
  1443. ) {
  1444. for (const tran of iterator.translation) {
  1445. if (tran.channal == result.channal) {
  1446. tran.text = result.text;
  1447. break;
  1448. }
  1449. }
  1450. }
  1451. }
  1452. }
  1453. sent_tran_div.find(".preview").removeClass("loading");
  1454. }
  1455. } else if (result.commit_type == 3) {
  1456. ntf_show("已经提交修改建议");
  1457. } else {
  1458. ntf_show("未提交");
  1459. }
  1460. }
  1461. }
  1462. //保存译文句子
  1463. function note_sent_save() {
  1464. let id = $("#edit_dialog_text").attr("sent_id");
  1465. let book = $("#edit_dialog_text").attr("book");
  1466. let para = $("#edit_dialog_text").attr("para");
  1467. let begin = $("#edit_dialog_text").attr("begin");
  1468. let end = $("#edit_dialog_text").attr("end");
  1469. let channal = $("#edit_dialog_text").attr("channal");
  1470. let text = $("#edit_dialog_text").val();
  1471. $.post(
  1472. "../usent/sent_post.php",
  1473. {
  1474. id: id,
  1475. book: book,
  1476. para: para,
  1477. begin: begin,
  1478. end: end,
  1479. channal: channal,
  1480. text: text,
  1481. lang: "zh",
  1482. },
  1483. function (data) {
  1484. let result = JSON.parse(data);
  1485. if (result.status > 0) {
  1486. alert("error" + result.message);
  1487. } else {
  1488. if (result.commit_type == 1 || result.commit_type == 2) {
  1489. ntf_show("成功修改");
  1490. if (result.text == "") {
  1491. let channel_info = "Empty";
  1492. let thisChannel = find_channal(result.channal);
  1493. if (thisChannel) {
  1494. channel_info = thisChannel.name + "-" + thisChannel.nickname;
  1495. }
  1496. $(
  1497. "#tran_text_" +
  1498. result.book +
  1499. "_" +
  1500. result.para +
  1501. "_" +
  1502. result.begin +
  1503. "_" +
  1504. result.end +
  1505. "_" +
  1506. result.channal
  1507. ).html("<span style='color:var(--border-line-color);'>" + channel_info + "</span>");
  1508. } else {
  1509. $(
  1510. "#tran_text_" +
  1511. result.book +
  1512. "_" +
  1513. result.para +
  1514. "_" +
  1515. result.begin +
  1516. "_" +
  1517. result.end +
  1518. "_" +
  1519. result.channal
  1520. ).html(marked(term_std_str_to_tran(result.text, result.channal, result.editor, result.lang)));
  1521. term_updata_translation();
  1522. for (const iterator of _arrData) {
  1523. if (
  1524. iterator.book == result.book &&
  1525. iterator.para == result.para &&
  1526. iterator.begin == result.begin &&
  1527. iterator.end == result.end
  1528. ) {
  1529. for (const tran of iterator.translation) {
  1530. if (tran.channal == result.channal) {
  1531. tran.text = result.text;
  1532. break;
  1533. }
  1534. }
  1535. }
  1536. }
  1537. }
  1538. } else if (result.commit_type == 3) {
  1539. ntf_show("已经提交修改建议");
  1540. } else {
  1541. ntf_show("未提交");
  1542. }
  1543. }
  1544. }
  1545. );
  1546. }
  1547. function copy_ref(book, para, begin, end) {
  1548. let strRef = "{{" + book + "-" + para + "-" + begin + "-" + end + "}}";
  1549. copy_to_clipboard(strRef);
  1550. }
  1551. function goto_nissaya(book, para, begin = 0, end = 0) {
  1552. window.open("../nissaya/index.php?book=" + book + "&para=" + para + "&begin=" + begin + "&end=" + end, "nissaya");
  1553. }
  1554. function edit_in_studio(book, para, begin, end) {
  1555. wbw_channal_list_open(book, [para]);
  1556. }
  1557. //显示和隐藏某个内容 如 巴利文
  1558. function setVisibility(key, value) {
  1559. switch (key) {
  1560. case "palitext":
  1561. if ($(value).is(":checked")) {
  1562. $(".palitext").show();
  1563. } else {
  1564. $(".palitext").hide();
  1565. }
  1566. break;
  1567. default:
  1568. break;
  1569. }
  1570. }
  1571. function note_show_pali_sim(SentId) {
  1572. pali_sim_dlg_open(SentId, 0, 20);
  1573. }
  1574. function set_pali_script(pos, script) {
  1575. if (script == "none") {
  1576. $(".palitext" + pos).html("");
  1577. } else {
  1578. $(".palitext" + pos).each(function () {
  1579. let html = $(this).siblings(".palitext_roma").first().html();
  1580. $(this).html(html);
  1581. });
  1582. $(".palitext" + pos)
  1583. .find("*")
  1584. .contents()
  1585. .filter(function () {
  1586. return this.nodeType != 1;
  1587. })
  1588. .wrap("<pl" + pos + "></pl" + pos + ">");
  1589. $(".palitext" + pos)
  1590. .contents()
  1591. .filter(function () {
  1592. return this.nodeType != 1;
  1593. })
  1594. .wrap("<pl" + pos + "></pl" + pos + ">");
  1595. $("pl" + pos).html(function (index, oldcontent) {
  1596. return roman_to_my(oldcontent);
  1597. });
  1598. }
  1599. }
  1600. function splite_pali_word() {
  1601. $("pali")
  1602. .contents()
  1603. .filter(function () {
  1604. return this.nodeType != 1;
  1605. })
  1606. .wrap("<pl></pl>");
  1607. $("pl").each(function () {
  1608. let html = $(this).html();
  1609. $(this).html("<w>" + html.replace(/\s/g, "</w> <w>") + "</w>");
  1610. });
  1611. $("w").click(function () {
  1612. let word = com_getPaliReal($(this).text());
  1613. if (gBuildinDictIsOpen) {
  1614. window.open("../dict/index.php?builtin=true&key=" + word, "dict");
  1615. }
  1616. });
  1617. }
  1618. function refresh_pali_script() {
  1619. if (_display && _display == "para") {
  1620. //段落模式
  1621. } else {
  1622. //句子模式
  1623. setting_get("lib.second_script", set_second_scrip);
  1624. }
  1625. }
  1626. function set_second_scrip(value) {
  1627. set_pali_script(2, value);
  1628. }
  1629. function slider_show(obj) {
  1630. $(obj).parent().parent().parent().parent().parent().toggleClass("slider_show_shell");
  1631. }
  1632. function find_sent_tran_div(obj) {
  1633. let jqObj = $(obj);
  1634. while (!jqObj.hasClass("sent_tran")) {
  1635. jqObj = jqObj.parent();
  1636. if (!jqObj) {
  1637. return false;
  1638. }
  1639. }
  1640. return jqObj;
  1641. /*
  1642. let parent = obj.parentNode;
  1643. while (parent.nodeType == 1) {
  1644. if ($(parent).hasClass("sent_tran")) {
  1645. return parent;
  1646. } else if (parent.nodeName == "BODY") {
  1647. return false;
  1648. }
  1649. parent = parent.parentNode;
  1650. }
  1651. return false;
  1652. */
  1653. }
  1654. //显示或隐藏pr数据
  1655. function note_pr_show(channel, id) {
  1656. let obj = $(".sent_tran[channel='" + channel + "'][sid='" + id + "']").find(".pr_content");
  1657. let prHtml = obj.first().html();
  1658. if (prHtml == "") {
  1659. note_get_pr(channel, id);
  1660. } else {
  1661. obj.slideUp();
  1662. obj.html("");
  1663. }
  1664. }
  1665. //获取pr数据并显示
  1666. function note_get_pr(channel, id) {
  1667. let sid = id.split("-");
  1668. let book = sid[0];
  1669. let para = sid[1];
  1670. let begin = sid[2];
  1671. let end = sid[3];
  1672. $.post(
  1673. "../usent/get_pr.php",
  1674. {
  1675. book: book,
  1676. para: para,
  1677. begin: begin,
  1678. end: end,
  1679. channel: channel,
  1680. },
  1681. function (data) {
  1682. let result = JSON.parse(data);
  1683. if (result.length > 0) {
  1684. let html = "<div class='compact'>";
  1685. for (const iterator of result) {
  1686. html += render_one_sent_tran_a(iterator);
  1687. }
  1688. html += "</div>";
  1689. $(".sent_tran[channel='" + channel + "'][sid='" + id + "']")
  1690. .find(".pr_content")
  1691. .html(html);
  1692. $(".sent_tran[channel='" + channel + "'][sid='" + id + "']")
  1693. .find(".pr_content")
  1694. .slideDown();
  1695. } else {
  1696. }
  1697. }
  1698. );
  1699. $(".sent_tran[channel='" + channel + "'][sid='" + id + "']")
  1700. .find(".pr_content")
  1701. .html("loading");
  1702. $(".sent_tran[channel='" + channel + "'][sid='" + id + "']")
  1703. .find(".pr_content")
  1704. .show();
  1705. }
  1706. function get_channel_by_id(id) {
  1707. if (typeof _channalData != "undefined") {
  1708. for (const iterator of _channalData) {
  1709. if (iterator.id == id) {
  1710. return iterator;
  1711. }
  1712. }
  1713. }
  1714. if (typeof _my_channal != "undefined") {
  1715. for (const iterator of _my_channal) {
  1716. if (iterator.id == id) {
  1717. return iterator;
  1718. }
  1719. }
  1720. }
  1721. return false;
  1722. }
  1723. //设置显示方向
  1724. function setDirection(obj) {
  1725. if (obj.value == "row") {
  1726. $("#contents").removeClass("vertical");
  1727. $("#contents").addClass("horizontal");
  1728. } else {
  1729. $("#contents").removeClass("horizontal");
  1730. $("#contents").addClass("vertical");
  1731. }
  1732. }
  1733. //设置逐段或逐句模式
  1734. function setDisplay(obj) {
  1735. if (obj.value == "para") {
  1736. $("#contents").removeClass("sent_mode");
  1737. $("#contents").addClass("para_mode");
  1738. } else {
  1739. $("#contents").removeClass("para_mode");
  1740. $("#contents").addClass("sent_mode");
  1741. }
  1742. }