note.js 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770
  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. "'>🧲" +
  574. gLocal.gui.translation +
  575. "</span>";
  576. output += "<span class='other_tran_num'></span>";
  577. output += "</span>";
  578. output += "<span class='separate_line'></span>";
  579. //手工义注
  580. output += "<span class='other_bar' >";
  581. output +=
  582. "<span class='other_tran_span commentray' title='📔" +
  583. gLocal.gui.vannana +
  584. "'>🪔" +
  585. gLocal.gui.commentary +
  586. "</span>";
  587. output += "<span class='other_tran_num'></span>";
  588. output += "</span>";
  589. output += "<span class='separate_line'></span>";
  590. //第三个按钮 相似句
  591. if (parseInt(in_json.sim) > 0) {
  592. output += "<span class='other_bar' >";
  593. output +=
  594. "<span class='similar_sent_span' onclick=\"note_show_pali_sim('" +
  595. in_json.pali_sent_id +
  596. "')\" title='" +
  597. gLocal.gui.similar_sentences +
  598. "'>🧬" +
  599. gLocal.gui.similar +
  600. "</span>";
  601. output += "<span class='similar_sent_num'>" + in_json.sim + "</span>";
  602. output += "</span>";
  603. output += "<span class='separate_line'></span>";
  604. }
  605. //第三个按钮 相似句结束
  606. output += "</span>";
  607. output += "<span class='tool_right'>";
  608. //出处路径开始
  609. output += "<span class='ref'>";
  610. output += "<span class='book_name tooltip'>" + in_json.booktitle;
  611. output += "<span class='tooltiptext tooltip-bottom'>";
  612. output += in_json.ref;
  613. output += "</span>";
  614. output += "<span class='sent_no'>";
  615. output += in_json.book + "-" + in_json.para + "-" + in_json.begin + "-" + in_json.end;
  616. output += "<span>";
  617. output += "</span>";
  618. output += "</span>";
  619. //出处路径结束
  620. output += "</span>";
  621. output += "</div>";
  622. //工具栏结束
  623. //未选择的其他译文开始
  624. output += "<div class='other_tran'>";
  625. output += "</div>";
  626. output += "</div>";
  627. return output;
  628. }
  629. //设置取消输入框的编辑模式
  630. function sent_tran_set_edit_mode(obj, isEditMode) {
  631. $(".sent_tran").removeClass("edit_mode");
  632. if (isEditMode) {
  633. let jqObj = $(obj);
  634. while (!jqObj.hasClass("sent_tran")) {
  635. jqObj = jqObj.parent();
  636. if (!jqObj) {
  637. return;
  638. }
  639. }
  640. jqObj.addClass("edit_mode");
  641. }
  642. }
  643. function sent_tran_edit(obj) {
  644. let jqObj = $(obj);
  645. while (!jqObj.hasClass("sent_tran")) {
  646. jqObj = jqObj.parent();
  647. if (!jqObj) {
  648. return;
  649. }
  650. }
  651. if (jqObj.hasClass("edit_mode")) {
  652. jqObj.removeClass("edit_mode");
  653. } else {
  654. $(".sent_tran").removeClass("edit_mode");
  655. jqObj.addClass("edit_mode");
  656. }
  657. }
  658. function sent_pr_merge(id) {
  659. $.post(
  660. "../usent/sent_pr_merge.php",
  661. {
  662. id: id,
  663. },
  664. function (data) {
  665. let result = JSON.parse(data);
  666. if (result.status > 0) {
  667. alert("error" + result.message);
  668. } else {
  669. ntf_show("成功采纳");
  670. }
  671. }
  672. );
  673. }
  674. function sent_commit(src, id) {
  675. commit_init({
  676. src: src,
  677. sent: [id],
  678. express: true,
  679. });
  680. }
  681. function render_one_sent_tran_a(iterator) {
  682. let mChannel = get_channel_by_id(iterator.channal);
  683. let tranText;
  684. let sid = iterator.book + "-" + iterator.para + "-" + iterator.begin + "-" + iterator.end;
  685. if (iterator.text == "") {
  686. if (typeof iterator.channalinfo == "undefined") {
  687. tranText =
  688. "<span style='color:var(--border-line-color);'>" +
  689. "空" +
  690. "@" +
  691. iterator.editor_name.nickname +
  692. "</span>";
  693. } else {
  694. tranText =
  695. "<span style='color:var(--border-line-color);'>" +
  696. iterator.channalinfo.name +
  697. "-" +
  698. iterator.channalinfo.lang +
  699. "</span>";
  700. }
  701. } else {
  702. //note_init处理句子链接
  703. tranText = note_init(term_std_str_to_tran(iterator.text, iterator.channal, iterator.editor, iterator.lang));
  704. }
  705. let html = "";
  706. html += "<div class='sent_tran ";
  707. if (typeof iterator.is_pr != "undefined" && iterator.is_pr == true) {
  708. html += " pr ";
  709. }
  710. html += "' dbid='" + iterator.id + "' channel='" + iterator.channal + "' sid='" + sid + "'>";
  711. html += "<div class='sent_tran_inner'>";
  712. html += '<div class="tool_bar">';
  713. html += ' <div class="right">';
  714. //句子菜单
  715. html += '<div class="pop_menu">';
  716. if (typeof iterator.is_pr != "undefined" && iterator.is_pr == true) {
  717. //在pr 列表中的译文
  718. if (typeof iterator.is_pr_editor != "undefined" && iterator.is_pr_editor == true) {
  719. //提交人
  720. //修改按钮
  721. html += "<button class='icon_btn tooltip' onclick='sent_tran_edit(this)'>";
  722. html += '<svg class="icon" >';
  723. html += '<use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#ic_mode_edit"></use>';
  724. html += "</svg>";
  725. html += "<span class='tooltiptext tooltip-top'>";
  726. html += gLocal.gui.modify;
  727. html += "</span>";
  728. html += "</button>";
  729. //删除按钮
  730. html += "<button class='icon_btn tooltip' onclick='sent_pr_del(this)'>";
  731. html += '<svg class="icon" >';
  732. html += '<use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#ic_delete"></use>';
  733. html += "</svg>";
  734. html += "<span class='tooltiptext tooltip-top'>";
  735. html += gLocal.gui.delete;
  736. html += "</span>";
  737. html += "</button>";
  738. } else {
  739. //非提交人
  740. if (parseInt(iterator.mypower) >= 20) {
  741. //有权限 采纳按钮
  742. html += "<button class='icon_btn tooltip' onclick=\"sent_pr_merge('" + iterator.id + "')\">";
  743. html += '<svg class="icon" >';
  744. html += '<use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#accept_copy"></use>';
  745. html += "</svg>";
  746. html += "<span class='tooltiptext tooltip-top'>";
  747. html += gLocal.gui.accept_copy;
  748. html += "</span>";
  749. html += "</button>";
  750. }
  751. //点赞按钮
  752. html += "<button class='icon_btn tooltip' onclick='sent_pr_like(this)'>";
  753. html += '<svg class="icon" >';
  754. html += '<use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#like"></use>';
  755. html += "</svg>";
  756. html += "<span class='tooltiptext tooltip-top'>";
  757. html += gLocal.gui.like;
  758. html += "</span>";
  759. html += "</button>";
  760. }
  761. } else {
  762. //非pr列表里的句子
  763. //编辑按钮
  764. html += "<button class='icon_btn tooltip' onclick='sent_tran_edit(this)'>";
  765. html += '<svg class="icon" >';
  766. if (parseInt(iterator.mypower) < 20) {
  767. html += '<use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#my_idea"></use>';
  768. } else {
  769. html += '<use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#ic_mode_edit"></use>';
  770. }
  771. html += "</svg>";
  772. html += "<span class='tooltiptext tooltip-top'>";
  773. if (parseInt(iterator.mypower) < 20) {
  774. html += "建议";
  775. } else {
  776. html += gLocal.gui.edit;
  777. }
  778. html += "</span>";
  779. html += "</button>";
  780. //推送按钮
  781. let commitIcon = "";
  782. let commitTipText = "";
  783. if (parseInt(iterator.mypower) >= 30 && parseInt(iterator.status) < 30) {
  784. //我的私有资源 公开发布
  785. commitIcon = "publish";
  786. commitTipText = gLocal.gui.publish;
  787. } else {
  788. if (parseInt(iterator.mypower) < 20) {
  789. //只读资源 采纳
  790. commitIcon = "accept_copy";
  791. commitTipText = gLocal.gui.accept_copy;
  792. } else {
  793. //其他资源 复制到
  794. commitIcon = "copy";
  795. commitTipText = gLocal.gui.copy_to;
  796. }
  797. }
  798. html += "<button class='icon_btn tooltip' ";
  799. html += " onclick=\"sent_commit('" + iterator.channal + "','" + sid + "')\">";
  800. html += '<svg class="icon" >';
  801. html += '<use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#' + commitIcon + '"></use>';
  802. html += "</svg>";
  803. html += "<span class='tooltiptext tooltip-top'>";
  804. html += commitTipText;
  805. html += "</span>";
  806. html += "</button>";
  807. //推送按钮结束
  808. //更多按钮
  809. html += '<div class="case_dropdown">';
  810. html += "<button class='icon_btn'>";
  811. html += '<svg class="icon" >';
  812. html += '<use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#ic_more"></use>';
  813. html += "</svg>";
  814. html += "</button>";
  815. html += '<div class="case_dropdown-content menu_space_between" style="right:0;">';
  816. //时间线
  817. html += "<a onclick=\"history_show('" + iterator.id + "')\">";
  818. html += "<span>" + gLocal.gui.timeline + "</span>";
  819. html += '<svg class="icon" >';
  820. html += '<use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#recent_scan"></use>';
  821. html += "</svg>";
  822. html += "</a>";
  823. //复制
  824. html += "<a onclick=\"history_show('" + iterator.id + "')\">";
  825. html += "<span>" + gLocal.gui.copy + "</span>";
  826. html += '<svg class="icon" >';
  827. html += '<use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#copy"></use>';
  828. html += "</svg>";
  829. html += "</a>";
  830. //点赞
  831. html += "<a onclick=\"history_show('" + iterator.id + "')\">";
  832. html += "<span>" + gLocal.gui.like + "</span>";
  833. html += '<svg class="icon" >';
  834. html += '<use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#like"></use>';
  835. html += "</svg>";
  836. html += "</a>";
  837. //分享
  838. html += "<a onclick=\"history_show('" + iterator.id + "')\">";
  839. html += "<span>" + gLocal.gui.share_to + "</span>";
  840. html += '<svg class="icon" >';
  841. html += '<use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#share_to"></use>';
  842. html += "</svg>";
  843. html += "</a>";
  844. html += "</div>";
  845. html += "</div>";
  846. //更多按钮结束
  847. }
  848. html += "</div>";
  849. //句子菜单结束
  850. html += "</div>";
  851. html += "</div>";
  852. //tool_bar 结束
  853. html += '<div class="left_bar" >';
  854. html += ' <div class="face">';
  855. if (iterator.id != "") {
  856. html += '<span class="head_img">' + iterator.editor_name.nickname.slice(0, 1) + "</span>";
  857. }
  858. html += "</div>";
  859. html +=
  860. '<div class="date" title="' +
  861. getFullDataTime(iterator.update_time) +
  862. '">' +
  863. getDataTime(iterator.update_time) +
  864. "</div>";
  865. html += "</div>";
  866. html += '<div class="body">';
  867. html += '<div class="head_bar">';
  868. html += '<div class="info">';
  869. html += '<span class="name">' + iterator.editor_name.nickname + "</span>";
  870. html += '<span class="date">' + getPassDataTime(iterator.update_time) + "</span>";
  871. html += "</div>";
  872. html += "<div class='preview'>" + tranText + "</div>";
  873. html += "</div>";
  874. html += '<div class="edit">';
  875. html += '<div class="input">';
  876. html += "<textarea class='tran_sent_textarea' dbid='" + iterator.id + "' ";
  877. html += "sid='" + sid + "' ";
  878. html += "channel='" + iterator.channal + "' ";
  879. if (typeof iterator.is_pr != "undefined" && iterator.is_pr == true) {
  880. html += ' is_pr="true" onchange1="note_pr_save(this)"';
  881. } else {
  882. html += 'is_pr="false" onchange1="note_sent_save_a(this)"';
  883. }
  884. html += ">" + iterator.text + "</textarea>";
  885. html += "</div>";
  886. html += '<div class="edit_tool">';
  887. if (parseInt(iterator.mypower) < 20) {
  888. html += "提交<b>修改建议</b> ";
  889. }
  890. html +=
  891. "按Esc <a onclick='tran_sent_edit_cancel(this)'>取消</a> 按按shift+回车<a onclick='tran_sent_save(this)'>" +
  892. gLocal.gui.save +
  893. "</a> 支持markdown语法";
  894. html += "</div>";
  895. html += "</div>";
  896. html += '<div class="foot_bar">';
  897. html += '<div class="info">';
  898. if (iterator.id != "") {
  899. html += '<span class="date"> ' + getPassDataTime(iterator.update_time) + "</span>";
  900. }
  901. if (iterator.id != "") {
  902. html += '<span class="name">' + iterator.editor_name.nickname + "</span>";
  903. }
  904. if (iterator.id != "") {
  905. html += '<span class="channel">' + gLocal.gui.updated + " @";
  906. if (typeof iterator.channalinfo == "undefined") {
  907. html += "unkown";
  908. } else {
  909. html += iterator.channalinfo.name;
  910. }
  911. html += "</span>";
  912. } else {
  913. html += '<span class="channel">' + gLocal.gui.no_updated + " @";
  914. if (typeof iterator.channalinfo == "undefined") {
  915. html += "unkown";
  916. } else {
  917. html += iterator.channalinfo.name;
  918. }
  919. html += "</span>";
  920. }
  921. html += '<ul class="tag_list">';
  922. if (iterator.pr_all && parseInt(iterator.pr_all) > 0) {
  923. html +=
  924. " <li onclick=\"note_pr_show('" +
  925. iterator.channal +
  926. "','" +
  927. sid +
  928. "')\"><span class='icon'>✋</span><span class='num'>" +
  929. iterator.pr_new +
  930. "/" +
  931. iterator.pr_all +
  932. "</span></li>";
  933. }
  934. html += "</ul>";
  935. html += "</div>"; //end of info
  936. html += "</div>"; //end of foot bar
  937. html += "</div>";
  938. html += "</div>";
  939. //sent_tran_inner结束
  940. html += '<div class="pr_content"></div>';
  941. html += "</div>";
  942. return html;
  943. }
  944. function tran_sent_textarea_event_init() {
  945. let textarea = document.querySelectorAll(".tran_sent_textarea");
  946. for (let iterator of textarea) {
  947. iterator.onkeydown = function (e) {
  948. let menu = document.querySelector("#menu");
  949. switch (e.key) {
  950. case "Enter":
  951. if (menu && menu.style.display == "block") {
  952. let value = textarea.value;
  953. let selectionStart = textarea.selectionStart;
  954. let str1 = value.slice(0, selectionStart);
  955. let str2 = value.slice(selectionStart);
  956. textarea.value = str1 + data[menuFocusIndex] + "]]" + str2;
  957. menu.style.display = "none";
  958. return false;
  959. } else {
  960. if (e.shiftKey) {
  961. //回车存盘
  962. tran_sent_save(e.currentTarget);
  963. return false;
  964. }
  965. }
  966. break;
  967. case "Escape":
  968. tran_sent_edit_cancel(e.currentTarget);
  969. break;
  970. default:
  971. break;
  972. }
  973. };
  974. }
  975. }
  976. function render_one_sent_tran(book, para, begin, end, iterator) {
  977. let output = "";
  978. output += "<div class='tran' lang='" + iterator.lang + "' style='display:flex;'>";
  979. //译文工具按钮开始
  980. output += "<div class='tran_text_tool_botton' onclick='tool_bar_show(this)'>";
  981. output +=
  982. "<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>";
  983. //译文工具栏开始
  984. output += "<div class='tran_text_tool_bar'>";
  985. output += "<div style='border-right: solid 1px;margin: 0.3em 0;'><li class = 'tip_buttom' ";
  986. output +=
  987. " onclick=\"note_edit_sentence('" +
  988. book +
  989. "' ,'" +
  990. para +
  991. "' ,'" +
  992. begin +
  993. "' ,'" +
  994. end +
  995. "' ,'" +
  996. iterator.channal +
  997. "')\"";
  998. output +=
  999. ">" +
  1000. '<svg class="icon" ><use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#ic_mode_edit"></use></svg>';
  1001. output += gLocal.gui.edit + "</li>";
  1002. output += "<li class = 'tip_buttom' ";
  1003. output += " onclick=\"history_show('" + iterator.id + "')\" >";
  1004. output +=
  1005. '<svg class="icon" ><use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#recent_scan"></use></svg>';
  1006. output += gLocal.gui.timeline + "</li>";
  1007. output +=
  1008. "<li class = 'tip_buttom'>" +
  1009. '<svg class="icon" ><use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#copy"></use></svg>';
  1010. output += gLocal.gui.copy + "</li></div>";
  1011. output +=
  1012. "<div style='border-right: solid 1px;margin: 0.3em 0;'><li class = 'tip_buttom'>" +
  1013. '<svg class="icon" ><use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#like"></use></svg>';
  1014. output += gLocal.gui.like + "</li>";
  1015. output +=
  1016. "<li class = 'tip_buttom'>" +
  1017. '<svg class="icon" ><use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#comment"></use></svg>';
  1018. output += gLocal.gui.comment + "</li>";
  1019. output +=
  1020. "<li class = 'tip_buttom'>" +
  1021. '<svg class="icon" ><use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#ic_shopping_cart"></use></svg>';
  1022. output += gLocal.gui.digest + "</li></div>";
  1023. output +=
  1024. "<div style='margin: 0.3em 0;'><li class = 'tip_buttom'>" +
  1025. '<svg class="icon" ><use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#share_to"></use></svg>';
  1026. output += gLocal.gui.share_to + "</li>";
  1027. output += "</div></div>";
  1028. //译文工具栏结束
  1029. output += "</div>";
  1030. //译文工具按钮结束
  1031. //译文正文开始
  1032. output +=
  1033. "<div class='text' id='tran_text_" +
  1034. book +
  1035. "_" +
  1036. para +
  1037. "_" +
  1038. begin +
  1039. "_" +
  1040. end +
  1041. "_" +
  1042. iterator.channal +
  1043. "'>";
  1044. if (iterator.text == "") {
  1045. output +=
  1046. "<span style='color:var(--border-line-color);'>" +
  1047. iterator.channalinfo.name +
  1048. "-" +
  1049. iterator.channalinfo.lang +
  1050. "</span>";
  1051. } else {
  1052. //note_init处理句子链接
  1053. output += note_init(term_std_str_to_tran(iterator.text, iterator.channal, iterator.editor, iterator.lang));
  1054. }
  1055. output += "</div>";
  1056. //译文正文结束
  1057. output += "</div>";
  1058. //单个channal译文框结束
  1059. return output;
  1060. }
  1061. function add_new_tran_button_click(obj) {
  1062. let html = "<ul>";
  1063. for (const iterator of _my_channal) {
  1064. if (iterator.status > 0) {
  1065. if (_channal.indexOf(iterator.id) < 0) {
  1066. html += '<li onclick="';
  1067. html +=
  1068. "new_sentence('" +
  1069. $(obj).parent().attr("book") +
  1070. "' ,'" +
  1071. $(obj).parent().attr("para") +
  1072. "' ,'" +
  1073. $(obj).parent().attr("begin") +
  1074. "' ,'" +
  1075. $(obj).parent().attr("end") +
  1076. "' ,'" +
  1077. iterator.id +
  1078. "',this)";
  1079. html += '">' + iterator.name;
  1080. if (parseInt(iterator.power) < 20) {
  1081. html += "(建议)";
  1082. }
  1083. html += "</li>";
  1084. }
  1085. }
  1086. }
  1087. html += "</ul>";
  1088. $(obj).parent().children(".tran_text_tool_bar").first().html(html);
  1089. if ($(obj).parent().children(".tran_text_tool_bar").css("display") == "block") {
  1090. $(obj).parent().children(".tran_text_tool_bar").first().hide();
  1091. } else {
  1092. $(obj).parent().children(".tran_text_tool_bar").first().show();
  1093. $(document).one("click", function () {
  1094. $(obj).parent().children(".tran_text_tool_bar").first().hide();
  1095. });
  1096. event.stopPropagation();
  1097. $(obj).parent().show();
  1098. }
  1099. }
  1100. function tool_bar_show(element) {
  1101. if ($(element).find(".tran_text_tool_bar").css("display") == "none") {
  1102. $(element).find(".tran_text_tool_bar").css("display", "flex");
  1103. $(element).find(".icon_expand").css("transform", "rotate(-180deg)");
  1104. $(element).css("background-color", "var(--btn-bg-color)");
  1105. $(element).css("visibility", "visible");
  1106. $(document).one("click", function () {
  1107. $(element).find(".tran_text_tool_bar").hide();
  1108. $(element).css("background-color", "var(--nocolor)");
  1109. $(element).find(".icon_expand").css("transform", "unset");
  1110. $(element).css("visibility", "");
  1111. });
  1112. event.stopPropagation();
  1113. } else {
  1114. $(element).find(".tran_text_tool_bar").hide();
  1115. $(element).css("background-color", "var(--nocolor)");
  1116. $(element).find(".icon_expand").css("transform", "unset");
  1117. $(element).css("visibility", "");
  1118. }
  1119. }
  1120. function new_sentence(book, para, begin, end, channel, obj) {
  1121. let newsent = { id: "", text: "", lang: "", channal: channel };
  1122. for (let iterator of _arrData) {
  1123. if (iterator.book == book && iterator.para == para && iterator.begin == begin && iterator.end == end) {
  1124. let found = false;
  1125. for (const tran of iterator.translation) {
  1126. if (tran.channal == channel) {
  1127. found = true;
  1128. break;
  1129. }
  1130. }
  1131. if (!found) {
  1132. iterator.translation.push(newsent);
  1133. }
  1134. }
  1135. }
  1136. if ($(obj).parent().parent().css("display") == "block") {
  1137. $(obj).parent().parent().hide();
  1138. }
  1139. note_edit_sentence(book, para, begin, end, channel);
  1140. }
  1141. //显示更多译文按钮动作
  1142. function set_more_button_display() {
  1143. $(".other_tran_div").each(function () {
  1144. const sentid = $(this).attr("sent").split("-");
  1145. const book = sentid[0];
  1146. const para = sentid[1];
  1147. const begin = sentid[2];
  1148. const end = sentid[3];
  1149. let count = 0;
  1150. for (const iterator of _channalData) {
  1151. if (iterator.final) {
  1152. for (const onesent of iterator.final) {
  1153. let id = onesent.id.split("-");
  1154. if (book == id[0] && para == id[1] && begin == id[2] && end == id[3] && onesent.final) {
  1155. if (_channal.indexOf(iterator.id) == -1) {
  1156. count++;
  1157. }
  1158. }
  1159. }
  1160. }
  1161. }
  1162. if (count > 0) {
  1163. $(this).find(".other_tran_num").html(count);
  1164. $(this).find(".other_tran_num").attr("style", "display:inline-flex;");
  1165. $(this)
  1166. .find(".other_bar")
  1167. .click(function () {
  1168. const sentid = $(this).parent().parent().attr("sent").split("-");
  1169. const book = sentid[0];
  1170. const para = sentid[1];
  1171. const begin = sentid[2];
  1172. const end = sentid[3];
  1173. let sentId = $(this).parent().parent().attr("sent");
  1174. if ($(this).parent().parent().siblings(".other_tran").first().css("display") == "none") {
  1175. $(".other_tran_div[sent='" + sentId + "']")
  1176. .children(".other_tran")
  1177. .slideDown();
  1178. $(this).siblings(".more_tran ").css("transform", "unset");
  1179. $.get(
  1180. "../usent/get.php",
  1181. {
  1182. book: book,
  1183. para: para,
  1184. begin: begin,
  1185. end: end,
  1186. },
  1187. function (data, status) {
  1188. let arrSent = JSON.parse(data);
  1189. let html = "<div class='compact'>";
  1190. for (const iterator of arrSent) {
  1191. if (_channal.indexOf(iterator.channal) == -1) {
  1192. html += render_one_sent_tran_a(iterator);
  1193. }
  1194. }
  1195. html += "</div>";
  1196. let sentId =
  1197. arrSent[0].book +
  1198. "-" +
  1199. arrSent[0].paragraph +
  1200. "-" +
  1201. arrSent[0].begin +
  1202. "-" +
  1203. arrSent[0].end;
  1204. $(".other_tran_div[sent='" + sentId + "']")
  1205. .children(".other_tran")
  1206. .html(html);
  1207. }
  1208. );
  1209. } else {
  1210. $(".other_tran_div[sent='" + sentId + "']")
  1211. .children(".other_tran")
  1212. .slideUp();
  1213. $(this).siblings(".more_tran ").css("transform", "rotate(-90deg)");
  1214. }
  1215. });
  1216. } else {
  1217. //隐藏自己
  1218. //$(this).hide();
  1219. $(this).find(".other_tran_span").addClass("disable"); //gLocal.gui.no + gLocal.gui.other + gLocal.gui.translation
  1220. //$(this).find(".more_tran").hide();
  1221. }
  1222. });
  1223. }
  1224. function note_edit_sentence(book, para, begin, end, channal) {
  1225. let channalInfo;
  1226. for (const iterator of _channalData) {
  1227. if (iterator.id == channal) {
  1228. channalInfo = iterator;
  1229. break;
  1230. }
  1231. }
  1232. for (const iterator of _arrData) {
  1233. if (iterator.book == book && iterator.para == para && iterator.begin == begin && iterator.end == end) {
  1234. for (const tran of iterator.translation) {
  1235. if (tran.channal == channal) {
  1236. let html = "";
  1237. html += "<div style='color:blue;'>" + channalInfo.name + "@" + channalInfo.nickname + "</div>";
  1238. html +=
  1239. "<textarea id='edit_dialog_text' sent_id='" +
  1240. tran.id +
  1241. "' book='" +
  1242. book +
  1243. "' para='" +
  1244. para +
  1245. "' begin='" +
  1246. begin +
  1247. "' end='" +
  1248. end +
  1249. "' channal='" +
  1250. channal +
  1251. "' style='width:100%;min-height:260px;'>" +
  1252. tran.text +
  1253. "</textarea>";
  1254. $("#edit_dialog_content").html(html);
  1255. $("#note_sent_edit_dlg").dialog("open");
  1256. return;
  1257. }
  1258. }
  1259. }
  1260. }
  1261. alert("未找到句子");
  1262. }
  1263. function tran_sent_edit_cancel(obj) {
  1264. sent_tran_set_edit_mode(obj, false);
  1265. }
  1266. function tran_sent_save(obj) {
  1267. let sentDiv = find_sent_tran_div(obj);
  1268. if (sentDiv) {
  1269. let textarea = $(sentDiv).children().find(".tran_sent_textarea").first();
  1270. let isPr = $(textarea).attr("is_pr");
  1271. if (isPr == "true") {
  1272. note_pr_save(textarea);
  1273. } else {
  1274. note_sent_save_a(textarea);
  1275. }
  1276. sent_tran_set_edit_mode(textarea, false);
  1277. } else {
  1278. console.error("sent div not found");
  1279. }
  1280. }
  1281. //保存pr句子 新
  1282. function note_pr_save(obj) {
  1283. let id = $(obj).attr("dbid");
  1284. let sid = $(obj).attr("sid").split("-");
  1285. let book = sid[0];
  1286. let para = sid[1];
  1287. let begin = sid[2];
  1288. let end = sid[3];
  1289. let channel = $(obj).attr("channel");
  1290. let text = $(obj).val();
  1291. let sent_tran_div = find_sent_tran_div(obj);
  1292. $.post(
  1293. "../usent/pr_post.php",
  1294. {
  1295. id: id,
  1296. book: book,
  1297. para: para,
  1298. begin: begin,
  1299. end: end,
  1300. channel: channel,
  1301. text: text,
  1302. },
  1303. sent_save_callback
  1304. );
  1305. if (sent_tran_div) {
  1306. $(sent_tran_div).find(".preview").addClass("loading");
  1307. }
  1308. }
  1309. //保存译文句子 新
  1310. function note_sent_save_a(obj) {
  1311. let id = $(obj).attr("dbid");
  1312. let sid = $(obj).attr("sid").split("-");
  1313. let book = sid[0];
  1314. let para = sid[1];
  1315. let begin = sid[2];
  1316. let end = sid[3];
  1317. let channal = $(obj).attr("channel");
  1318. let text = $(obj).val();
  1319. let sent_tran_div = find_sent_tran_div(obj);
  1320. $.post(
  1321. "../usent/sent_post.php",
  1322. {
  1323. id: id,
  1324. book: book,
  1325. para: para,
  1326. begin: begin,
  1327. end: end,
  1328. channal: channal,
  1329. text: text,
  1330. lang: "zh",
  1331. },
  1332. sent_save_callback
  1333. );
  1334. if (sent_tran_div) {
  1335. $(sent_tran_div).find(".preview").addClass("loading");
  1336. }
  1337. }
  1338. function update_sent_tran(sentData) {}
  1339. function sent_save_callback(data) {
  1340. let result = JSON.parse(data);
  1341. if (result.status > 0) {
  1342. alert("error" + result.message);
  1343. } else {
  1344. let sid = result.book + "-" + result.para + "-" + result.begin + "-" + result.end;
  1345. let sent_tran_div = $(
  1346. ".sent_tran[dbid='" + result.id + "'][channel='" + result.channal + "'][sid='" + sid + "']"
  1347. );
  1348. if (result.commit_type == 1 || result.commit_type == 2) {
  1349. ntf_show("成功修改");
  1350. if (sent_tran_div) {
  1351. let divPreview = sent_tran_div.find(".preview").first();
  1352. if (result.text == "") {
  1353. let channel_info = "Empty";
  1354. let thisChannel = find_channal(result.channal);
  1355. if (thisChannel) {
  1356. channel_info = thisChannel.name + "-" + thisChannel.nickname;
  1357. }
  1358. divPreview.html("<span style='color:var(--border-line-color);'>" + channel_info + "</span>");
  1359. } else {
  1360. divPreview.html(
  1361. marked(term_std_str_to_tran(result.text, result.channal, result.editor, result.lang))
  1362. );
  1363. term_updata_translation();
  1364. popup_init();
  1365. for (const iterator of _arrData) {
  1366. if (
  1367. iterator.book == result.book &&
  1368. iterator.para == result.para &&
  1369. iterator.begin == result.begin &&
  1370. iterator.end == result.end
  1371. ) {
  1372. for (const tran of iterator.translation) {
  1373. if (tran.channal == result.channal) {
  1374. tran.text = result.text;
  1375. break;
  1376. }
  1377. }
  1378. }
  1379. }
  1380. }
  1381. sent_tran_div.find(".preview").removeClass("loading");
  1382. }
  1383. } else if (result.commit_type == 3) {
  1384. ntf_show("已经提交修改建议");
  1385. } else {
  1386. ntf_show("未提交");
  1387. }
  1388. }
  1389. }
  1390. //保存译文句子
  1391. function note_sent_save() {
  1392. let id = $("#edit_dialog_text").attr("sent_id");
  1393. let book = $("#edit_dialog_text").attr("book");
  1394. let para = $("#edit_dialog_text").attr("para");
  1395. let begin = $("#edit_dialog_text").attr("begin");
  1396. let end = $("#edit_dialog_text").attr("end");
  1397. let channal = $("#edit_dialog_text").attr("channal");
  1398. let text = $("#edit_dialog_text").val();
  1399. $.post(
  1400. "../usent/sent_post.php",
  1401. {
  1402. id: id,
  1403. book: book,
  1404. para: para,
  1405. begin: begin,
  1406. end: end,
  1407. channal: channal,
  1408. text: text,
  1409. lang: "zh",
  1410. },
  1411. function (data) {
  1412. let result = JSON.parse(data);
  1413. if (result.status > 0) {
  1414. alert("error" + result.message);
  1415. } else {
  1416. if (result.commit_type == 1 || result.commit_type == 2) {
  1417. ntf_show("成功修改");
  1418. if (result.text == "") {
  1419. let channel_info = "Empty";
  1420. let thisChannel = find_channal(result.channal);
  1421. if (thisChannel) {
  1422. channel_info = thisChannel.name + "-" + thisChannel.nickname;
  1423. }
  1424. $(
  1425. "#tran_text_" +
  1426. result.book +
  1427. "_" +
  1428. result.para +
  1429. "_" +
  1430. result.begin +
  1431. "_" +
  1432. result.end +
  1433. "_" +
  1434. result.channal
  1435. ).html("<span style='color:var(--border-line-color);'>" + channel_info + "</span>");
  1436. } else {
  1437. $(
  1438. "#tran_text_" +
  1439. result.book +
  1440. "_" +
  1441. result.para +
  1442. "_" +
  1443. result.begin +
  1444. "_" +
  1445. result.end +
  1446. "_" +
  1447. result.channal
  1448. ).html(marked(term_std_str_to_tran(result.text, result.channal, result.editor, result.lang)));
  1449. term_updata_translation();
  1450. for (const iterator of _arrData) {
  1451. if (
  1452. iterator.book == result.book &&
  1453. iterator.para == result.para &&
  1454. iterator.begin == result.begin &&
  1455. iterator.end == result.end
  1456. ) {
  1457. for (const tran of iterator.translation) {
  1458. if (tran.channal == result.channal) {
  1459. tran.text = result.text;
  1460. break;
  1461. }
  1462. }
  1463. }
  1464. }
  1465. }
  1466. } else if (result.commit_type == 3) {
  1467. ntf_show("已经提交修改建议");
  1468. } else {
  1469. ntf_show("未提交");
  1470. }
  1471. }
  1472. }
  1473. );
  1474. }
  1475. function copy_ref(book, para, begin, end) {
  1476. let strRef = "{{" + book + "-" + para + "-" + begin + "-" + end + "}}";
  1477. copy_to_clipboard(strRef);
  1478. }
  1479. function goto_nissaya(book, para, begin = 0, end = 0) {
  1480. window.open("../nissaya/index.php?book=" + book + "&para=" + para + "&begin=" + begin + "&end=" + end, "nissaya");
  1481. }
  1482. function edit_in_studio(book, para, begin, end) {
  1483. wbw_channal_list_open(book, [para]);
  1484. }
  1485. //显示和隐藏某个内容 如 巴利文
  1486. function setVisibility(key, value) {
  1487. switch (key) {
  1488. case "palitext":
  1489. if ($(value).is(":checked")) {
  1490. $(".palitext").show();
  1491. } else {
  1492. $(".palitext").hide();
  1493. }
  1494. break;
  1495. default:
  1496. break;
  1497. }
  1498. }
  1499. function note_show_pali_sim(SentId) {
  1500. pali_sim_dlg_open(SentId, 0, 20);
  1501. }
  1502. function set_pali_script(pos, script) {
  1503. if (script == "none") {
  1504. $(".palitext" + pos).html("");
  1505. } else {
  1506. $(".palitext" + pos).each(function () {
  1507. let html = $(this).siblings(".palitext_roma").first().html();
  1508. $(this).html(html);
  1509. });
  1510. $(".palitext" + pos)
  1511. .find("*")
  1512. .contents()
  1513. .filter(function () {
  1514. return this.nodeType != 1;
  1515. })
  1516. .wrap("<pl" + pos + "></pl" + pos + ">");
  1517. $(".palitext" + pos)
  1518. .contents()
  1519. .filter(function () {
  1520. return this.nodeType != 1;
  1521. })
  1522. .wrap("<pl" + pos + "></pl" + pos + ">");
  1523. $("pl" + pos).html(function (index, oldcontent) {
  1524. return roman_to_my(oldcontent);
  1525. });
  1526. }
  1527. }
  1528. function splite_pali_word() {
  1529. $("pali")
  1530. .contents()
  1531. .filter(function () {
  1532. return this.nodeType != 1;
  1533. })
  1534. .wrap("<pl></pl>");
  1535. $("pl").each(function () {
  1536. let html = $(this).html();
  1537. $(this).html("<w>" + html.replace(/\s/g, "</w> <w>") + "</w>");
  1538. });
  1539. $("w").click(function () {
  1540. let word = com_getPaliReal($(this).text());
  1541. if (gBuildinDictIsOpen) {
  1542. window.open("../dict/index.php?builtin=true&key=" + word, "dict");
  1543. }
  1544. });
  1545. }
  1546. function refresh_pali_script() {
  1547. if (_display && _display == "para") {
  1548. //段落模式
  1549. } else {
  1550. //句子模式
  1551. setting_get("lib.second_script", set_second_scrip);
  1552. }
  1553. }
  1554. function set_second_scrip(value) {
  1555. set_pali_script(2, value);
  1556. }
  1557. function slider_show(obj) {
  1558. $(obj).parent().parent().parent().parent().parent().toggleClass("slider_show_shell");
  1559. }
  1560. function find_sent_tran_div(obj) {
  1561. let jqObj = $(obj);
  1562. while (!jqObj.hasClass("sent_tran")) {
  1563. jqObj = jqObj.parent();
  1564. if (!jqObj) {
  1565. return false;
  1566. }
  1567. }
  1568. return jqObj;
  1569. /*
  1570. let parent = obj.parentNode;
  1571. while (parent.nodeType == 1) {
  1572. if ($(parent).hasClass("sent_tran")) {
  1573. return parent;
  1574. } else if (parent.nodeName == "BODY") {
  1575. return false;
  1576. }
  1577. parent = parent.parentNode;
  1578. }
  1579. return false;
  1580. */
  1581. }
  1582. //显示或隐藏pr数据
  1583. function note_pr_show(channel, id) {
  1584. let obj = $(".sent_tran[channel='" + channel + "'][sid='" + id + "']").find(".pr_content");
  1585. let prHtml = obj.first().html();
  1586. if (prHtml == "") {
  1587. note_get_pr(channel, id);
  1588. } else {
  1589. obj.slideUp();
  1590. obj.html("");
  1591. }
  1592. }
  1593. //获取pr数据并显示
  1594. function note_get_pr(channel, id) {
  1595. let sid = id.split("-");
  1596. let book = sid[0];
  1597. let para = sid[1];
  1598. let begin = sid[2];
  1599. let end = sid[3];
  1600. $.post(
  1601. "../usent/get_pr.php",
  1602. {
  1603. book: book,
  1604. para: para,
  1605. begin: begin,
  1606. end: end,
  1607. channel: channel,
  1608. },
  1609. function (data) {
  1610. let result = JSON.parse(data);
  1611. if (result.length > 0) {
  1612. let html = "<div class='compact'>";
  1613. for (const iterator of result) {
  1614. html += render_one_sent_tran_a(iterator);
  1615. }
  1616. html += "</div>";
  1617. $(".sent_tran[channel='" + channel + "'][sid='" + id + "']")
  1618. .find(".pr_content")
  1619. .html(html);
  1620. $(".sent_tran[channel='" + channel + "'][sid='" + id + "']")
  1621. .find(".pr_content")
  1622. .slideDown();
  1623. } else {
  1624. }
  1625. }
  1626. );
  1627. $(".sent_tran[channel='" + channel + "'][sid='" + id + "']")
  1628. .find(".pr_content")
  1629. .html("loading");
  1630. $(".sent_tran[channel='" + channel + "'][sid='" + id + "']")
  1631. .find(".pr_content")
  1632. .show();
  1633. }
  1634. function get_channel_by_id(id) {
  1635. if (typeof _channalData != "undefined") {
  1636. for (const iterator of _channalData) {
  1637. if (iterator.id == id) {
  1638. return iterator;
  1639. }
  1640. }
  1641. }
  1642. if (typeof _my_channal != "undefined") {
  1643. for (const iterator of _my_channal) {
  1644. if (iterator.id == id) {
  1645. return iterator;
  1646. }
  1647. }
  1648. }
  1649. return false;
  1650. }
  1651. //设置显示方向
  1652. function setDirection(obj) {
  1653. if (obj.value == "row") {
  1654. $("#contents").removeClass("vertical");
  1655. $("#contents").addClass("horizontal");
  1656. } else {
  1657. $("#contents").removeClass("horizontal");
  1658. $("#contents").addClass("vertical");
  1659. }
  1660. }
  1661. //设置逐段或逐句模式
  1662. function setDisplay(obj) {
  1663. if (obj.value == "para") {
  1664. $("#contents").removeClass("sent_mode");
  1665. $("#contents").addClass("para_mode");
  1666. } else {
  1667. $("#contents").removeClass("para_mode");
  1668. $("#contents").addClass("sent_mode");
  1669. }
  1670. }