note.js 51 KB

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