note.js 47 KB

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