note.js 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624
  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. switch (parseInt(channalinfo.status)) {
  329. case 10:
  330. output += "🔐";
  331. break;
  332. case 20:
  333. output += "🌐";
  334. break;
  335. case 30:
  336. output += "🌐";
  337. break;
  338. default:
  339. break;
  340. }
  341. if (parseInt(channalinfo.power) >= 20) {
  342. //if (parseInt(channalinfo.power) != 30)
  343. {
  344. output += "✏️";
  345. }
  346. }
  347. //✋
  348. output += "<a onclick=\"set_channal('" + channalinfo.id + "')\">";
  349. output += channalinfo["name"];
  350. output += "</a>";
  351. if (parseInt(channalinfo.power) == 30) {
  352. output += "@" + gLocal.gui.your;
  353. } else {
  354. output += "@" + channalinfo["nickname"];
  355. }
  356. output += "</div>";
  357. output += "<div class='userinfo_channal'>";
  358. output += channalinfo["username"];
  359. output += "</div>";
  360. if (channalinfo["final"]) {
  361. //进度
  362. output += "<div>";
  363. let article_len = channalinfo["article_len"];
  364. let svg_width = article_len;
  365. let svg_height = parseInt(article_len / 10);
  366. output += '<svg viewBox="0 0 ' + svg_width + " " + svg_height + '" width="100%" >';
  367. let curr_x = 0;
  368. let allFinal = 0;
  369. for (const iterator of channalinfo["final"]) {
  370. let stroke_width = parseInt(iterator.len);
  371. output += "<rect ";
  372. output += ' x="' + curr_x + '"';
  373. output += ' y="0"';
  374. output += ' height="' + svg_height + '"';
  375. output += ' width="' + stroke_width + '"';
  376. if (iterator.final == true) {
  377. allFinal += stroke_width;
  378. output += ' class="progress_bar_done" ';
  379. } else {
  380. output += ' class="progress_bar_undone" ';
  381. }
  382. output += "/>";
  383. curr_x += stroke_width;
  384. }
  385. output +=
  386. "<rect x='0' y='0' width='" + svg_width + "' height='" + svg_height / 5 + "' class='progress_bar_bg' />";
  387. output +=
  388. "<rect x='0' y='0' width='" +
  389. allFinal +
  390. "' height='" +
  391. svg_height / 5 +
  392. "' class='progress_bar_percent' style='stroke-width: 0; fill: rgb(100, 228, 100);'/>";
  393. output += '<text x="0" y="' + svg_height + '" font-size="' + svg_height * 0.8 + '">';
  394. output += channalinfo["count"] + "/" + channalinfo["all"] + "@" + curr_x;
  395. output += "</text>";
  396. output += "<svg>";
  397. output += "</div>";
  398. //进度结束
  399. }
  400. output += "</div>";
  401. output += "</div>";
  402. return output;
  403. }
  404. function onChannelMultiSelectStart() {
  405. $(".channel_select").show();
  406. }
  407. function onChannelMultiSelectCancel() {
  408. $(".channel_select").hide();
  409. }
  410. function onChannelChange() {
  411. let channal_list = new Array();
  412. $("[channal_id]").each(function () {
  413. if (this.checked) {
  414. channal_list.push($(this).attr("channal_id"));
  415. }
  416. });
  417. set_channal(channal_list.join());
  418. }
  419. //点击引用 需要响应的事件
  420. function note_ref_init() {
  421. $("chapter").click(function () {
  422. let bookid = $(this).attr("book");
  423. let para = $(this).attr("para");
  424. window.open("../reader/?view=chapter&book=" + bookid + "&para=" + para, "_blank");
  425. });
  426. $("para").click(function () {
  427. let bookid = $(this).attr("book");
  428. let para = $(this).attr("para");
  429. window.open("../reader/?view=para&book=" + bookid + "&para=" + para, "_blank");
  430. });
  431. }
  432. /*
  433. id
  434. palitext
  435. tran
  436. ref
  437. */
  438. function note_json_html(in_json) {
  439. let output = "";
  440. output += '<div class="note_tool_bar" style=" position: relative;">';
  441. output += '<div class="case_dropdown note_tool_context" >';
  442. output += "<svg class='icon' >";
  443. output += "<use xlink:href='../studio/svg/icon.svg#ic_more'></use>";
  444. output += "</svg>";
  445. output += "<div class='case_dropdown-content sent_menu'>";
  446. if (typeof _reader_view != "undefined" && _reader_view != "sent") {
  447. output += "<a onclick='junp_to(this)'>" + gLocal.gui.jump_to_this_sent + "</a>";
  448. }
  449. output +=
  450. "<a onclick='related_para_dlg_open(" +
  451. in_json.book +
  452. "," +
  453. in_json.para +
  454. ")'>" +
  455. gLocal.gui.related_para +
  456. "</a>";
  457. output +=
  458. "<a onclick='goto_nissaya(" +
  459. in_json.book +
  460. "," +
  461. in_json.para +
  462. "," +
  463. in_json.begin +
  464. "," +
  465. in_json.end +
  466. ")'>" +
  467. gLocal.gui.show_nissaya +
  468. "</a>";
  469. output +=
  470. "<a onclick=\"copy_ref('" +
  471. in_json.book +
  472. "','" +
  473. in_json.para +
  474. "','" +
  475. in_json.begin +
  476. "','" +
  477. in_json.end +
  478. "')\">" +
  479. gLocal.gui.copy_link +
  480. "</a>";
  481. output += "<a onclick='copy_text(this)'>" + gLocal.gui.copy + "“" + gLocal.gui.pāli + "”</a>";
  482. output +=
  483. "<a onclick=\"edit_in_studio('" +
  484. in_json.book +
  485. "','" +
  486. in_json.para +
  487. "','" +
  488. in_json.begin +
  489. "','" +
  490. in_json.end +
  491. "')\">" +
  492. gLocal.gui.edit_now +
  493. "</a>";
  494. output += "<a onclick='add_to_list()'>" + gLocal.gui.add_to_edit_list + "</a>";
  495. output += "<a onclick='slider_show(this)'>Slider Show</a>";
  496. output += "</div>";
  497. output += "</div>";
  498. output += " </div>";
  499. output += "<div class='palitext palitext_roma'>" + in_json.palitext + "</div>";
  500. output += "<div class='palitext palitext1'></div>";
  501. output += "<div class='palitext palitext2'></div>";
  502. //output += "<div id='translation_div'>";
  503. for (const iterator of in_json.translation) {
  504. output += render_one_sent_tran_a(iterator);
  505. //output += render_one_sent_tran(in_json.book, in_json.para, in_json.begin, in_json.end, iterator);
  506. }
  507. //所选全部译文结束
  508. //output += "</div>";
  509. //未选择的其他译文开始
  510. output += "<div class='other_tran_div' sent='";
  511. output += in_json.book + "-" + in_json.para + "-" + in_json.begin + "-" + in_json.end + "' >";
  512. output += "<div class='tool_bar' sent='";
  513. output += in_json.book + "-" + in_json.para + "-" + in_json.begin + "-" + in_json.end + "' >";
  514. output += "<span class='tool_left'>";
  515. //第一个按钮
  516. //新增译文按钮开始
  517. output += "<span class='' ";
  518. output += "book='" + in_json.book + "' ";
  519. output += "para='" + in_json.para + "' ";
  520. output += "begin='" + in_json.begin + "' ";
  521. output += "end='" + in_json.end + "' ";
  522. output += " >";
  523. output += "<span class='' onclick='add_new_tran_button_click(this)' title='" + gLocal.gui.add_tran + "'>➕</span>";
  524. output += "<div class='tran_text_tool_bar'>";
  525. output += "</div>";
  526. output += "</span>";
  527. //新增译文按钮结束
  528. output += "<span class='separate_line'></span>";
  529. //第二个按钮
  530. output += "<span class='more_tran icon_expand'></span>";
  531. //其他译文工具条
  532. output += "<span class='other_bar' >";
  533. output +=
  534. "<span class='other_tran_span' title='" +
  535. gLocal.gui.other +
  536. gLocal.gui.translation +
  537. "'>🧲" +
  538. gLocal.gui.translation +
  539. "</span>";
  540. output += "<span class='other_tran_num'></span>";
  541. output += "</span>";
  542. output += "<span class='separate_line'></span>";
  543. //手工义注
  544. output += "<span class='other_bar' >";
  545. output +=
  546. "<span class='other_tran_span commentray' title='📔" +
  547. gLocal.gui.vannana +
  548. "'>🪔" +
  549. gLocal.gui.commentary +
  550. "</span>";
  551. output += "<span class='other_tran_num'></span>";
  552. output += "</span>";
  553. output += "<span class='separate_line'></span>";
  554. //第三个按钮 相似句
  555. if (parseInt(in_json.sim) > 0) {
  556. output += "<span class='other_bar' >";
  557. output +=
  558. "<span class='similar_sent_span' onclick=\"note_show_pali_sim('" +
  559. in_json.pali_sent_id +
  560. "')\" title='" +
  561. gLocal.gui.similar_sentences +
  562. "'>🧬" +
  563. gLocal.gui.similar +
  564. "</span>";
  565. output += "<span class='similar_sent_num'>" + in_json.sim + "</span>";
  566. output += "</span>";
  567. output += "<span class='separate_line'></span>";
  568. }
  569. //第三个按钮 相似句结束
  570. output += "</span>";
  571. output += "<span class='tool_right'>";
  572. //出处路径开始
  573. output += "<span class='ref'>" + in_json.ref;
  574. output += "<span class='sent_no'>";
  575. output += in_json.book + "-" + in_json.para + "-" + in_json.begin + "-" + in_json.end;
  576. output += "<span>";
  577. output += "</span>";
  578. //出处路径结束
  579. output += "</span>";
  580. output += "</div>";
  581. //工具栏结束
  582. //未选择的其他译文开始
  583. output += "<div class='other_tran'>";
  584. output += "</div>";
  585. output += "</div>";
  586. return output;
  587. }
  588. function sent_tran_edit(obj) {
  589. let jqObj = $(obj);
  590. while (!jqObj.hasClass("sent_tran")) {
  591. jqObj = jqObj.parent();
  592. if (!jqObj) {
  593. return;
  594. }
  595. }
  596. if (jqObj.hasClass("edit_mode")) {
  597. jqObj.removeClass("edit_mode");
  598. } else {
  599. $(".sent_tran").removeClass("edit_mode");
  600. jqObj.addClass("edit_mode");
  601. }
  602. }
  603. function sent_pr_merge(id) {
  604. $.post(
  605. "../usent/sent_pr_merge.php",
  606. {
  607. id: id,
  608. },
  609. function (data) {
  610. let result = JSON.parse(data);
  611. if (result.status > 0) {
  612. alert("error" + result.message);
  613. } else {
  614. ntf_show("成功采纳");
  615. }
  616. }
  617. );
  618. }
  619. function sent_commit(src, id) {
  620. commit_init({
  621. src: src,
  622. sent: [id],
  623. express: true,
  624. });
  625. }
  626. function render_one_sent_tran_a(iterator) {
  627. let mChannel = get_channel_by_id(iterator.channal);
  628. let tranText;
  629. let sid = iterator.book + "-" + iterator.para + "-" + iterator.begin + "-" + iterator.end;
  630. if (iterator.text == "") {
  631. if (typeof iterator.channalinfo == "undefined") {
  632. tranText =
  633. "<span style='color:var(--border-line-color);'>" +
  634. "空" +
  635. "@" +
  636. iterator.editor_name.nickname +
  637. "</span>";
  638. } else {
  639. tranText =
  640. "<span style='color:var(--border-line-color);'>" +
  641. iterator.channalinfo.name +
  642. "-" +
  643. iterator.channalinfo.lang +
  644. "</span>";
  645. }
  646. } else {
  647. //note_init处理句子链接
  648. tranText = note_init(term_std_str_to_tran(iterator.text, iterator.channal, iterator.editor, iterator.lang));
  649. }
  650. let html = "";
  651. html += "<div class='sent_tran ";
  652. if (typeof iterator.is_pr != "undefined" && iterator.is_pr == true) {
  653. html += " pr ";
  654. }
  655. html += "' dbid='" + iterator.id + "' channel='" + iterator.channal + "' sid='" + sid + "'>";
  656. html += "<div class='sent_tran_inner'>";
  657. html += '<div class="tool_bar">';
  658. html += ' <div class="right">';
  659. //句子菜单
  660. html += '<div class="pop_menu">';
  661. if (typeof iterator.is_pr != "undefined" && iterator.is_pr == true) {
  662. //在pr 列表中的译文
  663. if (typeof iterator.is_pr_editor != "undefined" && iterator.is_pr_editor == true) {
  664. //提交人
  665. //修改按钮
  666. html += "<button class='icon_btn tooltip' onclick='sent_tran_edit(this)'>";
  667. html += '<svg class="icon" >';
  668. html += '<use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#ic_mode_edit"></use>';
  669. html += "</svg>";
  670. html += "<span class='tooltiptext tooltip-top'>";
  671. html += gLocal.gui.modify;
  672. html += "</span>";
  673. html += "</button>";
  674. //删除按钮
  675. html += "<button class='icon_btn tooltip' onclick='sent_pr_del(this)'>";
  676. html += '<svg class="icon" >';
  677. html += '<use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#ic_delete"></use>';
  678. html += "</svg>";
  679. html += "<span class='tooltiptext tooltip-top'>";
  680. html += gLocal.gui.delete;
  681. html += "</span>";
  682. html += "</button>";
  683. } else {
  684. //非提交人
  685. if (parseInt(iterator.mypower) >= 20) {
  686. //有权限 采纳按钮
  687. html += "<button class='icon_btn tooltip' onclick=\"sent_pr_merge('" + iterator.id + "')\">";
  688. html += '<svg class="icon" >';
  689. html += '<use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#accept_copy"></use>';
  690. html += "</svg>";
  691. html += "<span class='tooltiptext tooltip-top'>";
  692. html += gLocal.gui.accept_copy;
  693. html += "</span>";
  694. html += "</button>";
  695. }
  696. //点赞按钮
  697. html += "<button class='icon_btn tooltip' onclick='sent_pr_like(this)'>";
  698. html += '<svg class="icon" >';
  699. html += '<use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#like"></use>';
  700. html += "</svg>";
  701. html += "<span class='tooltiptext tooltip-top'>";
  702. html += gLocal.gui.like;
  703. html += "</span>";
  704. html += "</button>";
  705. }
  706. } else {
  707. //非pr列表里的句子
  708. //编辑按钮
  709. html += "<button class='icon_btn tooltip' onclick='sent_tran_edit(this)'>";
  710. html += '<svg class="icon" >';
  711. if (parseInt(iterator.mypower) < 20) {
  712. html += '<use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#my_idea"></use>';
  713. } else {
  714. html += '<use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#ic_mode_edit"></use>';
  715. }
  716. html += "</svg>";
  717. html += "<span class='tooltiptext tooltip-top'>";
  718. if (parseInt(iterator.mypower) < 20) {
  719. html += gLocal.gui.suggest;
  720. } else {
  721. html += gLocal.gui.edit;
  722. }
  723. html += "</span>";
  724. html += "</button>";
  725. //推送按钮
  726. let commitIcon = "";
  727. let commitTipText = "";
  728. if (parseInt(iterator.mypower) >= 30 && parseInt(iterator.status) < 30) {
  729. //我的私有资源 公开发布
  730. commitIcon = "publish";
  731. commitTipText = gLocal.gui.publish;
  732. } else {
  733. if (parseInt(iterator.mypower) < 20) {
  734. //只读资源 采纳
  735. commitIcon = "accept_copy";
  736. commitTipText = gLocal.gui.accept_copy;
  737. } else {
  738. //其他资源 复制到
  739. commitIcon = "copy";
  740. commitTipText = gLocal.gui.copy_to;
  741. }
  742. }
  743. html += "<button class='icon_btn tooltip' ";
  744. html += " onclick=\"sent_commit('" + iterator.channal + "','" + sid + "')\">";
  745. html += '<svg class="icon" >';
  746. html += '<use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#' + commitIcon + '"></use>';
  747. html += "</svg>";
  748. html += "<span class='tooltiptext tooltip-top'>";
  749. html += commitTipText;
  750. html += "</span>";
  751. html += "</button>";
  752. //推送按钮结束
  753. //更多按钮
  754. html += '<div class="case_dropdown">';
  755. html += "<button class='icon_btn'>";
  756. html += '<svg class="icon" >';
  757. html += '<use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#ic_more"></use>';
  758. html += "</svg>";
  759. html += "</button>";
  760. html += '<div class="case_dropdown-content menu_space_between" style="right:0;">';
  761. //时间线
  762. html += "<a onclick=\"history_show('" + iterator.id + "')\">";
  763. html += "<span>" + gLocal.gui.timeline + "</span>";
  764. html += '<svg class="icon" >';
  765. html += '<use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#recent_scan"></use>';
  766. html += "</svg>";
  767. html += "</a>";
  768. //复制
  769. html += "<a onclick=\"history_show('" + iterator.id + "')\">";
  770. html += "<span>" + gLocal.gui.copy + "</span>";
  771. html += '<svg class="icon" >';
  772. html += '<use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#copy"></use>';
  773. html += "</svg>";
  774. html += "</a>";
  775. //点赞
  776. html += "<a onclick=\"history_show('" + iterator.id + "')\">";
  777. html += "<span>" + gLocal.gui.like + "</span>";
  778. html += '<svg class="icon" >';
  779. html += '<use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#like"></use>';
  780. html += "</svg>";
  781. html += "</a>";
  782. //分享
  783. html += "<a onclick=\"history_show('" + iterator.id + "')\">";
  784. html += "<span>" + gLocal.gui.share_to + "</span>";
  785. html += '<svg class="icon" >';
  786. html += '<use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#share_to"></use>';
  787. html += "</svg>";
  788. html += "</a>";
  789. html += "</div>";
  790. html += "</div>";
  791. //更多按钮结束
  792. }
  793. html += "</div>";
  794. //句子菜单结束
  795. html += "</div>";
  796. html += "</div>";
  797. //tool_bar 结束
  798. html += '<div class="left_bar" >';
  799. html += ' <div class="face">';
  800. if (iterator.id != "") {
  801. html += '<span class="head_img">' + iterator.editor_name.nickname.slice(0, 1) + "</span>";
  802. }
  803. html += "</div>";
  804. html +=
  805. '<div class="date" title="' +
  806. getFullDataTime(iterator.update_time) +
  807. '">' +
  808. getDataTime(iterator.update_time) +
  809. "</div>";
  810. html += "</div>";
  811. html += '<div class="body">';
  812. html += '<div class="head_bar">';
  813. html += '<div class="info">';
  814. html += '<span class="name">' + iterator.editor_name.nickname + "</span>";
  815. html += '<span class="date">' + getPassDataTime(iterator.update_time) + "</span>";
  816. html += "</div>";
  817. html += "<div class='preview'>" + tranText + "</div>";
  818. html += "</div>";
  819. html += '<div class="edit">';
  820. html += '<div class="input">';
  821. html += "<textarea dbid='" + iterator.id + "' ";
  822. html += "sid='" + sid + "' ";
  823. html += "channel='" + iterator.channal + "' ";
  824. if (typeof iterator.is_pr != "undefined" && iterator.is_pr == true) {
  825. html += 'onchange="note_pr_save(this)"';
  826. } else {
  827. html += 'onchange="note_sent_save_a(this)"';
  828. }
  829. html += ">" + iterator.text + "</textarea>";
  830. html += "</div>";
  831. html += '<div class="edit_tool">';
  832. if (parseInt(iterator.mypower) < 20) {
  833. html += "<b>提交修改建议</b> ";
  834. }
  835. html += "点击输入框外面自动<a onclick='sent_tran_edit(this)'>" + gLocal.gui.save + "</a> 支持markdown语法";
  836. html += "</div>";
  837. html += "</div>";
  838. html += '<div class="foot_bar">';
  839. html += '<div class="info">';
  840. if (iterator.id != "") {
  841. html += '<span class="date"> ' + getPassDataTime(iterator.update_time) + "</span>";
  842. }
  843. if (iterator.id != "") {
  844. html += '<span class="name">' + iterator.editor_name.nickname + "</span>";
  845. }
  846. if (iterator.id != "") {
  847. html += '<span class="channel">' + gLocal.gui.updated + " @";
  848. if (typeof iterator.channalinfo == "undefined") {
  849. html += "unkown";
  850. } else {
  851. html += iterator.channalinfo.name;
  852. }
  853. html += "</span>";
  854. } else {
  855. html += '<span class="channel">' + gLocal.gui.no_updated + " @";
  856. if (typeof iterator.channalinfo == "undefined") {
  857. html += "unkown";
  858. } else {
  859. html += iterator.channalinfo.name;
  860. }
  861. html += "</span>";
  862. }
  863. html += '<ul class="tag_list">';
  864. if (iterator.pr_all && parseInt(iterator.pr_all) > 0) {
  865. html +=
  866. " <li onclick=\"note_pr_show('" +
  867. iterator.channal +
  868. "','" +
  869. sid +
  870. "')\"><span class='icon'>✋</span><span class='num'>" +
  871. iterator.pr_new +
  872. "/" +
  873. iterator.pr_all +
  874. "</span></li>";
  875. }
  876. html += "</ul>";
  877. html += "</div>"; //end of info
  878. html += "</div>"; //end of foot bar
  879. html += "</div>";
  880. html += "</div>";
  881. //sent_tran_inner结束
  882. html += '<div class="pr_content"></div>';
  883. html += "</div>";
  884. return html;
  885. }
  886. function render_one_sent_tran(book, para, begin, end, iterator) {
  887. let output = "";
  888. output += "<div class='tran' lang='" + iterator.lang + "' style='display:flex;'>";
  889. //译文工具按钮开始
  890. output += "<div class='tran_text_tool_botton' onclick='tool_bar_show(this)'>";
  891. output +=
  892. "<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>";
  893. //译文工具栏开始
  894. output += "<div class='tran_text_tool_bar'>";
  895. output += "<div style='border-right: solid 1px;margin: 0.3em 0;'><li class = 'tip_buttom' ";
  896. output +=
  897. " onclick=\"note_edit_sentence('" +
  898. book +
  899. "' ,'" +
  900. para +
  901. "' ,'" +
  902. begin +
  903. "' ,'" +
  904. end +
  905. "' ,'" +
  906. iterator.channal +
  907. "')\"";
  908. output +=
  909. ">" +
  910. '<svg class="icon" ><use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#ic_mode_edit"></use></svg>';
  911. output += gLocal.gui.edit + "</li>";
  912. output += "<li class = 'tip_buttom' ";
  913. output += " onclick=\"history_show('" + iterator.id + "')\" >";
  914. output +=
  915. '<svg class="icon" ><use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#recent_scan"></use></svg>';
  916. output += gLocal.gui.timeline + "</li>";
  917. output +=
  918. "<li class = 'tip_buttom'>" +
  919. '<svg class="icon" ><use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#copy"></use></svg>';
  920. output += gLocal.gui.copy + "</li></div>";
  921. output +=
  922. "<div style='border-right: solid 1px;margin: 0.3em 0;'><li class = 'tip_buttom'>" +
  923. '<svg class="icon" ><use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#like"></use></svg>';
  924. output += gLocal.gui.like + "</li>";
  925. output +=
  926. "<li class = 'tip_buttom'>" +
  927. '<svg class="icon" ><use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#comment"></use></svg>';
  928. output += gLocal.gui.comment + "</li>";
  929. output +=
  930. "<li class = 'tip_buttom'>" +
  931. '<svg class="icon" ><use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#ic_shopping_cart"></use></svg>';
  932. output += gLocal.gui.digest + "</li></div>";
  933. output +=
  934. "<div style='margin: 0.3em 0;'><li class = 'tip_buttom'>" +
  935. '<svg class="icon" ><use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#share_to"></use></svg>';
  936. output += gLocal.gui.share_to + "</li>";
  937. output += "</div></div>";
  938. //译文工具栏结束
  939. output += "</div>";
  940. //译文工具按钮结束
  941. //译文正文开始
  942. output +=
  943. "<div class='text' id='tran_text_" +
  944. book +
  945. "_" +
  946. para +
  947. "_" +
  948. begin +
  949. "_" +
  950. end +
  951. "_" +
  952. iterator.channal +
  953. "'>";
  954. if (iterator.text == "") {
  955. output +=
  956. "<span style='color:var(--border-line-color);'>" +
  957. iterator.channalinfo.name +
  958. "-" +
  959. iterator.channalinfo.lang +
  960. "</span>";
  961. } else {
  962. //note_init处理句子链接
  963. output += note_init(term_std_str_to_tran(iterator.text, iterator.channal, iterator.editor, iterator.lang));
  964. }
  965. output += "</div>";
  966. //译文正文结束
  967. output += "</div>";
  968. //单个channal译文框结束
  969. return output;
  970. }
  971. function add_new_tran_button_click(obj) {
  972. let html = "<ul>";
  973. for (const iterator of _my_channal) {
  974. if (iterator.status > 0) {
  975. if (_channal.indexOf(iterator.id) < 0) {
  976. html += '<li onclick="';
  977. html +=
  978. "new_sentence('" +
  979. $(obj).parent().attr("book") +
  980. "' ,'" +
  981. $(obj).parent().attr("para") +
  982. "' ,'" +
  983. $(obj).parent().attr("begin") +
  984. "' ,'" +
  985. $(obj).parent().attr("end") +
  986. "' ,'" +
  987. iterator.id +
  988. "',this)";
  989. html += '">' + iterator.name;
  990. if (parseInt(iterator.power) < 20) {
  991. html += "(建议)";
  992. }
  993. html += "</li>";
  994. }
  995. }
  996. }
  997. html += "</ul>";
  998. $(obj).parent().children(".tran_text_tool_bar").first().html(html);
  999. if ($(obj).parent().children(".tran_text_tool_bar").css("display") == "block") {
  1000. $(obj).parent().children(".tran_text_tool_bar").first().hide();
  1001. } else {
  1002. $(obj).parent().children(".tran_text_tool_bar").first().show();
  1003. $(document).one("click", function () {
  1004. $(obj).parent().children(".tran_text_tool_bar").first().hide();
  1005. });
  1006. event.stopPropagation();
  1007. $(obj).parent().show();
  1008. }
  1009. }
  1010. function tool_bar_show(element) {
  1011. if ($(element).find(".tran_text_tool_bar").css("display") == "none") {
  1012. $(element).find(".tran_text_tool_bar").css("display", "flex");
  1013. $(element).find(".icon_expand").css("transform", "rotate(-180deg)");
  1014. $(element).css("background-color", "var(--btn-bg-color)");
  1015. $(element).css("visibility", "visible");
  1016. $(document).one("click", function () {
  1017. $(element).find(".tran_text_tool_bar").hide();
  1018. $(element).css("background-color", "var(--nocolor)");
  1019. $(element).find(".icon_expand").css("transform", "unset");
  1020. $(element).css("visibility", "");
  1021. });
  1022. event.stopPropagation();
  1023. } else {
  1024. $(element).find(".tran_text_tool_bar").hide();
  1025. $(element).css("background-color", "var(--nocolor)");
  1026. $(element).find(".icon_expand").css("transform", "unset");
  1027. $(element).css("visibility", "");
  1028. }
  1029. }
  1030. function new_sentence(book, para, begin, end, channel, obj) {
  1031. let newsent = { id: "", text: "", lang: "", channal: channel };
  1032. for (let iterator of _arrData) {
  1033. if (iterator.book == book && iterator.para == para && iterator.begin == begin && iterator.end == end) {
  1034. let found = false;
  1035. for (const tran of iterator.translation) {
  1036. if (tran.channal == channel) {
  1037. found = true;
  1038. break;
  1039. }
  1040. }
  1041. if (!found) {
  1042. iterator.translation.push(newsent);
  1043. }
  1044. }
  1045. }
  1046. if ($(obj).parent().parent().css("display") == "block") {
  1047. $(obj).parent().parent().hide();
  1048. }
  1049. note_edit_sentence(book, para, begin, end, channel);
  1050. }
  1051. //显示更多译文按钮动作
  1052. function set_more_button_display() {
  1053. $(".other_tran_div").each(function () {
  1054. const sentid = $(this).attr("sent").split("-");
  1055. const book = sentid[0];
  1056. const para = sentid[1];
  1057. const begin = sentid[2];
  1058. const end = sentid[3];
  1059. let count = 0;
  1060. for (const iterator of _channalData) {
  1061. if (iterator.final) {
  1062. for (const onesent of iterator.final) {
  1063. let id = onesent.id.split("-");
  1064. if (book == id[0] && para == id[1] && begin == id[2] && end == id[3] && onesent.final) {
  1065. if (_channal.indexOf(iterator.id) == -1) {
  1066. count++;
  1067. }
  1068. }
  1069. }
  1070. }
  1071. }
  1072. if (count > 0) {
  1073. $(this).find(".other_tran_num").html(count);
  1074. $(this).find(".other_tran_num").attr("style", "display:inline-flex;");
  1075. $(this)
  1076. .find(".other_bar")
  1077. .click(function () {
  1078. const sentid = $(this).parent().parent().attr("sent").split("-");
  1079. const book = sentid[0];
  1080. const para = sentid[1];
  1081. const begin = sentid[2];
  1082. const end = sentid[3];
  1083. let sentId = $(this).parent().parent().attr("sent");
  1084. if ($(this).parent().parent().siblings(".other_tran").first().css("display") == "none") {
  1085. $(".other_tran_div[sent='" + sentId + "']")
  1086. .children(".other_tran")
  1087. .slideDown();
  1088. $(this).siblings(".more_tran ").css("transform", "unset");
  1089. $.get(
  1090. "../usent/get.php",
  1091. {
  1092. book: book,
  1093. para: para,
  1094. begin: begin,
  1095. end: end,
  1096. },
  1097. function (data, status) {
  1098. let arrSent = JSON.parse(data);
  1099. let html = "<div class='compact'>";
  1100. for (const iterator of arrSent) {
  1101. if (_channal.indexOf(iterator.channal) == -1) {
  1102. html += render_one_sent_tran_a(iterator);
  1103. //html += "<div>" + marked(iterator.text) + "</div>";
  1104. }
  1105. }
  1106. html += "</div>";
  1107. let sentId =
  1108. arrSent[0].book +
  1109. "-" +
  1110. arrSent[0].paragraph +
  1111. "-" +
  1112. arrSent[0].begin +
  1113. "-" +
  1114. arrSent[0].end;
  1115. $(".other_tran_div[sent='" + sentId + "']")
  1116. .children(".other_tran")
  1117. .html(html);
  1118. }
  1119. );
  1120. } else {
  1121. $(".other_tran_div[sent='" + sentId + "']")
  1122. .children(".other_tran")
  1123. .slideUp();
  1124. $(this).siblings(".more_tran ").css("transform", "rotate(-90deg)");
  1125. }
  1126. });
  1127. } else {
  1128. //隐藏自己
  1129. //$(this).hide();
  1130. $(this).find(".other_tran_span").addClass("disable"); //gLocal.gui.no + gLocal.gui.other + gLocal.gui.translation
  1131. //$(this).find(".more_tran").hide();
  1132. }
  1133. });
  1134. }
  1135. function note_edit_sentence(book, para, begin, end, channal) {
  1136. let channalInfo;
  1137. for (const iterator of _channalData) {
  1138. if (iterator.id == channal) {
  1139. channalInfo = iterator;
  1140. break;
  1141. }
  1142. }
  1143. for (const iterator of _arrData) {
  1144. if (iterator.book == book && iterator.para == para && iterator.begin == begin && iterator.end == end) {
  1145. for (const tran of iterator.translation) {
  1146. if (tran.channal == channal) {
  1147. let html = "";
  1148. html += "<div style='color:blue;'>" + channalInfo.name + "@" + channalInfo.nickname + "</div>";
  1149. html +=
  1150. "<textarea id='edit_dialog_text' sent_id='" +
  1151. tran.id +
  1152. "' book='" +
  1153. book +
  1154. "' para='" +
  1155. para +
  1156. "' begin='" +
  1157. begin +
  1158. "' end='" +
  1159. end +
  1160. "' channal='" +
  1161. channal +
  1162. "' style='width:100%;min-height:260px;'>" +
  1163. tran.text +
  1164. "</textarea>";
  1165. $("#edit_dialog_content").html(html);
  1166. $("#note_sent_edit_dlg").dialog("open");
  1167. return;
  1168. }
  1169. }
  1170. }
  1171. }
  1172. alert("未找到句子");
  1173. }
  1174. function update_note_sent_tran(obj) {}
  1175. //保存pr句子 新
  1176. function note_pr_save(obj) {
  1177. let id = $(obj).attr("dbid");
  1178. let sid = $(obj).attr("sid").split("-");
  1179. let book = sid[0];
  1180. let para = sid[1];
  1181. let begin = sid[2];
  1182. let end = sid[3];
  1183. let channel = $(obj).attr("channel");
  1184. let text = $(obj).val();
  1185. let sent_tran_div = find_sent_tran_div(obj);
  1186. $.post(
  1187. "../usent/pr_post.php",
  1188. {
  1189. id: id,
  1190. book: book,
  1191. para: para,
  1192. begin: begin,
  1193. end: end,
  1194. channel: channel,
  1195. text: text,
  1196. },
  1197. sent_save_callback
  1198. );
  1199. if (sent_tran_div) {
  1200. $(sent_tran_div).find(".preview").addClass("loading");
  1201. }
  1202. }
  1203. //保存译文句子 新
  1204. function note_sent_save_a(obj) {
  1205. let id = $(obj).attr("dbid");
  1206. let sid = $(obj).attr("sid").split("-");
  1207. let book = sid[0];
  1208. let para = sid[1];
  1209. let begin = sid[2];
  1210. let end = sid[3];
  1211. let channal = $(obj).attr("channel");
  1212. let text = $(obj).val();
  1213. let sent_tran_div = find_sent_tran_div(obj);
  1214. $.post(
  1215. "../usent/sent_post.php",
  1216. {
  1217. id: id,
  1218. book: book,
  1219. para: para,
  1220. begin: begin,
  1221. end: end,
  1222. channal: channal,
  1223. text: text,
  1224. lang: "zh",
  1225. },
  1226. sent_save_callback
  1227. );
  1228. if (sent_tran_div) {
  1229. $(sent_tran_div).find(".preview").addClass("loading");
  1230. }
  1231. }
  1232. function sent_save_callback(data) {
  1233. let result = JSON.parse(data);
  1234. if (result.status > 0) {
  1235. alert("error" + result.message);
  1236. } else {
  1237. let sid = result.book + "-" + result.para + "-" + result.begin + "-" + result.end;
  1238. let sent_tran_div = $(
  1239. ".sent_tran[dbid='" + result.id + "'][channel='" + result.channal + "'][sid='" + sid + "']"
  1240. );
  1241. if (result.commit_type == 1 || result.commit_type == 2) {
  1242. ntf_show("成功修改");
  1243. if (sent_tran_div) {
  1244. let divPreview = sent_tran_div.find(".preview").first();
  1245. if (result.text == "") {
  1246. let channel_info = "Empty";
  1247. let thisChannel = find_channal(result.channal);
  1248. if (thisChannel) {
  1249. channel_info = thisChannel.name + "-" + thisChannel.nickname;
  1250. }
  1251. divPreview.html("<span style='color:var(--border-line-color);'>" + channel_info + "</span>");
  1252. } else {
  1253. divPreview.html(
  1254. marked(term_std_str_to_tran(result.text, result.channal, result.editor, result.lang))
  1255. );
  1256. term_updata_translation();
  1257. popup_init();
  1258. for (const iterator of _arrData) {
  1259. if (
  1260. iterator.book == result.book &&
  1261. iterator.para == result.para &&
  1262. iterator.begin == result.begin &&
  1263. iterator.end == result.end
  1264. ) {
  1265. for (const tran of iterator.translation) {
  1266. if (tran.channal == result.channal) {
  1267. tran.text = result.text;
  1268. break;
  1269. }
  1270. }
  1271. }
  1272. }
  1273. }
  1274. sent_tran_div.find(".preview").removeClass("loading");
  1275. }
  1276. } else if (result.commit_type == 3) {
  1277. ntf_show("已经提交修改建议");
  1278. } else {
  1279. ntf_show("未提交");
  1280. }
  1281. }
  1282. }
  1283. //保存译文句子
  1284. function note_sent_save() {
  1285. let id = $("#edit_dialog_text").attr("sent_id");
  1286. let book = $("#edit_dialog_text").attr("book");
  1287. let para = $("#edit_dialog_text").attr("para");
  1288. let begin = $("#edit_dialog_text").attr("begin");
  1289. let end = $("#edit_dialog_text").attr("end");
  1290. let channal = $("#edit_dialog_text").attr("channal");
  1291. let text = $("#edit_dialog_text").val();
  1292. $.post(
  1293. "../usent/sent_post.php",
  1294. {
  1295. id: id,
  1296. book: book,
  1297. para: para,
  1298. begin: begin,
  1299. end: end,
  1300. channal: channal,
  1301. text: text,
  1302. lang: "zh",
  1303. },
  1304. function (data) {
  1305. let result = JSON.parse(data);
  1306. if (result.status > 0) {
  1307. alert("error" + result.message);
  1308. } else {
  1309. if (result.commit_type == 1 || result.commit_type == 2) {
  1310. ntf_show("成功修改");
  1311. if (result.text == "") {
  1312. let channel_info = "Empty";
  1313. let thisChannel = find_channal(result.channal);
  1314. if (thisChannel) {
  1315. channel_info = thisChannel.name + "-" + thisChannel.nickname;
  1316. }
  1317. $(
  1318. "#tran_text_" +
  1319. result.book +
  1320. "_" +
  1321. result.para +
  1322. "_" +
  1323. result.begin +
  1324. "_" +
  1325. result.end +
  1326. "_" +
  1327. result.channal
  1328. ).html("<span style='color:var(--border-line-color);'>" + channel_info + "</span>");
  1329. } else {
  1330. $(
  1331. "#tran_text_" +
  1332. result.book +
  1333. "_" +
  1334. result.para +
  1335. "_" +
  1336. result.begin +
  1337. "_" +
  1338. result.end +
  1339. "_" +
  1340. result.channal
  1341. ).html(marked(term_std_str_to_tran(result.text, result.channal, result.editor, result.lang)));
  1342. term_updata_translation();
  1343. for (const iterator of _arrData) {
  1344. if (
  1345. iterator.book == result.book &&
  1346. iterator.para == result.para &&
  1347. iterator.begin == result.begin &&
  1348. iterator.end == result.end
  1349. ) {
  1350. for (const tran of iterator.translation) {
  1351. if (tran.channal == result.channal) {
  1352. tran.text = result.text;
  1353. break;
  1354. }
  1355. }
  1356. }
  1357. }
  1358. }
  1359. } else if (result.commit_type == 3) {
  1360. ntf_show("已经提交修改建议");
  1361. } else {
  1362. ntf_show("未提交");
  1363. }
  1364. }
  1365. }
  1366. );
  1367. }
  1368. function copy_ref(book, para, begin, end) {
  1369. let strRef = "{{" + book + "-" + para + "-" + begin + "-" + end + "}}";
  1370. copy_to_clipboard(strRef);
  1371. }
  1372. function goto_nissaya(book, para, begin = 0, end = 0) {
  1373. window.open("../nissaya/index.php?book=" + book + "&para=" + para + "&begin=" + begin + "&end=" + end, "nissaya");
  1374. }
  1375. function edit_in_studio(book, para, begin, end) {
  1376. wbw_channal_list_open(book, [para]);
  1377. }
  1378. //显示和隐藏某个内容 如 巴利文
  1379. function setVisibility(key, value) {
  1380. switch (key) {
  1381. case "palitext":
  1382. if ($(value).is(":checked")) {
  1383. $(".palitext").show();
  1384. } else {
  1385. $(".palitext").hide();
  1386. }
  1387. break;
  1388. default:
  1389. break;
  1390. }
  1391. }
  1392. function note_show_pali_sim(SentId) {
  1393. pali_sim_dlg_open(SentId, 0, 20);
  1394. }
  1395. function set_pali_script(pos, script) {
  1396. if (script == "none") {
  1397. $(".palitext" + pos).html("");
  1398. } else {
  1399. $(".palitext" + pos).each(function () {
  1400. let html = $(this).siblings(".palitext_roma").first().html();
  1401. $(this).html(html);
  1402. });
  1403. $(".palitext" + pos)
  1404. .find("*")
  1405. .contents()
  1406. .filter(function () {
  1407. return this.nodeType != 1;
  1408. })
  1409. .wrap("<pl" + pos + "></pl" + pos + ">");
  1410. $(".palitext" + pos)
  1411. .contents()
  1412. .filter(function () {
  1413. return this.nodeType != 1;
  1414. })
  1415. .wrap("<pl" + pos + "></pl" + pos + ">");
  1416. $("pl" + pos).html(function (index, oldcontent) {
  1417. return roman_to_my(oldcontent);
  1418. });
  1419. }
  1420. }
  1421. function splite_pali_word() {
  1422. $("pali")
  1423. .contents()
  1424. .filter(function () {
  1425. return this.nodeType != 1;
  1426. })
  1427. .wrap("<pl></pl>");
  1428. $("pl").each(function () {
  1429. let html = $(this).html();
  1430. $(this).html("<w>" + html.replace(/\s/g, "</w> <w>") + "</w>");
  1431. });
  1432. $("w").click(function () {
  1433. let word = com_getPaliReal($(this).text());
  1434. if (gBuildinDictIsOpen) {
  1435. window.open("../dict/index.php?builtin=true&key=" + word, "dict");
  1436. }
  1437. });
  1438. }
  1439. function refresh_pali_script() {
  1440. if (_display && _display == "para") {
  1441. //段落模式
  1442. } else {
  1443. //句子模式
  1444. setting_get("lib.second_script", set_second_scrip);
  1445. }
  1446. }
  1447. function set_second_scrip(value) {
  1448. set_pali_script(2, value);
  1449. }
  1450. function slider_show(obj) {
  1451. $(obj).parent().parent().parent().parent().parent().toggleClass("slider_show_shell");
  1452. }
  1453. function find_sent_tran_div(obj) {
  1454. let parent = obj.parentNode;
  1455. while (parent.nodeType == 1) {
  1456. if ($(parent).hasClass("sent_tran")) {
  1457. return parent;
  1458. } else if (parent.nodeName == "BODY") {
  1459. return false;
  1460. }
  1461. parent = parent.parentNode;
  1462. }
  1463. return false;
  1464. }
  1465. //显示或隐藏pr数据
  1466. function note_pr_show(channel, id) {
  1467. let obj = $(".sent_tran[channel='" + channel + "'][sid='" + id + "']").find(".pr_content");
  1468. let prHtml = obj.first().html();
  1469. if (prHtml == "") {
  1470. note_get_pr(channel, id);
  1471. } else {
  1472. obj.slideUp();
  1473. obj.html("");
  1474. }
  1475. }
  1476. //获取pr数据并显示
  1477. function note_get_pr(channel, id) {
  1478. let sid = id.split("-");
  1479. let book = sid[0];
  1480. let para = sid[1];
  1481. let begin = sid[2];
  1482. let end = sid[3];
  1483. $.post(
  1484. "../usent/get_pr.php",
  1485. {
  1486. book: book,
  1487. para: para,
  1488. begin: begin,
  1489. end: end,
  1490. channel: channel,
  1491. },
  1492. function (data) {
  1493. let result = JSON.parse(data);
  1494. if (result.length > 0) {
  1495. let html = "<div class='compact'>";
  1496. for (const iterator of result) {
  1497. html += render_one_sent_tran_a(iterator);
  1498. }
  1499. html += "</div>";
  1500. $(".sent_tran[channel='" + channel + "'][sid='" + id + "']")
  1501. .find(".pr_content")
  1502. .html(html);
  1503. $(".sent_tran[channel='" + channel + "'][sid='" + id + "']")
  1504. .find(".pr_content")
  1505. .slideDown();
  1506. } else {
  1507. }
  1508. }
  1509. );
  1510. $(".sent_tran[channel='" + channel + "'][sid='" + id + "']")
  1511. .find(".pr_content")
  1512. .html("loading");
  1513. $(".sent_tran[channel='" + channel + "'][sid='" + id + "']")
  1514. .find(".pr_content")
  1515. .show();
  1516. }
  1517. function get_channel_by_id(id) {
  1518. if (typeof _channalData != "undefined") {
  1519. for (const iterator of _channalData) {
  1520. if (iterator.id == id) {
  1521. return iterator;
  1522. }
  1523. }
  1524. }
  1525. if (typeof _my_channal != "undefined") {
  1526. for (const iterator of _my_channal) {
  1527. if (iterator.id == id) {
  1528. return iterator;
  1529. }
  1530. }
  1531. }
  1532. return false;
  1533. }