note.js 51 KB

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