2
0

note.js 45 KB

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