note.js 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505
  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"];
  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='more_tran icon_expand'></span>";
  515. //其他译文工具条
  516. output += "<span class='other_bar' >";
  517. output += "<span class='other_tran_span' >" + gLocal.gui.other + gLocal.gui.translation + "</span>";
  518. output += "<span class='other_tran_num'></span>";
  519. output += "</span>";
  520. output += "<span class='separate_line'></span>";
  521. //相似句工具条
  522. output += "<span class='other_bar' >";
  523. output +=
  524. "<span class='similar_sent_span' onclick=\"note_show_pali_sim('" +
  525. in_json.pali_sent_id +
  526. "')\">" +
  527. gLocal.gui.similar_sentences +
  528. "</span>";
  529. output += "<span class='similar_sent_num'>" + in_json.sim + "</span>";
  530. output += "</span>";
  531. output += "</div>";
  532. output += "<div class='other_tran'>";
  533. output += "</div>";
  534. output += "</div>";
  535. //未选择的其他译文开始
  536. //新增译文按钮开始
  537. output += "<div class='add_new icon_add' ";
  538. output += "book='" + in_json.book + "' ";
  539. output += "para='" + in_json.para + "' ";
  540. output += "begin='" + in_json.begin + "' ";
  541. output += "end='" + in_json.end + "' ";
  542. output += " >";
  543. output += "<div class='icon_add' onclick='add_new_tran_button_click(this)'></div>";
  544. output += "<div class='tran_text_tool_bar'>";
  545. output += "</div>";
  546. output += "</div>";
  547. //新增译文按钮结束
  548. //出处路径开始
  549. output += "<div class='ref'>" + in_json.ref;
  550. output +=
  551. "<span class='sent_no'>" +
  552. in_json.book +
  553. "-" +
  554. in_json.para +
  555. "-" +
  556. in_json.begin +
  557. "-" +
  558. in_json.end +
  559. "<span>" +
  560. "</div>";
  561. //出处路径结束
  562. return output;
  563. }
  564. function sent_tran_edit(obj) {
  565. let jqObj = $(obj);
  566. while (!jqObj.hasClass("sent_tran")) {
  567. jqObj = jqObj.parent();
  568. if (!jqObj) {
  569. return;
  570. }
  571. }
  572. if (jqObj.hasClass("edit_mode")) {
  573. jqObj.removeClass("edit_mode");
  574. } else {
  575. $(".sent_tran").removeClass("edit_mode");
  576. jqObj.addClass("edit_mode");
  577. }
  578. }
  579. function sent_pr_merge(id) {
  580. $.post(
  581. "../usent/sent_pr_merge.php",
  582. {
  583. id: id,
  584. },
  585. function (data) {
  586. let result = JSON.parse(data);
  587. if (result.status > 0) {
  588. alert("error" + result.message);
  589. } else {
  590. ntf_show("成功采纳");
  591. }
  592. }
  593. );
  594. }
  595. function sent_commit(src, id) {
  596. commit_init({
  597. src: src,
  598. sent: [id],
  599. express: true,
  600. });
  601. }
  602. function render_one_sent_tran_a(iterator) {
  603. let mChannel = get_channel_by_id(iterator.channal);
  604. let tranText;
  605. let sid = iterator.book + "-" + iterator.para + "-" + iterator.begin + "-" + iterator.end;
  606. if (iterator.text == "") {
  607. tranText =
  608. "<span style='color:var(--border-line-color);'>" +
  609. iterator.channalinfo.name +
  610. "-" +
  611. iterator.channalinfo.lang +
  612. "</span>";
  613. } else {
  614. //note_init处理句子链接
  615. tranText = note_init(term_std_str_to_tran(iterator.text, iterator.channal, iterator.editor, iterator.lang));
  616. }
  617. let html = "";
  618. html += "<div class='sent_tran ";
  619. if (typeof iterator.is_pr != "undefined" && iterator.is_pr == true) {
  620. html += " pr ";
  621. }
  622. html += "' channel='" + iterator.channal + "' sid='" + sid + "'>";
  623. html += "<div class='sent_tran_inner'>";
  624. html += '<div class="tool_bar">';
  625. html += ' <div class="right">';
  626. //句子菜单
  627. html += '<div class="pop_menu">';
  628. if (typeof iterator.is_pr != "undefined" && iterator.is_pr == true) {
  629. //在pr 列表中的译文
  630. if (typeof iterator.is_pr_editor != "undefined" && iterator.is_pr_editor == true) {
  631. //提交人
  632. //修改按钮
  633. html += "<button class='icon_btn tooltip' onclick='sent_pr_edit(this)'>";
  634. html += '<svg class="icon" >';
  635. html += '<use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#ic_mode_edit"></use>';
  636. html += "</svg>";
  637. html += "<span class='tooltiptext tooltip-top'>";
  638. html += gLocal.gui.modify;
  639. html += "</span>";
  640. html += "</button>";
  641. //删除按钮
  642. html += "<button class='icon_btn tooltip' onclick='sent_pr_del(this)'>";
  643. html += '<svg class="icon" >';
  644. html += '<use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#ic_delete"></use>';
  645. html += "</svg>";
  646. html += "<span class='tooltiptext tooltip-top'>";
  647. html += gLocal.gui.delete;
  648. html += "</span>";
  649. html += "</button>";
  650. } else {
  651. //非提交人
  652. //采纳按钮
  653. html += "<button class='icon_btn tooltip' onclick=\"sent_pr_merge('" + iterator.id + "')\">";
  654. html += '<svg class="icon" >';
  655. html += '<use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#ic_mode_edit"></use>';
  656. html += "</svg>";
  657. html += "<span class='tooltiptext tooltip-top'>";
  658. html += gLocal.gui.accept_copy;
  659. html += "</span>";
  660. html += "</button>";
  661. //点赞按钮
  662. html += "<button class='icon_btn tooltip' onclick='sent_pr_like(this)'>";
  663. html += '<svg class="icon" >';
  664. html += '<use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#like"></use>';
  665. html += "</svg>";
  666. html += "<span class='tooltiptext tooltip-top'>";
  667. html += gLocal.gui.like;
  668. html += "</span>";
  669. html += "</button>";
  670. }
  671. } else {
  672. //非pr列表里的句子
  673. //编辑按钮
  674. html += "<button class='icon_btn tooltip' onclick='sent_tran_edit(this)'>";
  675. html += '<svg class="icon" >';
  676. html += '<use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#ic_mode_edit"></use>';
  677. html += "</svg>";
  678. html += "<span class='tooltiptext tooltip-top'>";
  679. if (parseInt(iterator.mypower) < 20) {
  680. html += "建议";
  681. } else {
  682. html += gLocal.gui.edit;
  683. }
  684. html += "</span>";
  685. html += "</button>";
  686. //推送按钮
  687. if (parseInt(iterator.mypower) >= 20) {
  688. html += "<button class='icon_btn tooltip' ";
  689. html += " onclick=\"sent_commit('" + iterator.channal + "','" + sid + "')\">";
  690. html += '<svg class="icon" >';
  691. html += '<use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#ic_mode_edit"></use>';
  692. html += "</svg>";
  693. html += "<span class='tooltiptext tooltip-top'>";
  694. html += "推送";
  695. html += "</span>";
  696. html += "</button>";
  697. }
  698. //更多按钮
  699. html += '<div class="case_dropdown">';
  700. html += "<button class='icon_btn'>";
  701. html += '<svg class="icon" >';
  702. html += '<use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#ic_more"></use>';
  703. html += "</svg>";
  704. html += "</button>";
  705. html += '<div class="case_dropdown-content menu_space_between" style="right:0;">';
  706. //时间线
  707. html += "<a onclick=\"history_show('" + iterator.id + "')\">";
  708. html += "<span>" + gLocal.gui.timeline + "</span>";
  709. html += '<svg class="icon" >';
  710. html += '<use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#recent_scan"></use>';
  711. html += "</svg>";
  712. html += "</a>";
  713. //复制
  714. html += "<a onclick=\"history_show('" + iterator.id + "')\">";
  715. html += "<span>" + gLocal.gui.copy + "</span>";
  716. html += '<svg class="icon" >';
  717. html += '<use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#copy"></use>';
  718. html += "</svg>";
  719. html += "</a>";
  720. //点赞
  721. html += "<a onclick=\"history_show('" + iterator.id + "')\">";
  722. html += "<span>" + gLocal.gui.like + "</span>";
  723. html += '<svg class="icon" >';
  724. html += '<use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#like"></use>';
  725. html += "</svg>";
  726. html += "</a>";
  727. //分享
  728. html += "<a onclick=\"history_show('" + iterator.id + "')\">";
  729. html += "<span>" + gLocal.gui.share_to + "</span>";
  730. html += '<svg class="icon" >';
  731. html += '<use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#share_to"></use>';
  732. html += "</svg>";
  733. html += "</a>";
  734. html += "</div>";
  735. html += "</div>";
  736. //更多按钮结束
  737. }
  738. html += "</div>";
  739. //句子菜单结束
  740. html += "</div>";
  741. html += "</div>";
  742. //tool_bar 结束
  743. html += '<div class="left_bar">';
  744. html += ' <div class="face">';
  745. if (iterator.id != "") {
  746. html += '<span class="head_img">' + iterator.editor_name.nickname.slice(0, 1) + "</span>";
  747. }
  748. html += "</div>";
  749. html += '<div class="date">' + getPassDataTime(iterator.update_time) + "</div>";
  750. html += "</div>";
  751. html += '<div class="body">';
  752. html += '<div class="head_bar">';
  753. html += '<div class="info">';
  754. html += '<span class="name">' + iterator.editor_name.nickname + "</span>";
  755. html += '<span class="date">' + getPassDataTime(iterator.update_time) + "</span>";
  756. html += "</div>";
  757. html += "<div class='preview'>" + tranText + "</div>";
  758. html += "</div>";
  759. html += '<div class="edit">';
  760. html += '<div class="input">';
  761. html += "<textarea dbid='" + iterator.id + "' ";
  762. html += "sid='" + sid + "' ";
  763. html += "channel='" + iterator.channal + "' ";
  764. html += 'onchange="note_sent_save_a(this)">' + iterator.text + "</textarea>";
  765. html += "</div>";
  766. html += '<div class="edit_tool">';
  767. if (parseInt(iterator.mypower) < 20) {
  768. html += "<b>提交修改建议</b> ";
  769. }
  770. html += "点击输入框外面自动<a onclick='sent_tran_edit(this)'>保存</a> 支持markdown语法";
  771. html += "</div>";
  772. html += "</div>";
  773. html += '<div class="foot_bar">';
  774. html += '<div class="info">';
  775. if (iterator.id != "") {
  776. html += '<span class="name">' + iterator.editor_name.nickname + "</span>";
  777. }
  778. if (iterator.id != "") {
  779. html += '<span class="date"> 于' + getPassDataTime(iterator.update_time) + "</span>";
  780. }
  781. if (iterator.id != "") {
  782. html += '<span class="channel">更新了 @' + iterator.channalinfo.name + "</span>";
  783. } else {
  784. html += '<span class="channel">无人更新 @' + iterator.channalinfo.name + "</span>";
  785. }
  786. html += '<ul class="tag_list">';
  787. if (iterator.pr_all && parseInt(iterator.pr_all) > 0) {
  788. html +=
  789. " <li onclick=\"note_pr_show('" +
  790. iterator.channal +
  791. "','" +
  792. sid +
  793. "')\"><span class='icon'>✋</span><span class='num'>" +
  794. iterator.pr_new +
  795. "/" +
  796. iterator.pr_all +
  797. "</span></li>";
  798. }
  799. html += "</ul>";
  800. html += "</div>"; //end of info
  801. html += "</div>"; //end of foot bar
  802. html += "</div>";
  803. html += "</div>";
  804. //sent_tran_inner结束
  805. html += '<div class="pr_content"></div>';
  806. html += "</div>";
  807. return html;
  808. }
  809. function render_one_sent_tran(book, para, begin, end, iterator) {
  810. let output = "";
  811. output += "<div class='tran' lang='" + iterator.lang + "' style='display:flex;'>";
  812. //译文工具按钮开始
  813. output += "<div class='tran_text_tool_botton' onclick='tool_bar_show(this)'>";
  814. output +=
  815. "<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>";
  816. //译文工具栏开始
  817. output += "<div class='tran_text_tool_bar'>";
  818. output += "<div style='border-right: solid 1px;margin: 0.3em 0;'><li class = 'tip_buttom' ";
  819. output +=
  820. " onclick=\"note_edit_sentence('" +
  821. book +
  822. "' ,'" +
  823. para +
  824. "' ,'" +
  825. begin +
  826. "' ,'" +
  827. end +
  828. "' ,'" +
  829. iterator.channal +
  830. "')\"";
  831. output +=
  832. ">" +
  833. '<svg class="icon" ><use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#ic_mode_edit"></use></svg>';
  834. output += gLocal.gui.edit + "</li>";
  835. output += "<li class = 'tip_buttom' ";
  836. output += " onclick=\"history_show('" + iterator.id + "')\" >";
  837. output +=
  838. '<svg class="icon" ><use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#recent_scan"></use></svg>';
  839. output += gLocal.gui.timeline + "</li>";
  840. output +=
  841. "<li class = 'tip_buttom'>" +
  842. '<svg class="icon" ><use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#copy"></use></svg>';
  843. output += gLocal.gui.copy + "</li></div>";
  844. output +=
  845. "<div style='border-right: solid 1px;margin: 0.3em 0;'><li class = 'tip_buttom'>" +
  846. '<svg class="icon" ><use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#like"></use></svg>';
  847. output += gLocal.gui.like + "</li>";
  848. output +=
  849. "<li class = 'tip_buttom'>" +
  850. '<svg class="icon" ><use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#comment"></use></svg>';
  851. output += gLocal.gui.comment + "</li>";
  852. output +=
  853. "<li class = 'tip_buttom'>" +
  854. '<svg class="icon" ><use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#ic_shopping_cart"></use></svg>';
  855. output += gLocal.gui.digest + "</li></div>";
  856. output +=
  857. "<div style='margin: 0.3em 0;'><li class = 'tip_buttom'>" +
  858. '<svg class="icon" ><use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#share_to"></use></svg>';
  859. output += gLocal.gui.share_to + "</li>";
  860. output += "</div></div>";
  861. //译文工具栏结束
  862. output += "</div>";
  863. //译文工具按钮结束
  864. //译文正文开始
  865. output +=
  866. "<div class='text' id='tran_text_" +
  867. book +
  868. "_" +
  869. para +
  870. "_" +
  871. begin +
  872. "_" +
  873. end +
  874. "_" +
  875. iterator.channal +
  876. "'>";
  877. if (iterator.text == "") {
  878. output +=
  879. "<span style='color:var(--border-line-color);'>" +
  880. iterator.channalinfo.name +
  881. "-" +
  882. iterator.channalinfo.lang +
  883. "</span>";
  884. } else {
  885. //note_init处理句子链接
  886. output += note_init(term_std_str_to_tran(iterator.text, iterator.channal, iterator.editor, iterator.lang));
  887. }
  888. output += "</div>";
  889. //译文正文结束
  890. output += "</div>";
  891. //单个channal译文框结束
  892. return output;
  893. }
  894. function add_new_tran_button_click(obj) {
  895. let html = "<ul>";
  896. for (const iterator of _my_channal) {
  897. if (iterator.status > 0) {
  898. if (_channal.indexOf(iterator.id) < 0) {
  899. html += '<li onclick="';
  900. html +=
  901. "new_sentence('" +
  902. $(obj).parent().attr("book") +
  903. "' ,'" +
  904. $(obj).parent().attr("para") +
  905. "' ,'" +
  906. $(obj).parent().attr("begin") +
  907. "' ,'" +
  908. $(obj).parent().attr("end") +
  909. "' ,'" +
  910. iterator.id +
  911. "',this)";
  912. html += '">' + iterator.name;
  913. if (parseInt(iterator.power) < 20) {
  914. html += "(建议)";
  915. }
  916. html += "</li>";
  917. }
  918. }
  919. }
  920. html += "</ul>";
  921. $(obj).parent().children(".tran_text_tool_bar").first().html(html);
  922. if ($(obj).parent().children(".tran_text_tool_bar").css("display") == "block") {
  923. $(obj).parent().children(".tran_text_tool_bar").first().hide();
  924. } else {
  925. $(obj).parent().children(".tran_text_tool_bar").first().show();
  926. $(obj).parent().show();
  927. }
  928. }
  929. function new_sentence(book, para, begin, end, channel, obj) {
  930. let newsent = { id: "", text: "", lang: "", channal: channel };
  931. for (let iterator of _arrData) {
  932. if (iterator.book == book && iterator.para == para && iterator.begin == begin && iterator.end == end) {
  933. let found = false;
  934. for (const tran of iterator.translation) {
  935. if (tran.channal == channel) {
  936. found = true;
  937. break;
  938. }
  939. }
  940. if (!found) {
  941. iterator.translation.push(newsent);
  942. }
  943. }
  944. }
  945. if ($(obj).parent().parent().css("display") == "block") {
  946. $(obj).parent().parent().hide();
  947. }
  948. note_edit_sentence(book, para, begin, end, channel);
  949. }
  950. //显示更多译文按钮动作
  951. function set_more_button_display() {
  952. $(".other_tran_div").each(function () {
  953. const sentid = $(this).attr("sent").split("-");
  954. const book = sentid[0];
  955. const para = sentid[1];
  956. const begin = sentid[2];
  957. const end = sentid[3];
  958. let count = 0;
  959. for (const iterator of _channalData) {
  960. if (iterator.final) {
  961. for (const onesent of iterator.final) {
  962. let id = onesent.id.split("-");
  963. if (book == id[0] && para == id[1] && begin == id[2] && end == id[3] && onesent.final) {
  964. if (_channal.indexOf(iterator.id) == -1) {
  965. count++;
  966. }
  967. }
  968. }
  969. }
  970. }
  971. if (count > 0) {
  972. $(this).find(".other_tran_num").html(count);
  973. $(this).find(".other_tran_num").attr("style", "display:inline-flex;");
  974. $(this)
  975. .find(".other_bar")
  976. .click(function () {
  977. const sentid = $(this).parent().attr("sent").split("-");
  978. const book = sentid[0];
  979. const para = sentid[1];
  980. const begin = sentid[2];
  981. const end = sentid[3];
  982. let sentId = book + "-" + para + "-" + begin + "-" + end;
  983. if ($(this).parent().siblings(".other_tran").first().css("display") == "none") {
  984. $(".other_tran_div[sent='" + sentId + "']")
  985. .children(".other_tran")
  986. .slideDown();
  987. $(this).siblings(".more_tran ").css("transform", "unset");
  988. $.get(
  989. "../usent/get.php",
  990. {
  991. book: book,
  992. para: para,
  993. begin: begin,
  994. end: end,
  995. },
  996. function (data, status) {
  997. let arrSent = JSON.parse(data);
  998. let html = "<div class='compact'>";
  999. for (const iterator of arrSent) {
  1000. if (_channal.indexOf(iterator.channal) == -1) {
  1001. html += render_one_sent_tran_a(iterator);
  1002. //html += "<div>" + marked(iterator.text) + "</div>";
  1003. }
  1004. }
  1005. html += "</div>";
  1006. let sentId =
  1007. arrSent[0].book +
  1008. "-" +
  1009. arrSent[0].paragraph +
  1010. "-" +
  1011. arrSent[0].begin +
  1012. "-" +
  1013. arrSent[0].end;
  1014. $(".other_tran_div[sent='" + sentId + "']")
  1015. .children(".other_tran")
  1016. .html(html);
  1017. }
  1018. );
  1019. } else {
  1020. $(".other_tran_div[sent='" + sentId + "']")
  1021. .children(".other_tran")
  1022. .slideUp();
  1023. $(this).siblings(".more_tran ").css("transform", "rotate(-90deg)");
  1024. }
  1025. });
  1026. } else {
  1027. //隐藏自己
  1028. //$(this).hide();
  1029. $(this)
  1030. .find(".other_tran_span")
  1031. .html(gLocal.gui.no + gLocal.gui.other + gLocal.gui.translation);
  1032. //$(this).find(".more_tran").hide();
  1033. }
  1034. });
  1035. }
  1036. function note_edit_sentence(book, para, begin, end, channal) {
  1037. let channalInfo;
  1038. for (const iterator of _channalData) {
  1039. if (iterator.id == channal) {
  1040. channalInfo = iterator;
  1041. break;
  1042. }
  1043. }
  1044. for (const iterator of _arrData) {
  1045. if (iterator.book == book && iterator.para == para && iterator.begin == begin && iterator.end == end) {
  1046. for (const tran of iterator.translation) {
  1047. if (tran.channal == channal) {
  1048. let html = "";
  1049. html += "<div style='color:blue;'>" + channalInfo.name + "@" + channalInfo.nickname + "</div>";
  1050. html +=
  1051. "<textarea id='edit_dialog_text' sent_id='" +
  1052. tran.id +
  1053. "' book='" +
  1054. book +
  1055. "' para='" +
  1056. para +
  1057. "' begin='" +
  1058. begin +
  1059. "' end='" +
  1060. end +
  1061. "' channal='" +
  1062. channal +
  1063. "' style='width:100%;min-height:260px;'>" +
  1064. tran.text +
  1065. "</textarea>";
  1066. $("#edit_dialog_content").html(html);
  1067. $("#note_sent_edit_dlg").dialog("open");
  1068. return;
  1069. }
  1070. }
  1071. }
  1072. }
  1073. alert("未找到句子");
  1074. }
  1075. function update_note_sent_tran(obj) {}
  1076. //保存译文句子 新
  1077. function note_sent_save_a(obj) {
  1078. let id = $(obj).attr("dbid");
  1079. let sid = $(obj).attr("sid").split("-");
  1080. let book = sid[0];
  1081. let para = sid[1];
  1082. let begin = sid[2];
  1083. let end = sid[3];
  1084. let channal = $(obj).attr("channel");
  1085. let text = $(obj).val();
  1086. let sent_tran_div = find_sent_tran_div(obj);
  1087. $.post(
  1088. "../usent/sent_post.php",
  1089. {
  1090. id: id,
  1091. book: book,
  1092. para: para,
  1093. begin: begin,
  1094. end: end,
  1095. channal: channal,
  1096. text: text,
  1097. lang: "zh",
  1098. },
  1099. function (data) {
  1100. let result = JSON.parse(data);
  1101. if (result.status > 0) {
  1102. alert("error" + result.message);
  1103. } else {
  1104. if (result.commit_type == 1 || result.commit_type == 2) {
  1105. ntf_show("成功修改");
  1106. if (sent_tran_div) {
  1107. let divPreview = $(sent_tran_div).find(".preview").first();
  1108. if (result.text == "") {
  1109. let channel_info = "Empty";
  1110. let thisChannel = find_channal(result.channal);
  1111. if (thisChannel) {
  1112. channel_info = thisChannel.name + "-" + thisChannel.nickname;
  1113. }
  1114. divPreview.html(
  1115. "<span style='color:var(--border-line-color);'>" + channel_info + "</span>"
  1116. );
  1117. } else {
  1118. divPreview.html(
  1119. marked(term_std_str_to_tran(result.text, result.channal, result.editor, result.lang))
  1120. );
  1121. term_updata_translation();
  1122. popup_init();
  1123. for (const iterator of _arrData) {
  1124. if (
  1125. iterator.book == result.book &&
  1126. iterator.para == result.para &&
  1127. iterator.begin == result.begin &&
  1128. iterator.end == result.end
  1129. ) {
  1130. for (const tran of iterator.translation) {
  1131. if (tran.channal == result.channal) {
  1132. tran.text = result.text;
  1133. break;
  1134. }
  1135. }
  1136. }
  1137. }
  1138. }
  1139. $(sent_tran_div).find(".preview").removeClass("loading");
  1140. }
  1141. } else if (result.commit_type == 3) {
  1142. ntf_show("已经提交修改建议");
  1143. } else {
  1144. ntf_show("未提交");
  1145. }
  1146. }
  1147. }
  1148. );
  1149. if (sent_tran_div) {
  1150. $(sent_tran_div).find(".preview").addClass("loading");
  1151. }
  1152. }
  1153. //保存译文句子
  1154. function note_sent_save() {
  1155. let id = $("#edit_dialog_text").attr("sent_id");
  1156. let book = $("#edit_dialog_text").attr("book");
  1157. let para = $("#edit_dialog_text").attr("para");
  1158. let begin = $("#edit_dialog_text").attr("begin");
  1159. let end = $("#edit_dialog_text").attr("end");
  1160. let channal = $("#edit_dialog_text").attr("channal");
  1161. let text = $("#edit_dialog_text").val();
  1162. $.post(
  1163. "../usent/sent_post.php",
  1164. {
  1165. id: id,
  1166. book: book,
  1167. para: para,
  1168. begin: begin,
  1169. end: end,
  1170. channal: channal,
  1171. text: text,
  1172. lang: "zh",
  1173. },
  1174. function (data) {
  1175. let result = JSON.parse(data);
  1176. if (result.status > 0) {
  1177. alert("error" + result.message);
  1178. } else {
  1179. if (result.commit_type == 1 || result.commit_type == 2) {
  1180. ntf_show("成功修改");
  1181. if (result.text == "") {
  1182. let channel_info = "Empty";
  1183. let thisChannel = find_channal(result.channal);
  1184. if (thisChannel) {
  1185. channel_info = thisChannel.name + "-" + thisChannel.nickname;
  1186. }
  1187. $(
  1188. "#tran_text_" +
  1189. result.book +
  1190. "_" +
  1191. result.para +
  1192. "_" +
  1193. result.begin +
  1194. "_" +
  1195. result.end +
  1196. "_" +
  1197. result.channal
  1198. ).html("<span style='color:var(--border-line-color);'>" + channel_info + "</span>");
  1199. } else {
  1200. $(
  1201. "#tran_text_" +
  1202. result.book +
  1203. "_" +
  1204. result.para +
  1205. "_" +
  1206. result.begin +
  1207. "_" +
  1208. result.end +
  1209. "_" +
  1210. result.channal
  1211. ).html(marked(term_std_str_to_tran(result.text, result.channal, result.editor, result.lang)));
  1212. term_updata_translation();
  1213. for (const iterator of _arrData) {
  1214. if (
  1215. iterator.book == result.book &&
  1216. iterator.para == result.para &&
  1217. iterator.begin == result.begin &&
  1218. iterator.end == result.end
  1219. ) {
  1220. for (const tran of iterator.translation) {
  1221. if (tran.channal == result.channal) {
  1222. tran.text = result.text;
  1223. break;
  1224. }
  1225. }
  1226. }
  1227. }
  1228. }
  1229. } else if (result.commit_type == 3) {
  1230. ntf_show("已经提交修改建议");
  1231. } else {
  1232. ntf_show("未提交");
  1233. }
  1234. }
  1235. }
  1236. );
  1237. }
  1238. function copy_ref(book, para, begin, end) {
  1239. let strRef = "{{" + book + "-" + para + "-" + begin + "-" + end + "}}";
  1240. copy_to_clipboard(strRef);
  1241. }
  1242. function goto_nissaya(book, para, begin = 0, end = 0) {
  1243. window.open("../nissaya/index.php?book=" + book + "&para=" + para + "&begin=" + begin + "&end=" + end, "nissaya");
  1244. }
  1245. function edit_in_studio(book, para, begin, end) {
  1246. wbw_channal_list_open(book, [para]);
  1247. }
  1248. function tool_bar_show(element) {
  1249. if ($(element).find(".tran_text_tool_bar").css("display") == "none") {
  1250. $(element).find(".tran_text_tool_bar").css("display", "flex");
  1251. $(element).find(".icon_expand").css("transform", "rotate(-180deg)");
  1252. $(element).css("background-color", "var(--btn-bg-color)");
  1253. $(element).css("visibility", "visible");
  1254. $(document).one("click", function () {
  1255. $(element).find(".tran_text_tool_bar").hide();
  1256. $(element).css("background-color", "var(--nocolor)");
  1257. $(element).find(".icon_expand").css("transform", "unset");
  1258. $(element).css("visibility", "");
  1259. });
  1260. event.stopPropagation();
  1261. } else {
  1262. $(element).find(".tran_text_tool_bar").hide();
  1263. $(element).css("background-color", "var(--nocolor)");
  1264. $(element).find(".icon_expand").css("transform", "unset");
  1265. $(element).css("visibility", "");
  1266. }
  1267. }
  1268. //显示和隐藏某个内容 如 巴利文
  1269. function setVisibility(key, value) {
  1270. switch (key) {
  1271. case "palitext":
  1272. if ($(value).is(":checked")) {
  1273. $(".palitext").show();
  1274. } else {
  1275. $(".palitext").hide();
  1276. }
  1277. break;
  1278. default:
  1279. break;
  1280. }
  1281. }
  1282. function note_show_pali_sim(SentId) {
  1283. pali_sim_dlg_open(SentId, 0, 20);
  1284. }
  1285. function set_pali_script(pos, script) {
  1286. if (script == "none") {
  1287. $(".palitext" + pos).html("");
  1288. } else {
  1289. $(".palitext" + pos).each(function () {
  1290. let html = $(this).siblings(".palitext_roma").first().html();
  1291. $(this).html(html);
  1292. });
  1293. $(".palitext" + pos)
  1294. .find("*")
  1295. .contents()
  1296. .filter(function () {
  1297. return this.nodeType != 1;
  1298. })
  1299. .wrap("<pl" + pos + "></pl" + pos + ">");
  1300. $(".palitext" + pos)
  1301. .contents()
  1302. .filter(function () {
  1303. return this.nodeType != 1;
  1304. })
  1305. .wrap("<pl" + pos + "></pl" + pos + ">");
  1306. $("pl" + pos).html(function (index, oldcontent) {
  1307. return roman_to_my(oldcontent);
  1308. });
  1309. }
  1310. }
  1311. function splite_pali_word() {
  1312. $("pali")
  1313. .contents()
  1314. .filter(function () {
  1315. return this.nodeType != 1;
  1316. })
  1317. .wrap("<pl></pl>");
  1318. $("pl").each(function () {
  1319. let html = $(this).html();
  1320. $(this).html("<w>" + html.replace(/\s/g, "</w> <w>") + "</w>");
  1321. });
  1322. $("w").click(function () {
  1323. let word = com_getPaliReal($(this).text());
  1324. if (gBuildinDictIsOpen) {
  1325. window.open("../dict/index.php?builtin=true&key=" + word, "dict");
  1326. }
  1327. });
  1328. }
  1329. function refresh_pali_script() {
  1330. if (_display && _display == "para") {
  1331. //段落模式
  1332. } else {
  1333. //句子模式
  1334. setting_get("lib.second_script", set_second_scrip);
  1335. }
  1336. }
  1337. function set_second_scrip(value) {
  1338. set_pali_script(2, value);
  1339. }
  1340. function slider_show(obj) {
  1341. $(obj).parent().parent().parent().parent().parent().toggleClass("slider_show_shell");
  1342. }
  1343. function find_sent_tran_div(obj) {
  1344. let parent = obj.parentNode;
  1345. while (parent.nodeType == 1) {
  1346. if ($(parent).hasClass("sent_tran")) {
  1347. return parent;
  1348. } else if (parent.nodeName == "BODY") {
  1349. return false;
  1350. }
  1351. parent = parent.parentNode;
  1352. }
  1353. return false;
  1354. }
  1355. //显示或隐藏pr数据
  1356. function note_pr_show(channel, id) {
  1357. let obj = $(".sent_tran[channel='" + channel + "'][sid='" + id + "']").find(".pr_content");
  1358. let prHtml = obj.first().html();
  1359. if (prHtml == "") {
  1360. note_get_pr(channel, id);
  1361. } else {
  1362. obj.slideUp();
  1363. obj.html("");
  1364. }
  1365. }
  1366. //获取pr数据并显示
  1367. function note_get_pr(channel, id) {
  1368. let sid = id.split("-");
  1369. let book = sid[0];
  1370. let para = sid[1];
  1371. let begin = sid[2];
  1372. let end = sid[3];
  1373. $.post(
  1374. "../usent/get_pr.php",
  1375. {
  1376. book: book,
  1377. para: para,
  1378. begin: begin,
  1379. end: end,
  1380. channel: channel,
  1381. },
  1382. function (data) {
  1383. let result = JSON.parse(data);
  1384. if (result.length > 0) {
  1385. let html = "<div class='compact'>";
  1386. for (const iterator of result) {
  1387. html += render_one_sent_tran_a(iterator);
  1388. }
  1389. html += "</div>";
  1390. $(".sent_tran[channel='" + channel + "'][sid='" + id + "']")
  1391. .find(".pr_content")
  1392. .html(html);
  1393. $(".sent_tran[channel='" + channel + "'][sid='" + id + "']")
  1394. .find(".pr_content")
  1395. .slideDown();
  1396. } else {
  1397. }
  1398. }
  1399. );
  1400. $(".sent_tran[channel='" + channel + "'][sid='" + id + "']")
  1401. .find(".pr_content")
  1402. .html("loading");
  1403. $(".sent_tran[channel='" + channel + "'][sid='" + id + "']")
  1404. .find(".pr_content")
  1405. .show();
  1406. }
  1407. function get_channel_by_id(id) {
  1408. if (typeof _channalData != "undefined") {
  1409. for (const iterator of _channalData) {
  1410. if (iterator.id == id) {
  1411. return iterator;
  1412. }
  1413. }
  1414. }
  1415. if (typeof _my_channal != "undefined") {
  1416. for (const iterator of _my_channal) {
  1417. if (iterator.id == id) {
  1418. return iterator;
  1419. }
  1420. }
  1421. }
  1422. return false;
  1423. }