note.js 43 KB

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