note.js 64 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426
  1. var _display = "para";
  2. var _mode = "read";
  3. var _direction = "row";
  4. var _word = "";
  5. var _channal = "";
  6. var _lang = "";
  7. var _author = "";
  8. var _arrData = new Array();
  9. var _channalData;
  10. var MAX_NOTE_NEST = 2;
  11. var gBuildinDictIsOpen = false;
  12. var note_renderer = new marked.Renderer();
  13. note_renderer.code = function(code, language) {
  14. if (language == "mermaid") return '<pre class="mermaid">' + code + "</pre>";
  15. else return "<pre><code>" + code + "</code></pre>";
  16. };
  17. /*
  18. {{203-1654-23-45@11@en@*}}
  19. <note>203-1654-23-45@11@en@*</note>
  20. <note id=guid book=203 para=1654 begin=23 end=45 author=11 lang=en tag=*></note>
  21. <note id=guid book=203 para=1654 begin=23 end=45 author=11 lang=en tag=*>
  22. <div class=text>
  23. pali text
  24. </div>
  25. <tran>
  26. </tran>
  27. <ref>
  28. </ref>
  29. </note>
  30. */
  31. /*
  32. 解析百科字符串
  33. {{203-1654-23-45@11@en@*}}
  34. <note id=12345 info="203-1654-23-45@11@en@*"><note>
  35. <note id="guid" book=203 para=1654 begin=23 end=45 author=11 lang=en tag=*></note>
  36. */
  37. function note_create() {
  38. $.post("../ucenter/get_setting.php", {}, function (data, status) {
  39. setting = JSON.parse(data);
  40. });
  41. wbw_channal_list_init();
  42. note_sent_edit_dlg_init();
  43. term_edit_dlg_init();
  44. pali_sim_dlg_init();
  45. related_para_dlg_init();
  46. term_get_all_pali();
  47. }
  48. function note_sent_edit_dlg_init() {
  49. $("body").append(
  50. '<div id="note_sent_edit_dlg" title="' +
  51. gLocal.gui.edit +
  52. '"><guide gid="markdown_guide"></guide><div id="edit_dialog_content"></div></div>'
  53. );
  54. guide_init();
  55. $("#note_sent_edit_dlg").dialog({
  56. autoOpen: false,
  57. width: 550,
  58. buttons: [
  59. {
  60. text: gLocal.gui.save,
  61. click: function () {
  62. note_sent_save();
  63. $(this).dialog("close");
  64. },
  65. },
  66. {
  67. text: gLocal.gui.cancel,
  68. click: function () {
  69. $(this).dialog("close");
  70. },
  71. },
  72. ],
  73. });
  74. }
  75. function note_init(input,channel="",editor="",lang="en") {
  76. if (input) {
  77. let output = "<div>";
  78. //output += marked(input);
  79. output += marked(term_std_str_to_tran(input, channel, editor, lang), { renderer: note_renderer });
  80. output += "</div>";
  81. let newString = output.replace(/\{\{/g, '<span class="note_shell"><note style="border: solid 2px var(--btn-bg-color);" info="');
  82. newString = newString.replace(/\}\}/g, '" ></note></span>');
  83. return newString;
  84. } else {
  85. return "";
  86. }
  87. }
  88. function note_update_background_style() {
  89. var mSentsBook = new Array();
  90. var mBgIndex = 1;
  91. $("note[info]").each(function () {
  92. let info = $(this).attr("info").split("-");
  93. if (info.length >= 2) {
  94. let book = info[0];
  95. $(this).attr("book", book);
  96. if (!mSentsBook[book]) {
  97. mSentsBook[book] = mBgIndex;
  98. mBgIndex++;
  99. }
  100. $(this).addClass("bg_color_" + mSentsBook[book]);
  101. }
  102. });
  103. }
  104. //
  105. function note_refresh_new(callback = null) {
  106. note_update_background_style();
  107. let objNotes = document.querySelectorAll("note");
  108. let arrSentInfo = new Array();
  109. for (const iterator of objNotes) {
  110. let id = iterator.id;
  111. if (id == null || id == "") {
  112. //查看这个节点是第几层note嵌套。大于预定层数退出。
  113. let layout = 1;
  114. let parent = iterator.parentNode;
  115. while (parent.nodeType == 1) {
  116. if (parent.nodeName == "NOTE") {
  117. layout++;
  118. if (layout > MAX_NOTE_NEST) {
  119. return false;
  120. }
  121. } else if (parent.nodeName == "BODY") {
  122. break;
  123. }
  124. parent = parent.parentNode;
  125. }
  126. id = com_guid();
  127. iterator.id = id;
  128. if (iterator.hasAttribute("info")) {
  129. let info = iterator.getAttribute("info");
  130. if (info != null || info != "") {
  131. /*
  132. let arrInfo = info.split("-");
  133. if (arrInfo.length >= 2) {
  134. let book = arrInfo[0];
  135. let para = arrInfo[1];
  136. }
  137. */
  138. arrSentInfo.push({ id: id, data: info });
  139. }
  140. }
  141. }
  142. }
  143. if (arrSentInfo.length > 0) {
  144. let setting = new Object();
  145. setting.lang = "";
  146. setting.channal = _channal;
  147. $.post(
  148. "../term/note.php",
  149. {
  150. setting: JSON.stringify(setting),
  151. data: JSON.stringify(arrSentInfo),
  152. },
  153. function (data, status) {
  154. if (status == "success") {
  155. try {
  156. let sentData = JSON.parse(data);
  157. for (const iterator of sentData) {
  158. let id = iterator.id;
  159. let strHtml = "<a name='" + id + "'></a>";
  160. if (_mode && _mode == "read") {
  161. //阅读模式
  162. strHtml += render_read_mode_sent(iterator);
  163. $("#" + id).html(strHtml);
  164. } else {
  165. //编辑模式
  166. strHtml += note_json_html(iterator);
  167. $("#" + id).html(strHtml);
  168. }
  169. }
  170. //处理<code>标签作为气泡注释
  171. popup_init();
  172. //刷新句子链接递归,有加层数限制。
  173. //note_refresh_new();
  174. //将新的数据添加到数据总表
  175. _arrData = _arrData.concat(sentData);
  176. note_ref_init();
  177. //获取术语字典
  178. term_get_dict();
  179. //刷新channel列表
  180. note_channal_list();
  181. //显示不同的巴利语脚本
  182. refresh_pali_script();
  183. //把巴利语单词用<w>分隔用于点词查询等
  184. splite_pali_word();
  185. //处理编辑框消息
  186. tran_sent_textarea_event_init();
  187. if (callback) {
  188. callback();
  189. }
  190. //初始化mermaid
  191. mermaid.initialize();
  192. } catch (e) {
  193. console.error(e);
  194. }
  195. }
  196. }
  197. );
  198. } else {
  199. term_get_dict();
  200. }
  201. }
  202. //渲染巴利原文句子
  203. function render_pali_sent(palitext){
  204. let output = "";
  205. output =
  206. "<pali book='" +
  207. palitext.book +
  208. "' para='" +
  209. palitext.para +
  210. "' begin='" +
  211. palitext.begin +
  212. "' end='" +
  213. palitext.end +
  214. "' >";
  215. if(palitext.book<1000){
  216. output += palitext.palitext;
  217. }
  218. else{
  219. output += marked(palitext.palitext);
  220. }
  221. output +="</pali>";
  222. return output;
  223. }
  224. //渲染阅读模式句子
  225. function render_read_mode_sent(iterator) {
  226. let id = iterator.id;
  227. let strPalitext =render_pali_sent(iterator);
  228. if (
  229. $("#" + id)
  230. .parent()
  231. .parent()
  232. .children(".para_div").length == 0
  233. ) {
  234. let tranDivHtml = "";
  235. if (_channal != "") {
  236. let arrChannal = _channal.split(",");
  237. for (let index = arrChannal.length - 1; index >= 0; index--) {
  238. const iChannal = arrChannal[index];
  239. tranDivHtml += "<div class='tran_div_channel' channal='" + iChannal + "'></div>";
  240. }
  241. } else {
  242. tranDivHtml = "<div class='tran_div_channel' channal='0'></div>";
  243. }
  244. $("#" + id)
  245. .parent()
  246. .parent()
  247. .prepend(
  248. "<div class='para_div'>"+
  249. "<div class='palitext_div'>"+
  250. "<div class='palitext palitext1'></div>"+
  251. "<div class='palitext palitext2'></div>"+
  252. "</div>"+
  253. "<div class='para_tran_div'>" +
  254. tranDivHtml +
  255. "</div></div>"
  256. );
  257. }
  258. $("#" + id)
  259. .parent()
  260. .parent()
  261. .children(".para_div")
  262. .find(".palitext")
  263. .first()
  264. .append(strPalitext);
  265. let htmlSent = "";
  266. htmlSent += "<div class='note_body'>";
  267. htmlSent += "<div class='palitext_div'>";
  268. htmlSent += "<div class='palitext palitext1'>" + strPalitext + "</div>";
  269. htmlSent += "<span class='sent_no_read_mode'>";
  270. htmlSent += iterator.book + "-" + iterator.para + "-" + iterator.begin + "-" + iterator.end;
  271. htmlSent += "<span>";
  272. htmlSent += "<div class='palitext palitext2'></div>";
  273. htmlSent += "</div>";
  274. htmlSent += "<div class='sent_tran_div'>";
  275. for (const oneTran of iterator.translation) {
  276. let html = "<span class='tran_sent' lang='" + oneTran.lang + "' channal='" + oneTran.channal + "'>";
  277. //将绝对链接转换为 用户连接的主机链接
  278. oneTran.text = oneTran.text.replace(/[A-z]*.wikipali.org/g,location.host);
  279. html += marked(term_std_str_to_tran(oneTran.text, oneTran.channal, oneTran.editor, oneTran.lang));
  280. html += "</span>";
  281. htmlSent += html;
  282. let channelId = "0";
  283. if (_channal != "") {
  284. channelId = oneTran.channal;
  285. }
  286. $("#" + id)
  287. .parent()
  288. .parent()
  289. .find(".tran_div_channel[channal='" + channelId + "']")
  290. .append(html);
  291. }
  292. htmlSent += "</div>";
  293. htmlSent += "</div>"; //note_body
  294. htmlSent += "<div class='note_foot'>";
  295. htmlSent += "<span>" + iterator.ref + "</span>";
  296. htmlSent +=
  297. "<span class='sent_id'>" +
  298. iterator.book +
  299. "-" +
  300. iterator.para +
  301. "-" +
  302. iterator.begin +
  303. "-" +
  304. iterator.end +
  305. "</span>";
  306. htmlSent += "</div>"; //note_foot
  307. return htmlSent;
  308. }
  309. //生成channel列表
  310. function note_channal_list() {
  311. console.log("note_channal_list start");
  312. let arrSentInfo = new Array();
  313. $("note").each(function () {
  314. let info = $(this).attr("info");
  315. if (info && info != "") {
  316. arrSentInfo.push({ id: "", data: info });
  317. }
  318. });
  319. if (arrSentInfo.length > 0) {
  320. $.post(
  321. "../term/channal_list.php",
  322. {
  323. setting: "",
  324. data: JSON.stringify(arrSentInfo),
  325. },
  326. function (data, status) {
  327. if (status == "success") {
  328. try {
  329. let active = JSON.parse(data);
  330. _channalData = active;
  331. for (const iterator of _my_channal) {
  332. let found = false;
  333. for (const one of active) {
  334. if (iterator.uid == one.uid) {
  335. found = true;
  336. break;
  337. }
  338. }
  339. if (found == false) {
  340. _channalData.push(iterator);
  341. }
  342. }
  343. let strHtml = "";
  344. for (const iterator of _channalData) {
  345. if (_channal.indexOf(iterator.id) >= 0) {
  346. strHtml += render_channal_list(iterator);
  347. }
  348. }
  349. for (const iterator of _channalData) {
  350. if (_channal.indexOf(iterator.id) == -1) {
  351. strHtml += render_channal_list(iterator);
  352. }
  353. }
  354. $("#channal_list").html(strHtml);
  355. set_more_button_display();
  356. let lang=new Object();
  357. let currLang=_lang;
  358. let firstChannel="";
  359. if(_channal!=""){
  360. firstChannel = _channal.split(",")[0];
  361. }
  362. for (const iterator of _channalData) {
  363. lang[iterator.lang]=1;
  364. if(iterator.id==firstChannel){
  365. currLang = iterator.lang;
  366. }
  367. }
  368. let htmlLangSelect="<option value=''>全部语言</option>";
  369. let isLangMatched=false;
  370. for (const key in lang) {
  371. if (lang.hasOwnProperty.call(lang, key)) {
  372. let strLang = key;
  373. if(gLocal.language.hasOwnProperty.call(gLocal.language, key)){
  374. strLang = gLocal.language[key];
  375. }
  376. htmlLangSelect += "<option value='"+key+"' ";
  377. if(currLang==key){
  378. htmlLangSelect += "selected ";
  379. isLangMatched = true;
  380. }
  381. htmlLangSelect +=">"+strLang+"</option>";
  382. }
  383. }
  384. $("#select_lang").html(htmlLangSelect);
  385. if(isLangMatched){
  386. render_edition_list(currLang);
  387. }else{
  388. render_edition_list("");
  389. }
  390. } catch (e) {
  391. console.error(e);
  392. }
  393. }
  394. }
  395. );
  396. }
  397. }
  398. function lang_changed(obj){
  399. _lang = $(obj).val();
  400. render_edition_list(_lang);
  401. }
  402. //顶部的版本列表
  403. function render_edition_list(lang=""){
  404. let firstChannel="";
  405. if(_channal!=""){
  406. firstChannel = _channal.split(",")[0];
  407. }
  408. let html = "";
  409. html += "<div class='case_dropdown-content'>";
  410. let currChannel="选择一个版本";
  411. for (const iterator of _channalData) {
  412. if(iterator.id==firstChannel){
  413. currChannel = iterator.name;
  414. }
  415. if(lang=="" || (lang!="" && lang==iterator.lang)){
  416. if (iterator["final"]){
  417. html += "<a onclick=\"edition_list_changed('"+iterator.id+"')\">"+iterator.name+"</a>";
  418. }
  419. }
  420. }
  421. html +="</div>";
  422. html = "<span>"+currChannel+"▼</span>" + html;
  423. $("#edition_dropdown").html(html);
  424. }
  425. function edition_list_changed(channelId){
  426. _channal = channelId;
  427. render_edition_list(_lang);
  428. set_channal(channelId);
  429. }
  430. function find_channal(id) {
  431. for (const iterator of _channalData) {
  432. if (id == iterator.id) {
  433. return iterator;
  434. }
  435. }
  436. return false;
  437. }
  438. //生成版本列表
  439. //选择列表中的版本切换页面
  440. function render_channal_list(channalinfo) {
  441. let output = "";
  442. let checked = "";
  443. let selected = "noselect";
  444. if (_channal.indexOf(channalinfo.uid) >= 0) {
  445. checked = "checked";
  446. selected = "selected";
  447. }
  448. output += "<div class='list_with_head " + selected + "'>";
  449. output += '<div class="tool_bar">';
  450. output += '<div class="right">';
  451. output += '<div class="pop_menu">';
  452. output += render_icon_button("copy", "commit_init({src:'" + channalinfo.uid + "'})", gLocal.gui.copy_to);
  453. output += render_icon_button("ic_mode_edit", "", gLocal.gui.modify);
  454. output += "</div>";
  455. output += "</div>";
  456. output += "</div>";
  457. output +=
  458. '<div class="channel_select"><input type="checkbox" ' + checked + " channal_id='" + channalinfo.uid + "'></div>";
  459. output += "<div class='head'>";
  460. output += "<span class='head_img'>";
  461. if (parseInt(channalinfo.power) == 30) {
  462. output += gLocal.gui.your.slice(0, 1);
  463. } else {
  464. output += channalinfo.nickname.slice(0, 1);
  465. }
  466. output += "</span>";
  467. output += "</div>";
  468. output += "<div style='width: 100%;overflow-x: hidden;'>";
  469. output += "<div class='channal_list' >";
  470. // output += "<a href='../wiki/wiki.php?word=" + _word;
  471. // output += "&channal=" + channalinfo.uid + "' >";
  472. switch (parseInt(channalinfo.status)) {
  473. case 10:
  474. output += "🔐";
  475. break;
  476. case 20:
  477. output += "🌐";
  478. break;
  479. case 30:
  480. output += "🌐";
  481. break;
  482. default:
  483. break;
  484. }
  485. if (parseInt(channalinfo.power) >= 20) {
  486. //if (parseInt(channalinfo.power) != 30)
  487. {
  488. output += "✏️";
  489. }
  490. }
  491. //✋
  492. output += "<a onclick=\"set_channal('" + channalinfo.uid + "')\">";
  493. output += channalinfo["name"];
  494. output += "</a>";
  495. if (parseInt(channalinfo.power) == 30) {
  496. output += "@" + gLocal.gui.your;
  497. } else {
  498. output += "@" + channalinfo["nickname"];
  499. }
  500. output += "</div>";
  501. output += "<div class='userinfo_channal'>";
  502. output += channalinfo["username"];
  503. output += "</div>";
  504. //绘制句子进度
  505. if (channalinfo["final"]) {
  506. //进度
  507. output += "<div>";
  508. let article_len = channalinfo["article_len"];
  509. let svg_width = article_len;
  510. let svg_height = parseInt(article_len / 15);
  511. output += '<svg viewBox="0 0 ' + svg_width + " " + svg_height + '" width="100%" >';
  512. let curr_x = 0;
  513. let allFinal = 0;
  514. for (const iterator of channalinfo["final"]) {
  515. let stroke_width = parseInt(iterator.len);
  516. output += "<rect ";
  517. output += ' x="' + curr_x + '"';
  518. output += ' y="0"';
  519. output += ' height="' + svg_height + '"';
  520. output += ' width="' + stroke_width + '"';
  521. if (iterator.final == true) {
  522. allFinal += stroke_width;
  523. output += ' class="progress_bar_done" ';
  524. } else {
  525. output += ' class="progress_bar_undone" ';
  526. }
  527. output += "/>";
  528. curr_x += stroke_width;
  529. }
  530. output +=
  531. "<rect x='0' y='0' width='" + svg_width + "' height='" + svg_height / 5 + "' class='progress_bar_bg' />";
  532. output +=
  533. "<rect x='0' y='0' width='" +
  534. allFinal +
  535. "' height='" +
  536. svg_height / 5 +
  537. "' class='progress_bar_percent' style='stroke-width: 0; fill: rgb(100, 228, 100);'/>";
  538. output += '<text x="0" y="' + svg_height + '" font-size="' + svg_height * 0.8 + '">';
  539. output += channalinfo["count"] + "/" + channalinfo["all"] + "@" + curr_x;
  540. output += "</text>";
  541. output += "<svg>";
  542. output += "</div>";
  543. //进度结束
  544. }
  545. output += "</div>";
  546. output += "</div>";
  547. return output;
  548. }
  549. function onChannelMultiSelectStart() {
  550. $(".channel_select").show();
  551. }
  552. function onChannelMultiSelectCancel() {
  553. $(".channel_select").hide();
  554. }
  555. function onChannelChange() {
  556. let channal_list = new Array();
  557. $("[channal_id]").each(function () {
  558. if (this.checked) {
  559. channal_list.push($(this).attr("channal_id"));
  560. }
  561. });
  562. set_channal(channal_list.join());
  563. }
  564. //点击引用 需要响应的事件
  565. function note_ref_init() {
  566. $("chapter").click(function () {
  567. let bookid = $(this).attr("book");
  568. let para = $(this).attr("para");
  569. window.open("../article/?view=chapter&book=" + bookid + "&par=" + para, "_blank");
  570. });
  571. $("para").click(function () {
  572. let bookid = $(this).attr("book");
  573. let para = $(this).attr("para");
  574. window.open("../article/?view=para&book=" + bookid + "&par=" + para, "_blank");
  575. });
  576. }
  577. /*
  578. 生成编辑模式句子块
  579. id
  580. palitext
  581. tran
  582. ref
  583. */
  584. function note_json_html(in_json) {
  585. let output = "";
  586. output += '<div class="note_tool_bar" style=" position: relative;">';
  587. output += '<div class="case_dropdown note_tool_context" >';
  588. output += "<svg class='icon' >";
  589. output += "<use xlink:href='../studio/svg/icon.svg#ic_more'></use>";
  590. output += "</svg>";
  591. output += "<div class='case_dropdown-content sent_menu'>";
  592. if (typeof _reader_view != "undefined" && _reader_view != "sent") {
  593. output += "<a onclick='junp_to(this)'>" + gLocal.gui.jump_to_this_sent + "</a>";
  594. }
  595. output +=
  596. "<a onclick='related_para_dlg_open(" +
  597. in_json.book +
  598. "," +
  599. in_json.para +
  600. ")'>" +
  601. gLocal.gui.related_para +
  602. "</a>";
  603. output +=
  604. "<a onclick='goto_nissaya(" +
  605. in_json.book +
  606. "," +
  607. in_json.para +
  608. "," +
  609. in_json.begin +
  610. "," +
  611. in_json.end +
  612. ")'>" +
  613. gLocal.gui.show_nissaya +
  614. "</a>";
  615. output +=
  616. "<a onclick=\"copy_ref('" +
  617. in_json.book +
  618. "','" +
  619. in_json.para +
  620. "','" +
  621. in_json.begin +
  622. "','" +
  623. in_json.end +
  624. "')\">" +
  625. gLocal.gui.copy_link +
  626. "</a>";
  627. output += "<a onclick='copy_text(this)'>" + gLocal.gui.copy + "“" + gLocal.gui.pāli + "”</a>";
  628. output +=
  629. "<a onclick=\"edit_in_studio('" +
  630. in_json.book +
  631. "','" +
  632. in_json.para +
  633. "','" +
  634. in_json.begin +
  635. "','" +
  636. in_json.end +
  637. "')\">" +
  638. gLocal.gui.edit_now +
  639. "</a>";
  640. output += "<a onclick='add_to_list()'>" + gLocal.gui.add_to_edit_list + "</a>";
  641. output += "<a onclick='slider_show(this)'>Slider Show</a>";
  642. output += "</div>";
  643. output += "</div>";
  644. output += " </div>";
  645. let strPalitext = render_pali_sent(in_json);
  646. output += "<div class='note_body'>";
  647. output += "<div class='palitext_div'>";
  648. output += "<div class='palitext palitext_roma'>" + strPalitext + "</div>";
  649. output += "<div class='palitext palitext1'></div>";
  650. output += "<div class='palitext palitext2'></div>";
  651. output += "</div>";
  652. //译文开始
  653. output += "<div class='sent_tran_div'>";
  654. for (const iterator of in_json.translation) {
  655. output += render_one_sent_tran_a(iterator);
  656. }
  657. output += "</div>";
  658. //译文结束
  659. output += "</div>"; /**note_body end */
  660. //工具栏开始
  661. output += "<div class='other_tran_div' sent='";
  662. output += in_json.book + "-" + in_json.para + "-" + in_json.begin + "-" + in_json.end + "' >";
  663. output += "<div class='tool_bar' sent='";
  664. output += in_json.book + "-" + in_json.para + "-" + in_json.begin + "-" + in_json.end + "' >";
  665. output += "<span class='tool_left'>";
  666. //第一个按钮
  667. //新增译文按钮开始
  668. output += "<span class='' ";
  669. output += "book='" + in_json.book + "' ";
  670. output += "para='" + in_json.para + "' ";
  671. output += "begin='" + in_json.begin + "' ";
  672. output += "end='" + in_json.end + "' ";
  673. output += " >";
  674. output += "<span class='' onclick='add_new_tran_button_click(this)' title='" + gLocal.gui.add_tran + "'>➕</span>";
  675. output += "<div class='tran_text_tool_bar'>";
  676. output += "</div>";
  677. output += "</span>";
  678. //新增译文按钮结束
  679. output += "<span class='separate_line'></span>";
  680. //第二个按钮
  681. output += "<span class='more_tran icon_expand'></span>";
  682. //其他译文工具条
  683. output += "<span class='other_bar' >";
  684. output +=
  685. "<span class='other_tran_span' title='🧲" +
  686. gLocal.gui.other +
  687. gLocal.gui.translation +
  688. "'>";
  689. output += "<svg class='icon' style='fill: var(--box-bg-color1)'>";
  690. output += "<use xlink:href='../../node_modules/bootstrap-icons/bootstrap-icons.svg#translate'>";
  691. output += "</svg>" ;
  692. output += gLocal.gui.translation ;
  693. output += "</span>";
  694. output += "<span class='other_tran_num'></span>";
  695. output += "</span>";
  696. output += "<span class='separate_line'></span>";
  697. //手工义注
  698. output += "<span class='other_bar disable'>";
  699. output +=
  700. "<span class='other_tran_span commentray' title='📔" +
  701. gLocal.gui.vannana +
  702. "'>🪔" +
  703. gLocal.gui.commentary +
  704. "</span>";
  705. output += "<span class='other_comm_num'></span>";
  706. output += "</span>";
  707. output += "<span class='separate_line'></span>";
  708. //第三个按钮 相似句
  709. if (parseInt(in_json.sim) > 0) {
  710. output += "<span class='other_bar' >";
  711. output +=
  712. "<span class='similar_sent_span' onclick=\"note_show_pali_sim('" +
  713. in_json.pali_sent_id +
  714. "')\" title='" +
  715. gLocal.gui.similar_sentences +
  716. "'>🧬" +
  717. gLocal.gui.similar +
  718. "</span>";
  719. output += "<span class='similar_sent_num'>" + in_json.sim + "</span>";
  720. output += "</span>";
  721. output += "<span class='separate_line'></span>";
  722. }
  723. //第三个按钮 相似句结束
  724. output += "</span>";
  725. output += "<span class='tool_right'>";
  726. //出处路径开始
  727. output += "<span class='ref'>";
  728. output += "<span class='book_name tooltip'>" + in_json.booktitle;
  729. output += "<span class='tooltiptext tooltip-bottom'>";
  730. output += in_json.ref;
  731. output += "</span>";
  732. output += "<span class='sent_no'>";
  733. output += in_json.book + "-" + in_json.para + "-" + in_json.begin + "-" + in_json.end;
  734. output += "<span>";
  735. output += "</span>";
  736. output += "</span>";
  737. //出处路径结束
  738. output += "</span>";
  739. output += "</div>";
  740. //工具栏结束
  741. //未选择的其他译文开始
  742. output += "<div class='other_tran'>";
  743. output += "</div>";
  744. output += "</div>";
  745. return output;
  746. }
  747. //设置取消输入框的编辑模式
  748. function sent_tran_set_edit_mode(obj, isEditMode) {
  749. $(".sent_tran").removeClass("edit_mode");
  750. if (isEditMode) {
  751. let jqObj = $(obj);
  752. while (!jqObj.hasClass("sent_tran")) {
  753. jqObj = jqObj.parent();
  754. if (!jqObj) {
  755. return;
  756. }
  757. }
  758. jqObj.addClass("edit_mode");
  759. }
  760. }
  761. function sent_tran_edit(obj) {
  762. let jqObj = $(obj);
  763. while (!jqObj.hasClass("sent_tran")) {
  764. jqObj = jqObj.parent();
  765. if (!jqObj) {
  766. return;
  767. }
  768. }
  769. if (jqObj.hasClass("edit_mode")) {
  770. jqObj.removeClass("edit_mode");
  771. } else {
  772. $(".sent_tran").removeClass("edit_mode");
  773. jqObj.addClass("edit_mode");
  774. }
  775. }
  776. //采纳 pr
  777. function sent_pr_merge(id) {
  778. $.post(
  779. "../usent/sent_pr_merge.php",
  780. {
  781. id: id,
  782. },
  783. function (data) {
  784. let result = JSON.parse(data);
  785. if (result.status > 0) {
  786. alert("error" + result.message);
  787. } else {
  788. ntf_show("成功采纳");
  789. }
  790. }
  791. );
  792. }
  793. function sent_commit(src, id) {
  794. commit_init({
  795. src: src,
  796. sent: [id],
  797. express: false,
  798. });
  799. }
  800. function render_icon_button(icon_id, event, tiptitle) {
  801. let html = "";
  802. html += "<button class='icon_btn tooltip' onclick=\"" + event + '">';
  803. html += '<svg class="icon" >';
  804. html += '<use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#' + icon_id + '"></use>';
  805. html += "</svg>";
  806. html += "<span class='tooltiptext tooltip-top'>";
  807. html += tiptitle;
  808. html += "</span>";
  809. html += "</button>";
  810. return html;
  811. }
  812. var menuFocusIndex=0;
  813. var term_data=["amanussa","anadhiṭṭhita","anantarāya","anissaṭṭha","aniyata","antaravāsaka"];
  814. var term_filterd_data=[];
  815. var term_input_text ;
  816. var term_input="";
  817. function TermRenderSentTranTextarea(text,dbId,sentId,channelId,isPr){
  818. let html="";
  819. html += '<div class="text_input" >';
  820. html += '<div class="menu"></div>';
  821. html += '<div class="textarea text_shadow"></div>';
  822. html += "<textarea class='textarea tran_sent_textarea' onfocus=\"text_input_textarea_focuse(this)\"";
  823. html += " dbid='" + dbId + "' ";
  824. html += "sid='" + sentId + "' ";
  825. html += "channel='" + channelId + "' ";
  826. if (typeof isPr != "undefined" && isPr == true) {
  827. html += ' is_pr="true" "';
  828. } else {
  829. html += 'is_pr="false"';
  830. }
  831. html += ">" ;
  832. html += text;
  833. html += "</textarea>";
  834. html += '</div>';
  835. return html;
  836. }
  837. function render_one_sent_tran_a(iterator, diff = false) {
  838. let mChannel = get_channel_by_id(iterator.channal);
  839. let tranText;
  840. let sid = iterator.book + "-" + iterator.para + "-" + iterator.begin + "-" + iterator.end;
  841. //将绝对链接转换为 用户连接的主机链接
  842. let showText = iterator.text.replace(/[A-z]*.wikipali.org/g,location.host);
  843. if (iterator.text == "") {
  844. if (typeof iterator.channalinfo == "undefined") {
  845. tranText =
  846. "<span style='color:var(--border-line-color);'>" +
  847. "空" +
  848. "@" +
  849. iterator.editor_name.nickname +
  850. "</span>";
  851. } else {
  852. tranText =
  853. "<span style='color:var(--border-line-color);'>" +
  854. iterator.channalinfo.name +
  855. "-" +
  856. iterator.channalinfo.lang +
  857. "</span>";
  858. }
  859. } else {
  860. if (diff) {
  861. let orgText = "";
  862. for (const oneSent of _arrData) {
  863. if (
  864. oneSent.book == iterator.book &&
  865. oneSent.para == iterator.para &&
  866. oneSent.begin == iterator.begin &&
  867. oneSent.end == iterator.end
  868. ) {
  869. for (const tran of oneSent.translation) {
  870. if (tran.channal == iterator.channal) {
  871. orgText = tran.text;
  872. break;
  873. }
  874. }
  875. break;
  876. }
  877. }
  878. tranText = str_diff(orgText, iterator.text);
  879. } else {
  880. //note_init处理句子链接
  881. tranText = note_init(term_std_str_to_tran(showText, iterator.channal, iterator.editor, iterator.lang));
  882. }
  883. }
  884. let html = "";
  885. html += "<div class='sent_tran ";
  886. if (typeof iterator.is_pr != "undefined" && iterator.is_pr == true) {
  887. html += " pr ";
  888. }
  889. html += "' dbid='" + iterator.id + "' channel='" + iterator.channal + "' sid='" + sid + "'>";
  890. html += "<div class='sent_tran_inner'>";
  891. html += '<div class="tool_bar">';
  892. html += ' <div class="right">';
  893. //句子菜单
  894. html += '<div class="pop_menu">';
  895. if (typeof iterator.is_pr != "undefined" && iterator.is_pr == true) {
  896. //在pr 列表中的译文
  897. if (typeof iterator.is_pr_editor != "undefined" && iterator.is_pr_editor == true) {
  898. //提交人
  899. //修改按钮
  900. html += render_icon_button("ic_mode_edit", "sent_tran_edit(this)", gLocal.gui.modify);
  901. //删除按钮
  902. html += render_icon_button("ic_delete", "sent_pr_del(this)", gLocal.gui.delete);
  903. } else {
  904. //非提交人
  905. if (parseInt(iterator.mypower) >= 20) {
  906. //有权限 采纳按钮
  907. html += render_icon_button(
  908. "accept_copy",
  909. "sent_pr_merge('" + iterator.id + "')",
  910. gLocal.gui.accept_copy
  911. );
  912. }
  913. //点赞按钮
  914. html += render_icon_button("like", "sent_pr_like(this)", gLocal.gui.like);
  915. }
  916. } else {
  917. //非pr列表里的句子
  918. //编辑按钮
  919. if (parseInt(iterator.mypower) < 20) {
  920. html += render_icon_button("my_idea", "sent_tran_edit(this)", gLocal.gui.suggest);
  921. } else {
  922. html += render_icon_button("ic_mode_edit", "sent_tran_edit(this)", gLocal.gui.edit);
  923. }
  924. //推送按钮
  925. let commitIcon = "";
  926. let commitTipText = "";
  927. if (parseInt(iterator.mypower) >= 30 && parseInt(iterator.status) < 30) {
  928. //我的私有资源 公开发布
  929. commitIcon = "publish";
  930. commitTipText = gLocal.gui.publish;
  931. } else {
  932. if (parseInt(iterator.mypower) < 20) {
  933. //只读资源 采纳
  934. commitIcon = "accept_copy";
  935. commitTipText = gLocal.gui.accept_copy;
  936. } else {
  937. //其他资源 复制到
  938. commitIcon = "copy";
  939. commitTipText = gLocal.gui.copy_to;
  940. }
  941. }
  942. html += render_icon_button(commitIcon, "sent_commit('" + iterator.channal + "','" + sid + "')", commitTipText);
  943. //推送按钮结束
  944. //更多按钮
  945. html += '<div class="case_dropdown">';
  946. html += "<button class='icon_btn'>";
  947. html += '<svg class="icon" >';
  948. html += '<use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#ic_more"></use>';
  949. html += "</svg>";
  950. html += "</button>";
  951. html += '<div class="case_dropdown-content menu_space_between" style="right:0;">';
  952. //时间线
  953. html += "<a onclick=\"history_show('" + iterator.id + "')\">";
  954. html += "<span>" + gLocal.gui.timeline + "</span>";
  955. html += '<svg class="icon" >';
  956. html += '<use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#recent_scan"></use>';
  957. html += "</svg>";
  958. html += "</a>";
  959. //复制
  960. html += "<a onclick=\"history_show('" + iterator.id + "')\">";
  961. html += "<span>" + gLocal.gui.copy + "</span>";
  962. html += '<svg class="icon" >';
  963. html += '<use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#copy"></use>';
  964. html += "</svg>";
  965. html += "</a>";
  966. //点赞
  967. html += "<a onclick=\"history_show('" + iterator.id + "')\">";
  968. html += "<span>" + gLocal.gui.like + "</span>";
  969. html += '<svg class="icon" >';
  970. html += '<use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#like"></use>';
  971. html += "</svg>";
  972. html += "</a>";
  973. //分享
  974. html += "<a onclick=\"history_show('" + iterator.id + "')\">";
  975. html += "<span>" + gLocal.gui.share_to + "</span>";
  976. html += '<svg class="icon" >';
  977. html += '<use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#share_to"></use>';
  978. html += "</svg>";
  979. html += "</a>";
  980. html += "</div>";
  981. html += "</div>";
  982. //更多按钮结束
  983. }
  984. html += "</div>";
  985. //句子菜单结束
  986. html += "</div>";
  987. html += "</div>";
  988. //tool_bar 结束
  989. html += '<div class="left_bar" >';
  990. html += "<span class='icon_sent_status icon_sent_loading'>";
  991. html +=
  992. "<svg class='icon icon_spin' style='fill: var(--detail-color); '>" +
  993. "<use xlink='http://www.w3.org/1999/xlink' href='../studio/svg/icon.svg#loading'></use>" +
  994. "</svg>";
  995. html += "</span>";
  996. html += "<span class='icon_sent_status icon_sent_error' title='再次发送' onclick='tran_sent_save(this)'>";
  997. html +=
  998. "<svg class='icon' style='fill: red; '>" +
  999. "<use xlink='http://www.w3.org/1999/xlink' href='../term/error.svg'></use>" +
  1000. "</svg>";
  1001. html += "</span>";
  1002. html += ' <div class="face">';
  1003. if (iterator.id != "") {
  1004. html += '<span class="head_img">' + iterator.editor_name.nickname.slice(0, 1) + "</span>";
  1005. }
  1006. html += "</div>";
  1007. html +=
  1008. '<div class="date" title="' +
  1009. getFullDataTime(iterator.update_time) +
  1010. '">' +
  1011. getDataTime(iterator.update_time) +
  1012. "</div>";
  1013. html += "</div>";
  1014. html += '<div class="body">';
  1015. html += '<div class="head_bar">';
  1016. html += '<div class="info">';
  1017. html += '<span class="name channel_name" title="' + iterator.editor_name.nickname + gLocal.gui.recent_update + '">';
  1018. if (typeof iterator.channalinfo == "undefined") {
  1019. html += "unkown";
  1020. } else {
  1021. html += iterator.channalinfo.name;
  1022. }
  1023. html += "</span>";
  1024. html += '<span class="name editor_name" ';
  1025. if (typeof iterator.channalinfo == "undefined") {
  1026. html += ">";
  1027. html += "unkown";
  1028. } else {
  1029. html += 'title="' + iterator.channalinfo.name + gLocal.gui.recent_update + '">';
  1030. html += iterator.editor_name.nickname;
  1031. }
  1032. html += "</span>";
  1033. html += '<span class="date">' + getPassDataTime(iterator.update_time) + "</span>";
  1034. html += "</div>";
  1035. html += "<div class='preview'>" + tranText + "</div>";
  1036. html += "</div>";
  1037. html += '<div class="edit">';
  1038. html += '<div class="input">';
  1039. //输入框
  1040. html += TermRenderSentTranTextarea(iterator.text,iterator.id,sid,iterator.channal,iterator.is_pr);
  1041. html += "</div>";
  1042. html += '<div class="edit_tool">';
  1043. //html += ""
  1044. html += '<span style="display: inline-flex;">';
  1045. html += '<span class="keybutton" >ESC</span> = ';
  1046. html += "<a onclick='tran_sent_edit_cancel(this)'>" + gLocal.gui.cancel + "</a>";
  1047. html += "</span>";
  1048. html += "<span style='display: inline-flex;'>";
  1049. html += '<span class="keybutton" >Ctrl/⌘</span>';
  1050. html += "➕";
  1051. html += '<span class="keybutton" >Enter</span> = ';
  1052. if (parseInt(iterator.mypower) < 20) {
  1053. html += "<a onclick='tran_sent_save(this)'>";
  1054. html += gLocal.gui.submit + "<b>" + gLocal.gui.suggest + gLocal.gui.translation + "</b>";
  1055. html += "</a></span><span style='display: inline-flex;'>";
  1056. } else {
  1057. html += "<a onclick='tran_sent_save(this)'>";
  1058. html += gLocal.gui.save;
  1059. html += "</a></span><span style='display: inline-flex;'>";
  1060. }
  1061. html += '<span class="keybutton" >Enter</span> = ';
  1062. html += gLocal.gui.next_line;
  1063. html += "</span><span style='display: inline-flex;'>MarkDown✅</span>";
  1064. html += "</div>";
  1065. html += "</div>";
  1066. html += '<div class="foot_bar">';
  1067. html += '<div class="info">';
  1068. if (iterator.id != "") {
  1069. html += '<span class="date"> ' + getPassDataTime(iterator.update_time) + "</span>";
  1070. }
  1071. if (iterator.id != "") {
  1072. html += '<span class="name">' + iterator.editor_name.nickname + "</span>";
  1073. }
  1074. if (iterator.id != "") {
  1075. html += '<span class="channel">' + gLocal.gui.updated + " ";
  1076. if (typeof iterator.channalinfo == "undefined") {
  1077. html += "unkown";
  1078. } else {
  1079. html += "<a title='" + iterator.channalinfo.summary + "'>" + iterator.channalinfo.name + "@</a>";
  1080. }
  1081. html += "</span>";
  1082. } else {
  1083. html += '<span class="channel">' + gLocal.gui.no_updated + " @";
  1084. if (typeof iterator.channalinfo == "undefined") {
  1085. html += "unkown";
  1086. } else {
  1087. html += "<a title='" + iterator.channalinfo.owner + "'>" + iterator.channalinfo.name + "@</a>";
  1088. }
  1089. html += "</span>";
  1090. }
  1091. html += '<ul class="tag_list">';
  1092. if (iterator.pr_all && parseInt(iterator.pr_all) > 0) {
  1093. html +=
  1094. "<li onclick=\"note_pr_show('" +
  1095. iterator.channal +
  1096. "','" +
  1097. sid +
  1098. "')\"><span class='icon'>✋</span><span class='num'>" +
  1099. iterator.pr_new +
  1100. "/" +
  1101. iterator.pr_all +
  1102. "</span></li>";
  1103. }
  1104. html += "</ul>";
  1105. html += "</div>"; //end of info
  1106. html += "</div>"; //end of foot bar
  1107. html += "</div>";
  1108. html += "</div>";
  1109. //sent_tran_inner结束
  1110. html += '<div class="pr_content"></div>';
  1111. html += "</div>";
  1112. return html;
  1113. }
  1114. function tran_sent_textarea_event_init() {
  1115. let textarea = document.querySelectorAll(".tran_sent_textarea");
  1116. for (let iterator of textarea) {
  1117. iterator.onkeydown = function (e) {
  1118. let menu = document.querySelector("#menu");
  1119. switch (e.key) {
  1120. case "Enter":
  1121. if (menu && menu.style.display == "block") {
  1122. let value = textarea.value;
  1123. let selectionStart = textarea.selectionStart;
  1124. let str1 = value.slice(0, selectionStart);
  1125. let str2 = value.slice(selectionStart);
  1126. textarea.value = str1 + data[menuFocusIndex] + "]]" + str2;
  1127. menu.style.display = "none";
  1128. return false;
  1129. } else {
  1130. if (e.ctrlKey) {
  1131. //回车存盘
  1132. tran_sent_save(e.currentTarget);
  1133. return false;
  1134. }
  1135. }
  1136. break;
  1137. case "Escape":
  1138. tran_sent_edit_cancel(e.currentTarget);
  1139. break;
  1140. default:
  1141. break;
  1142. }
  1143. };
  1144. }
  1145. }
  1146. function render_one_sent_tran(book, para, begin, end, iterator) {
  1147. let output = "";
  1148. output += "<div class='tran' lang='" + iterator.lang + "' style='display:flex;'>";
  1149. //译文工具按钮开始
  1150. output += "<div class='tran_text_tool_botton' onclick='tool_bar_show(this)'>";
  1151. output +=
  1152. "<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>";
  1153. //译文工具栏开始
  1154. output += "<div class='tran_text_tool_bar'>";
  1155. output += "<div style='border-right: solid 1px;margin: 0.3em 0;'><li class = 'tip_buttom' ";
  1156. output +=
  1157. " onclick=\"note_edit_sentence('" +
  1158. book +
  1159. "' ,'" +
  1160. para +
  1161. "' ,'" +
  1162. begin +
  1163. "' ,'" +
  1164. end +
  1165. "' ,'" +
  1166. iterator.channal +
  1167. "')\"";
  1168. output +=
  1169. ">" +
  1170. '<svg class="icon" ><use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#ic_mode_edit"></use></svg>';
  1171. output += gLocal.gui.edit + "</li>";
  1172. output += "<li class = 'tip_buttom' ";
  1173. output += " onclick=\"history_show('" + iterator.id + "')\" >";
  1174. output +=
  1175. '<svg class="icon" ><use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#recent_scan"></use></svg>';
  1176. output += gLocal.gui.timeline + "</li>";
  1177. output +=
  1178. "<li class = 'tip_buttom'>" +
  1179. '<svg class="icon" ><use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#copy"></use></svg>';
  1180. output += gLocal.gui.copy + "</li></div>";
  1181. output +=
  1182. "<div style='border-right: solid 1px;margin: 0.3em 0;'><li class = 'tip_buttom'>" +
  1183. '<svg class="icon" ><use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#like"></use></svg>';
  1184. output += gLocal.gui.like + "</li>";
  1185. output +=
  1186. "<li class = 'tip_buttom'>" +
  1187. '<svg class="icon" ><use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#comment"></use></svg>';
  1188. output += gLocal.gui.comment + "</li>";
  1189. output +=
  1190. "<li class = 'tip_buttom'>" +
  1191. '<svg class="icon" ><use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#ic_shopping_cart"></use></svg>';
  1192. output += gLocal.gui.digest + "</li></div>";
  1193. output +=
  1194. "<div style='margin: 0.3em 0;'><li class = 'tip_buttom'>" +
  1195. '<svg class="icon" ><use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#share_to"></use></svg>';
  1196. output += gLocal.gui.share_to + "</li>";
  1197. output += "</div></div>";
  1198. //译文工具栏结束
  1199. output += "</div>";
  1200. //译文工具按钮结束
  1201. //译文正文开始
  1202. output +=
  1203. "<div class='text' id='tran_text_" +
  1204. book +
  1205. "_" +
  1206. para +
  1207. "_" +
  1208. begin +
  1209. "_" +
  1210. end +
  1211. "_" +
  1212. iterator.channal +
  1213. "'>";
  1214. if (iterator.text == "") {
  1215. output +=
  1216. "<span style='color:var(--border-line-color);'>" +
  1217. iterator.channalinfo.name +
  1218. "-" +
  1219. iterator.channalinfo.lang +
  1220. "</span>";
  1221. } else {
  1222. //note_init处理句子链接
  1223. output += note_init(term_std_str_to_tran(iterator.text, iterator.channal, iterator.editor, iterator.lang));
  1224. }
  1225. output += "</div>";
  1226. //译文正文结束
  1227. output += "</div>";
  1228. //单个channal译文框结束
  1229. return output;
  1230. }
  1231. function hidden_control(obj) {
  1232. if ($(".lang_2")[0].style.display == "none" && $(".lang_3")[0].style.display == "none") {
  1233. $(".lang_2").show();
  1234. $(".lang_3").show();
  1235. obj.innerHTML = "⬅"
  1236. }
  1237. else {
  1238. $(".lang_2").hide();
  1239. $(".lang_3").hide();
  1240. obj.innerHTML = "➡"
  1241. }
  1242. }
  1243. function add_new_tran_button_click(obj) {
  1244. let html = "<div style='display:flex; max-width: 70vw; white-space: normal;'>";
  1245. var first_lang = "";
  1246. for (const iterator of _my_channal) {
  1247. if (iterator.lang) {
  1248. first_lang = iterator.lang;
  1249. break;
  1250. }
  1251. }
  1252. //母语channel列表
  1253. html += "<ul class='channel_list lang_0' >";
  1254. html += "<li>";
  1255. html += gLocal.language[first_lang];
  1256. html += "</li>";
  1257. for (const iterator of _my_channal) {
  1258. if (iterator.status > 0 && first_lang.indexOf(iterator.lang) != -1 && iterator.lang != 0) {
  1259. if (_channal.indexOf(iterator.id) < 0) {
  1260. html += '<li class="channel_name" onclick="';
  1261. html +=
  1262. "new_sentence('" +
  1263. $(obj).parent().attr("book") +
  1264. "' ,'" +
  1265. $(obj).parent().attr("para") +
  1266. "' ,'" +
  1267. $(obj).parent().attr("begin") +
  1268. "' ,'" +
  1269. $(obj).parent().attr("end") +
  1270. "' ,'" +
  1271. iterator.id +
  1272. "',this)";
  1273. html += '" title="' + iterator.nickname;
  1274. html += '">' + iterator.name;
  1275. if (parseInt(iterator.power) < 20) {
  1276. html += "(建议)";
  1277. }
  1278. html += "</li>";
  1279. }
  1280. }
  1281. }
  1282. html += "<li><a href='../channal/my_channal_index.php' target='_blank'><button>" + gLocal.gui.new + "&nbsp;" + gLocal.gui.channel + "</button></a></li>"
  1283. html += "</ul>";
  1284. //非母语channel列表
  1285. html += "<ul class='channel_list lang_1'>";
  1286. html += "<li>";
  1287. html += gLocal.gui.other;
  1288. html += "&nbsp;<button style='height: 1.8em;' onmouseover='hidden_control(this)'>➡</button>"
  1289. html += "</li>";
  1290. for (const iterator of _my_channal) {
  1291. if (iterator.status > 0 && first_lang.indexOf(iterator.lang) == -1 && iterator.lang != 0) {
  1292. if (_channal.indexOf(iterator.id) < 0) {
  1293. html += '<li class="channel_name" onclick="';
  1294. html +=
  1295. "new_sentence('" +
  1296. $(obj).parent().attr("book") +
  1297. "' ,'" +
  1298. $(obj).parent().attr("para") +
  1299. "' ,'" +
  1300. $(obj).parent().attr("begin") +
  1301. "' ,'" +
  1302. $(obj).parent().attr("end") +
  1303. "' ,'" +
  1304. iterator.id +
  1305. "',this)";
  1306. html += '" title="' + iterator.nickname;
  1307. html += '">' + iterator.name;
  1308. if (parseInt(iterator.power) < 20) {
  1309. html += "(建议)";
  1310. }
  1311. html += "</li>";
  1312. }
  1313. }
  1314. }
  1315. html += "</ul>";
  1316. //协作channel列表-带中文
  1317. html += "<ul class='channel_list lang_2' style='display:none;'>";
  1318. html += "<li>";
  1319. html += "协作";
  1320. html += "</li>";
  1321. for (const iterator of _my_channal) {
  1322. if (iterator.status > 0 && iterator.lang == 0 && checkStringIsChinese(iterator.name) == true) {
  1323. if (_channal.indexOf(iterator.id) < 0) {
  1324. html += '<li class="channel_name" onclick="';
  1325. html +=
  1326. "new_sentence('" +
  1327. $(obj).parent().attr("book") +
  1328. "' ,'" +
  1329. $(obj).parent().attr("para") +
  1330. "' ,'" +
  1331. $(obj).parent().attr("begin") +
  1332. "' ,'" +
  1333. $(obj).parent().attr("end") +
  1334. "' ,'" +
  1335. iterator.id +
  1336. "',this)";
  1337. html += '" title="' + iterator.nickname;
  1338. html += '">' + iterator.name;
  1339. if (parseInt(iterator.power) < 20) {
  1340. html += "(建议)";
  1341. }
  1342. html += "</li>";
  1343. }
  1344. }
  1345. }
  1346. html += "</ul>";
  1347. //协作channel列表-不带中文
  1348. html += "<ul class='channel_list lang_3' style='display:none;'>";
  1349. html += "<li>";
  1350. html += "collaborate";
  1351. html += "</li>";
  1352. for (const iterator of _my_channal) {
  1353. if (iterator.status > 0 && iterator.lang == 0 && checkStringIsChinese(iterator.name) == false) {
  1354. if (_channal.indexOf(iterator.id) < 0) {
  1355. html += '<li class="channel_name" onclick="';
  1356. html +=
  1357. "new_sentence('" +
  1358. $(obj).parent().attr("book") +
  1359. "' ,'" +
  1360. $(obj).parent().attr("para") +
  1361. "' ,'" +
  1362. $(obj).parent().attr("begin") +
  1363. "' ,'" +
  1364. $(obj).parent().attr("end") +
  1365. "' ,'" +
  1366. iterator.id +
  1367. "',this)";
  1368. html += '" title="' + iterator.nickname;
  1369. html += '">' + iterator.name;
  1370. if (parseInt(iterator.power) < 20) {
  1371. html += "(建议)";
  1372. }
  1373. html += "</li>";
  1374. }
  1375. }
  1376. }
  1377. html += "</ul>";
  1378. html += "</div>";
  1379. $(obj).parent().children(".tran_text_tool_bar").first().html(html);
  1380. if ($(obj).parent().children(".tran_text_tool_bar").css("display") == "block") {
  1381. $(obj).parent().children(".tran_text_tool_bar").first().hide();
  1382. } else {
  1383. $(obj).parent().children(".tran_text_tool_bar").first().show();
  1384. $(document).one("click", function () {
  1385. $(obj).parent().children(".tran_text_tool_bar").first().hide();
  1386. });
  1387. event.stopPropagation();
  1388. $(obj).parent().show();
  1389. }
  1390. }
  1391. function checkStringIsChinese(str) {
  1392. var pattern = new RegExp("[\u4E00-\u9FA5]+");
  1393. if (pattern.test(str)) {
  1394. return true;
  1395. }
  1396. return false;
  1397. }
  1398. function tool_bar_show(element) {
  1399. if ($(element).find(".tran_text_tool_bar").css("display") == "none") {
  1400. $(element).find(".tran_text_tool_bar").css("display", "flex");
  1401. $(element).find(".icon_expand").css("transform", "rotate(-180deg)");
  1402. $(element).css("background-color", "var(--btn-bg-color)");
  1403. $(element).css("visibility", "visible");
  1404. $(document).one("click", function () {
  1405. $(element).find(".tran_text_tool_bar").hide();
  1406. $(element).css("background-color", "var(--nocolor)");
  1407. $(element).find(".icon_expand").css("transform", "unset");
  1408. $(element).css("visibility", "");
  1409. });
  1410. event.stopPropagation();
  1411. } else {
  1412. $(element).find(".tran_text_tool_bar").hide();
  1413. $(element).css("background-color", "var(--nocolor)");
  1414. $(element).find(".icon_expand").css("transform", "unset");
  1415. $(element).css("visibility", "");
  1416. }
  1417. }
  1418. function new_sentence(book, para, begin, end, channel, obj) {
  1419. let newsent = { id: "", text: "", lang: "", channal: channel };
  1420. for (let iterator of _arrData) {
  1421. if (iterator.book == book && iterator.para == para && iterator.begin == begin && iterator.end == end) {
  1422. let found = false;
  1423. for (const tran of iterator.translation) {
  1424. if (tran.channal == channel) {
  1425. found = true;
  1426. break;
  1427. }
  1428. }
  1429. if (!found) {
  1430. iterator.translation.push(newsent);
  1431. }
  1432. }
  1433. }
  1434. if ($(obj).parent().parent().css("display") == "block") {
  1435. $(obj).parent().parent().hide();
  1436. }
  1437. note_edit_sentence(book, para, begin, end, channel);
  1438. }
  1439. //显示更多译文按钮动作
  1440. function set_more_button_display() {
  1441. $(".other_tran_div").each(function () {
  1442. const sentid = $(this).attr("sent").split("-");
  1443. const book = sentid[0];
  1444. const para = sentid[1];
  1445. const begin = sentid[2];
  1446. const end = sentid[3];
  1447. let count = 0;
  1448. for (const iterator of _channalData) {
  1449. if (iterator.final) {
  1450. for (const onesent of iterator.final) {
  1451. let id = onesent.id.split("-");
  1452. if (book == id[0] && para == id[1] && begin == id[2] && end == id[3] && onesent.final) {
  1453. if (_channal.indexOf(iterator.id) == -1) {
  1454. count++;
  1455. }
  1456. }
  1457. }
  1458. }
  1459. }
  1460. if (count > 0) {
  1461. $(this).find(".other_tran_num").html(count);
  1462. $(this).find(".other_tran_num").attr("style", "display:inline-flex;");
  1463. $(this)
  1464. .find(".other_bar")
  1465. .click(function () {
  1466. const sentid = $(this).parent().parent().attr("sent").split("-");
  1467. const book = sentid[0];
  1468. const para = sentid[1];
  1469. const begin = sentid[2];
  1470. const end = sentid[3];
  1471. let sentId = $(this).parent().parent().attr("sent");
  1472. if ($(this).parent().parent().siblings(".other_tran").first().css("display") == "none") {
  1473. $(".other_tran_div[sent='" + sentId + "']")
  1474. .children(".other_tran")
  1475. .slideDown();
  1476. $(this).siblings(".more_tran ").css("transform", "unset");
  1477. $.get(
  1478. "../usent/get.php",
  1479. {
  1480. book: book,
  1481. para: para,
  1482. begin: begin,
  1483. end: end,
  1484. },
  1485. function (data, status) {
  1486. let arrSent = JSON.parse(data);
  1487. let html = "<div class='compact'>";
  1488. for (const iterator of arrSent) {
  1489. if (_channal.indexOf(iterator.channal) == -1) {
  1490. html += render_one_sent_tran_a(iterator);
  1491. }
  1492. }
  1493. html += "</div>";
  1494. let sentId =
  1495. arrSent[0].book +
  1496. "-" +
  1497. arrSent[0].paragraph +
  1498. "-" +
  1499. arrSent[0].begin +
  1500. "-" +
  1501. arrSent[0].end;
  1502. $(".other_tran_div[sent='" + sentId + "']")
  1503. .children(".other_tran")
  1504. .html(html);
  1505. //初始化文本编辑框消息处理
  1506. tran_sent_textarea_event_init();
  1507. }
  1508. );
  1509. } else {
  1510. $(".other_tran_div[sent='" + sentId + "']")
  1511. .children(".other_tran")
  1512. .slideUp();
  1513. $(this).siblings(".more_tran ").css("transform", "rotate(-90deg)");
  1514. }
  1515. });
  1516. } else {
  1517. //隐藏自己
  1518. //$(this).hide();
  1519. $(this).find(".other_tran_span").addClass("disable"); //gLocal.gui.no + gLocal.gui.other + gLocal.gui.translation
  1520. //$(this).find(".more_tran").hide();
  1521. }
  1522. });
  1523. }
  1524. function note_edit_sentence(book, para, begin, end, channal) {
  1525. let channalInfo;
  1526. for (const iterator of _channalData) {
  1527. if (iterator.id == channal) {
  1528. channalInfo = iterator;
  1529. break;
  1530. }
  1531. }
  1532. for (const iterator of _arrData) {
  1533. if (iterator.book == book && iterator.para == para && iterator.begin == begin && iterator.end == end) {
  1534. for (const tran of iterator.translation) {
  1535. if (tran.channal == channal) {
  1536. let html = "";
  1537. html += "<div style='color:blue;'>" + channalInfo.name + "@" + channalInfo.nickname + "</div>";
  1538. html +=
  1539. "<textarea id='edit_dialog_text' sent_id='" +
  1540. tran.id +
  1541. "' book='" +
  1542. book +
  1543. "' para='" +
  1544. para +
  1545. "' begin='" +
  1546. begin +
  1547. "' end='" +
  1548. end +
  1549. "' channal='" +
  1550. channal +
  1551. "' style='width:100%;min-height:260px;'>" +
  1552. tran.text +
  1553. "</textarea>";
  1554. $("#edit_dialog_content").html(html);
  1555. $("#note_sent_edit_dlg").dialog("open");
  1556. return;
  1557. }
  1558. }
  1559. }
  1560. }
  1561. alert("未找到句子");
  1562. }
  1563. function tran_sent_edit_cancel(obj) {
  1564. sent_tran_set_edit_mode(obj, false);
  1565. }
  1566. function tran_sent_save(obj) {
  1567. let sentDiv = find_sent_tran_div(obj);
  1568. if (sentDiv) {
  1569. let textarea = $(sentDiv).children().find(".tran_sent_textarea").first();
  1570. let isPr = $(textarea).attr("is_pr");
  1571. if (isPr == "true") {
  1572. note_pr_save(textarea);
  1573. } else {
  1574. note_sent_save_a(textarea);
  1575. }
  1576. sent_tran_set_edit_mode(textarea, false);
  1577. } else {
  1578. console.error("sent div not found");
  1579. }
  1580. }
  1581. //保存pr句子 新
  1582. function note_pr_save(obj) {
  1583. let id = $(obj).attr("dbid");
  1584. let sid = $(obj).attr("sid").split("-");
  1585. let book = sid[0];
  1586. let para = sid[1];
  1587. let begin = sid[2];
  1588. let end = sid[3];
  1589. let channel = $(obj).attr("channel");
  1590. let text = $(obj).val();
  1591. let sent_tran_div = find_sent_tran_div(obj);
  1592. $.post(
  1593. "../usent/pr_post.php",
  1594. {
  1595. id: id,
  1596. book: book,
  1597. para: para,
  1598. begin: begin,
  1599. end: end,
  1600. channel: channel,
  1601. text: text,
  1602. },
  1603. sent_save_callback
  1604. );
  1605. if (sent_tran_div) {
  1606. $(sent_tran_div).addClass("loading");
  1607. }
  1608. }
  1609. //保存译文句子 新
  1610. function note_sent_save_a(obj) {
  1611. let id = $(obj).attr("dbid");
  1612. let sid = $(obj).attr("sid").split("-");
  1613. let book = sid[0];
  1614. let para = sid[1];
  1615. let begin = sid[2];
  1616. let end = sid[3];
  1617. let channal = $(obj).attr("channel");
  1618. let text = $(obj).val();
  1619. let sent_tran_div = find_sent_tran_div(obj);
  1620. $.ajaxSetup({
  1621. timeout: 5000,
  1622. });
  1623. $.post("../usent/sent_post.php", {
  1624. id: id,
  1625. book: book,
  1626. para: para,
  1627. begin: begin,
  1628. end: end,
  1629. channal: channal,
  1630. text: text,
  1631. lang: "zh",
  1632. })
  1633. .done(function (data) {
  1634. sent_save_callback(data);
  1635. })
  1636. .fail(function (xhr, error, data) {
  1637. let sid = book + "-" + para + "-" + begin + "-" + end;
  1638. let sent_tran_div = $(".sent_tran[channel='" + channal + "'][sid='" + sid + "']");
  1639. if (sent_tran_div) {
  1640. sent_tran_div.removeClass("loading");
  1641. sent_tran_div.addClass("error");
  1642. }
  1643. switch (error) {
  1644. case "timeout":
  1645. alert("服务器长时间没有回应。请稍后重试。");
  1646. break;
  1647. case "error":
  1648. alert("与服务器通讯失败,您可能没有连接到网络。请稍后重试。");
  1649. break;
  1650. case "notmodified":
  1651. break;
  1652. default:
  1653. break;
  1654. }
  1655. });
  1656. if (sent_tran_div) {
  1657. $(sent_tran_div).addClass("loading");
  1658. $(sent_tran_div).removeClass("error");
  1659. }
  1660. }
  1661. function update_sent_tran(sentData) {}
  1662. function sent_save_callback(data) {
  1663. let result;
  1664. try {
  1665. result = JSON.parse(data);
  1666. } catch (e) {
  1667. alert(e.message);
  1668. console.error('sent_save_callback',data);
  1669. return;
  1670. }
  1671. if (result.status > 0) {
  1672. alert("error" + result.message);
  1673. } else {
  1674. let sid = result.book + "-" + result.para + "-" + result.begin + "-" + result.end;
  1675. let sent_tran_div = $(
  1676. ".sent_tran[dbid='" + result.id + "'][channel='" + result.channal + "'][sid='" + sid + "']"
  1677. );
  1678. if (sent_tran_div) {
  1679. sent_tran_div.removeClass("loading");
  1680. }
  1681. if (result.commit_type == 1 || result.commit_type == 2) {
  1682. ntf_show("成功修改");
  1683. if (sent_tran_div) {
  1684. let divPreview = sent_tran_div.find(".preview").first();
  1685. if (result.text == "") {
  1686. let channel_info = "Empty";
  1687. let thisChannel = find_channal(result.channal);
  1688. if (thisChannel) {
  1689. channel_info = thisChannel.name + "-" + thisChannel.nickname;
  1690. }
  1691. divPreview.html("<span style='color:var(--border-line-color);'>" + channel_info + "</span>");
  1692. } else {
  1693. divPreview.html(
  1694. marked(term_std_str_to_tran(result.text, result.channal, result.editor, result.lang))
  1695. );
  1696. term_updata_translation();
  1697. popup_init();
  1698. for (const iterator of _arrData) {
  1699. if (
  1700. iterator.book == result.book &&
  1701. iterator.para == result.para &&
  1702. iterator.begin == result.begin &&
  1703. iterator.end == result.end
  1704. ) {
  1705. for (const tran of iterator.translation) {
  1706. if (tran.channal == result.channal) {
  1707. tran.text = result.text;
  1708. break;
  1709. }
  1710. }
  1711. }
  1712. }
  1713. }
  1714. }
  1715. } else if (result.commit_type == 3) {
  1716. ntf_show("已经提交修改建议");
  1717. } else {
  1718. ntf_show("未提交");
  1719. }
  1720. }
  1721. }
  1722. //保存译文句子
  1723. function note_sent_save() {
  1724. let id = $("#edit_dialog_text").attr("sent_id");
  1725. let book = $("#edit_dialog_text").attr("book");
  1726. let para = $("#edit_dialog_text").attr("para");
  1727. let begin = $("#edit_dialog_text").attr("begin");
  1728. let end = $("#edit_dialog_text").attr("end");
  1729. let channal = $("#edit_dialog_text").attr("channal");
  1730. let text = $("#edit_dialog_text").val();
  1731. $.post(
  1732. "../usent/sent_post.php",
  1733. {
  1734. id: id,
  1735. book: book,
  1736. para: para,
  1737. begin: begin,
  1738. end: end,
  1739. channal: channal,
  1740. text: text,
  1741. lang: "zh",
  1742. },
  1743. function (data) {
  1744. let result = JSON.parse(data);
  1745. if (result.status > 0) {
  1746. alert("error" + result.message);
  1747. } else {
  1748. if (result.commit_type == 1 || result.commit_type == 2) {
  1749. ntf_show("成功修改");
  1750. if (result.text == "") {
  1751. let channel_info = "Empty";
  1752. let thisChannel = find_channal(result.channal);
  1753. if (thisChannel) {
  1754. channel_info = thisChannel.name + "-" + thisChannel.nickname;
  1755. }
  1756. $(
  1757. "#tran_text_" +
  1758. result.book +
  1759. "_" +
  1760. result.para +
  1761. "_" +
  1762. result.begin +
  1763. "_" +
  1764. result.end +
  1765. "_" +
  1766. result.channal
  1767. ).html("<span style='color:var(--border-line-color);'>" + channel_info + "</span>");
  1768. } else {
  1769. $(
  1770. "#tran_text_" +
  1771. result.book +
  1772. "_" +
  1773. result.para +
  1774. "_" +
  1775. result.begin +
  1776. "_" +
  1777. result.end +
  1778. "_" +
  1779. result.channal
  1780. ).html(marked(term_std_str_to_tran(result.text, result.channal, result.editor, result.lang)));
  1781. term_updata_translation();
  1782. for (const iterator of _arrData) {
  1783. if (
  1784. iterator.book == result.book &&
  1785. iterator.para == result.para &&
  1786. iterator.begin == result.begin &&
  1787. iterator.end == result.end
  1788. ) {
  1789. for (const tran of iterator.translation) {
  1790. if (tran.channal == result.channal) {
  1791. tran.text = result.text;
  1792. break;
  1793. }
  1794. }
  1795. }
  1796. }
  1797. }
  1798. } else if (result.commit_type == 3) {
  1799. ntf_show("已经提交修改建议");
  1800. } else {
  1801. ntf_show("未提交");
  1802. }
  1803. }
  1804. }
  1805. );
  1806. }
  1807. function copy_ref(book, para, begin, end) {
  1808. let strRef = "{{" + book + "-" + para + "-" + begin + "-" + end + "}}";
  1809. copy_to_clipboard(strRef);
  1810. }
  1811. function goto_nissaya(book, para, begin = 0, end = 0) {
  1812. window.open("../nissaya/index.php?book=" + book + "&par=" + para + "&begin=" + begin + "&end=" + end, "nissaya");
  1813. }
  1814. function edit_in_studio(book, para, begin, end) {
  1815. wbw_channal_list_open(book, [para]);
  1816. }
  1817. //显示和隐藏某个内容 如 巴利文
  1818. function setVisibility(key, value) {
  1819. switch (key) {
  1820. case "palitext":
  1821. if ($(value).is(":checked")) {
  1822. $(".palitext").show();
  1823. } else {
  1824. $(".palitext").hide();
  1825. }
  1826. break;
  1827. default:
  1828. break;
  1829. }
  1830. }
  1831. function note_show_pali_sim(SentId) {
  1832. pali_sim_dlg_open(SentId, 0, 20);
  1833. }
  1834. function set_pali_script(pos, script) {
  1835. if (script == "none") {
  1836. $(".palitext" + pos).html("");
  1837. } else {
  1838. $(".palitext" + pos).each(function () {
  1839. let html = $(this).siblings(".palitext_roma").first().html();
  1840. $(this).html(html);
  1841. });
  1842. $(".palitext" + pos)
  1843. .find("*")
  1844. .contents()
  1845. .filter(function () {
  1846. return this.nodeType != 1;
  1847. })
  1848. .wrap("<pl" + pos + "></pl" + pos + ">");
  1849. $(".palitext" + pos)
  1850. .contents()
  1851. .filter(function () {
  1852. return this.nodeType != 1;
  1853. })
  1854. .wrap("<pl" + pos + "></pl" + pos + ">");
  1855. $("pl" + pos).html(function (index, oldcontent) {
  1856. switch(script){
  1857. case "မြန်မာ":
  1858. return roman_to_my(oldcontent);
  1859. case "My2Roman":
  1860. return my_to_roman(oldcontent);
  1861. case "සිංහල":
  1862. return roman_to_si(oldcontent);
  1863. case "ᨲ᩠ᩅᩫᨴᩱ᩠ᨿᨵᨾ᩠ᨾ᩼":
  1864. return roman_to_tai(oldcontent);
  1865. case "อักษรไทย":
  1866. return roman_to_thai(oldcontent);
  1867. default:
  1868. return(oldcontent);
  1869. }
  1870. });
  1871. }
  1872. }
  1873. function splite_pali_word() {
  1874. $("pali")
  1875. .contents()
  1876. .filter(function () {
  1877. return this.nodeType != 1;
  1878. })
  1879. .wrap("<pl></pl>");
  1880. $("pl").each(function () {
  1881. let html = $(this).html();
  1882. $(this).html("<w>" + html.replace(/\s/g, "</w> <w>") + "</w>");
  1883. });
  1884. $("w").click(function () {
  1885. let word = com_getPaliReal($(this).text());
  1886. if (gBuildinDictIsOpen) {
  1887. window.open("../dict/index.php?builtin=true&key=" + word, "dict");
  1888. }
  1889. });
  1890. }
  1891. function refresh_pali_script() {
  1892. if (_display && _display == "para") {
  1893. //段落模式
  1894. } else {
  1895. //句子模式
  1896. setting_get("lib.second_script", set_second_scrip);
  1897. }
  1898. }
  1899. function set_second_scrip(value) {
  1900. set_pali_script(2, value);
  1901. }
  1902. function slider_show(obj) {
  1903. $(obj).parent().parent().parent().parent().parent().toggleClass("slider_show_shell");
  1904. }
  1905. function find_sent_tran_div(obj) {
  1906. let jqObj = $(obj);
  1907. while (!jqObj.hasClass("sent_tran")) {
  1908. jqObj = jqObj.parent();
  1909. if (!jqObj) {
  1910. return false;
  1911. }
  1912. }
  1913. return jqObj;
  1914. /*
  1915. let parent = obj.parentNode;
  1916. while (parent.nodeType == 1) {
  1917. if ($(parent).hasClass("sent_tran")) {
  1918. return parent;
  1919. } else if (parent.nodeName == "BODY") {
  1920. return false;
  1921. }
  1922. parent = parent.parentNode;
  1923. }
  1924. return false;
  1925. */
  1926. }
  1927. //显示或隐藏pr数据
  1928. function note_pr_show(channel, id) {
  1929. let obj = $(".sent_tran[channel='" + channel + "'][sid='" + id + "']").find(".pr_content");
  1930. let prHtml = obj.first().html();
  1931. if (prHtml == "") {
  1932. note_get_pr(channel, id);
  1933. } else {
  1934. obj.slideUp();
  1935. obj.html("");
  1936. }
  1937. }
  1938. //获取pr数据并显示
  1939. function note_get_pr(channel, id) {
  1940. let sid = id.split("-");
  1941. let book = sid[0];
  1942. let para = sid[1];
  1943. let begin = sid[2];
  1944. let end = sid[3];
  1945. $.post(
  1946. "../usent/get_pr.php",
  1947. {
  1948. book: book,
  1949. para: para,
  1950. begin: begin,
  1951. end: end,
  1952. channel: channel,
  1953. },
  1954. function (data) {
  1955. let result = JSON.parse(data);
  1956. if (result.length > 0) {
  1957. let html = "<div class='compact pr'>";
  1958. for (const iterator of result) {
  1959. html += render_one_sent_tran_a(iterator, true);
  1960. }
  1961. html += "</div>";
  1962. $(".sent_tran[channel='" + channel + "'][sid='" + id + "']")
  1963. .find(".pr_content")
  1964. .html(html);
  1965. $(".sent_tran[channel='" + channel + "'][sid='" + id + "']")
  1966. .find(".pr_content")
  1967. .slideDown();
  1968. } else {
  1969. }
  1970. }
  1971. );
  1972. $(".sent_tran[channel='" + channel + "'][sid='" + id + "']")
  1973. .find(".pr_content")
  1974. .html("loading");
  1975. $(".sent_tran[channel='" + channel + "'][sid='" + id + "']")
  1976. .find(".pr_content")
  1977. .show();
  1978. }
  1979. function get_channel_by_id(id) {
  1980. if (typeof _channalData != "undefined") {
  1981. for (const iterator of _channalData) {
  1982. if (iterator.id == id) {
  1983. return iterator;
  1984. }
  1985. }
  1986. }
  1987. if (typeof _my_channal != "undefined") {
  1988. for (const iterator of _my_channal) {
  1989. if (iterator.id == id) {
  1990. return iterator;
  1991. }
  1992. }
  1993. }
  1994. return false;
  1995. }
  1996. //设置显示方向
  1997. function setDirection(obj) {
  1998. if (obj.value == "row") {
  1999. $("#contents").removeClass("vertical");
  2000. $("#contents").addClass("horizontal");
  2001. _direction = "row";
  2002. } else {
  2003. $("#contents").removeClass("horizontal");
  2004. $("#contents").addClass("vertical");
  2005. _direction = "col";
  2006. }
  2007. }
  2008. //设置逐段或逐句模式
  2009. function setDisplay(obj) {
  2010. if (obj.value == "para") {
  2011. $("#contents").removeClass("sent_mode");
  2012. $("#contents").addClass("para_mode");
  2013. _display = "para";
  2014. } else {
  2015. $("#contents").removeClass("para_mode");
  2016. $("#contents").addClass("sent_mode");
  2017. _display = "sent";
  2018. }
  2019. }
  2020. //获取文章中H 并渲染为目录
  2021. function render_heading_toc() {
  2022. //$(":header")
  2023. }
  2024. //术语输入At
  2025. const _term_max_menu=9;
  2026. function term_set_word_list_data(el){
  2027. let sid = $(el).attr("sid");
  2028. let asid = sid.split("-");
  2029. let words=new Array();
  2030. let tmpWords = [];
  2031. term_data=[];
  2032. for (const it of _arrData) {
  2033. if(it.book==asid[0] && it.para==asid[1] && it.begin==asid[2] && it.end==asid[3]){
  2034. let palitext = it.palitext;
  2035. words = palitext.split(" ");
  2036. }
  2037. }
  2038. console.log("word",words);
  2039. //查询parent
  2040. for (let index = 0; index < words.length; index++) {
  2041. words[index] = com_getPaliReal(words[index]);
  2042. if(words[index]!=""){
  2043. let parents = term_parent(words[index]);
  2044. for (const key in parents) {
  2045. if (parents.hasOwnProperty.call(parents, key)) {
  2046. //term_data.push({word:key,en:com_getPaliEn(key),weight:weight});
  2047. tmpWords[key]={word:key,en:com_getPaliEn(key),weight:3,exist:0};
  2048. }
  2049. }
  2050. }
  2051. }
  2052. for (const iterator of arrTermAllPali) {
  2053. if(tmpWords.hasOwnProperty(iterator.word)){
  2054. tmpWords[iterator.word].weight+=1;
  2055. tmpWords[iterator.word].exist=1;
  2056. }else{
  2057. tmpWords[iterator.word]={word:iterator.word,en:com_getPaliEn(iterator.word),weight:1,exist:1};
  2058. }
  2059. }
  2060. //arrMyTerm 词头查重
  2061. let tmpMyTerm=[];
  2062. for (const iterator of arrMyTerm) {
  2063. tmpMyTerm[iterator.word]=1;
  2064. }
  2065. //加入到列表
  2066. //在我的字典中的排名靠前
  2067. for (const key in tmpMyTerm) {
  2068. if (tmpMyTerm.hasOwnProperty.call(tmpMyTerm, key)) {
  2069. if(tmpWords.hasOwnProperty(key)){
  2070. tmpWords[key].weight+=1;
  2071. tmpWords[key].exist=2;
  2072. }else{
  2073. tmpWords[key]={word:key,en:com_getPaliEn(key),weight:1,exist:2};
  2074. }
  2075. }
  2076. }
  2077. for (const key in tmpWords) {
  2078. if (tmpWords.hasOwnProperty.call(tmpWords, key)) {
  2079. const element = tmpWords[key];
  2080. term_data.push(element);
  2081. }
  2082. }
  2083. term_data.sort(function(a,b){
  2084. return b.weight-a.weight;
  2085. });
  2086. }
  2087. function text_input_textarea_focuse(el){
  2088. term_set_word_list_data(el);
  2089. term_input_text = el;
  2090. term_input_text.onresize = function(){
  2091. term_input_text.parentElement.querySelector(".text_shadow").style.height=term_input_text.clientHeight+"px";
  2092. }
  2093. term_input_text.onkeydown = function (e) {
  2094. let menu = term_input_text.parentElement.querySelector('.menu');
  2095. switch (e.key) {
  2096. case "ArrowDown"://down arrow
  2097. if(menu.style.display=="block"){
  2098. menuFocusIndex++;
  2099. if(menuFocusIndex>_term_max_menu){
  2100. menuFocusIndex=_term_max_menu;
  2101. }
  2102. menu.innerHTML=TermAtRenderMenu({focus:menuFocusIndex});
  2103. return false;
  2104. }
  2105. break;
  2106. case "ArrowUp"://up arrow
  2107. if(menu.style.display=="block"){
  2108. menuFocusIndex--;
  2109. if(menuFocusIndex<0){
  2110. menuFocusIndex=0;
  2111. }
  2112. menu.innerHTML=TermAtRenderMenu({focus:menuFocusIndex});
  2113. return false;
  2114. }
  2115. break;
  2116. case "Enter":
  2117. if(menu.style.display=="block"){
  2118. term_insert(term_filterd_data[menuFocusIndex]);
  2119. return false;
  2120. }
  2121. if (e.ctrlKey) {
  2122. //回车存盘
  2123. tran_sent_save(e.currentTarget);
  2124. return false;
  2125. }
  2126. break;
  2127. case "Escape":
  2128. if(menu.style.display=="block"){
  2129. term_at_menu_hide();
  2130. }else{
  2131. tran_sent_edit_cancel(e.currentTarget);
  2132. }
  2133. break;
  2134. default:
  2135. break;
  2136. }
  2137. }
  2138. term_input_text.onkeyup = function (e) {
  2139. let textHeight = term_input_text.parentElement.querySelector(".text_shadow").scrollHeight;
  2140. let textHeight2 = term_input_text.clientHeight;
  2141. if(textHeight2>textHeight){
  2142. textHeight=textHeight2;
  2143. }
  2144. term_input_text.style.height = textHeight+"px";
  2145. console.log("text height",textHeight);
  2146. let value = term_input_text.value
  2147. let selectionStart = term_input_text.selectionStart
  2148. let str1 = value.slice(0, selectionStart)
  2149. let str2 = value.slice(selectionStart)
  2150. let textNode1 = document.createTextNode(str1)
  2151. let textNode2 = document.createTextNode(str2)
  2152. let cursor = document.createElement('span')
  2153. cursor.innerHTML = '&nbsp;'
  2154. cursor.setAttribute('class','cursor')
  2155. let mirror = term_input_text.parentElement.querySelector('.text_shadow')
  2156. mirror.innerHTML = ''
  2157. mirror.appendChild(textNode1)
  2158. mirror.appendChild(cursor)
  2159. mirror.appendChild(textNode2)
  2160. let menu = term_input_text.parentElement.querySelector('.menu');
  2161. if(str1.slice(-2)=="[[" ){
  2162. if( menu.style.display!="block"){
  2163. menuFocusIndex=0;
  2164. menu.innerHTML=TermAtRenderMenu({focus:0});
  2165. term_at_menu_show(cursor);
  2166. }
  2167. }else{
  2168. if( menu.style.display=="block"){
  2169. let pos1=str1.lastIndexOf("[[");
  2170. let pos2=str1.lastIndexOf("]]");
  2171. if(pos1==-1 || (pos1!=-1 && pos2>pos1)){
  2172. //光标前没有[[ 或 光标在[[]] 之后
  2173. term_at_menu_hide();
  2174. }
  2175. }
  2176. }
  2177. if(menu.style.display=="block"){
  2178. //term_input += e.key;
  2179. let value = term_input_text.value
  2180. let selectionStart = term_input_text.selectionStart
  2181. let str1 = value.slice(0, selectionStart)
  2182. let str2 = value.slice(selectionStart)
  2183. let pos1=str1.lastIndexOf("[[");
  2184. let pos2=str1.lastIndexOf("]]");
  2185. if(pos1!=-1){
  2186. if(pos2==-1 || pos2<pos1){
  2187. //光标
  2188. term_input = str1.slice(str1.lastIndexOf("[[")+2);
  2189. }
  2190. }
  2191. console.log("term_input",term_input);
  2192. menu.innerHTML=TermAtRenderMenu({focus:menuFocusIndex});
  2193. }
  2194. console.log(e.key);
  2195. console.log(cursor.offsetLeft,cursor.offsetTop)
  2196. }
  2197. }
  2198. function term_at_menu_show(cursor){
  2199. menuFocusIndex=0;
  2200. let menu = term_input_text.parentElement.querySelector('.menu');
  2201. menu.style.display="block";
  2202. menu.style.top=cursor.offsetTop+20+"px";
  2203. menu.style.left=cursor.offsetLeft+"px";
  2204. $(document).on("keyup", function (e) {
  2205. if(e.key=="Escape"){
  2206. term_at_menu_hide();
  2207. }
  2208. });
  2209. }
  2210. function term_at_menu_hide(){
  2211. let menu = term_input_text.parentElement.querySelector('.menu');
  2212. menu.style.display="none";
  2213. term_input="";
  2214. }
  2215. function term_insert(strTerm){
  2216. let value = term_input_text.value;
  2217. let selectionStart = term_input_text.selectionStart;
  2218. let str1 = value.slice(0, selectionStart)
  2219. let str2 = value.slice(selectionStart)
  2220. let pos1=str1.lastIndexOf("[[");
  2221. let pos2=str1.lastIndexOf("]]");
  2222. if(pos1!=-1){
  2223. //光标前有[[
  2224. if(pos2==-1 || pos2<pos1){
  2225. //光标在[[之间]]
  2226. str1 = str1.slice(0,str1.lastIndexOf("[[")+2);
  2227. }
  2228. }
  2229. //TODO 光标会跑到最下面
  2230. term_input_text.value = str1+strTerm+"]]"+str2;
  2231. term_at_menu_hide();
  2232. }
  2233. function TermAtRenderMenu(params) {
  2234. term_filterd_data=[];
  2235. let html="";
  2236. html +="<div class='term_at_menu_input'>"+term_input+"|</div>";
  2237. html +="<ul class='term_at_menu_ul'>";
  2238. let index=0;
  2239. let focusIndex = params.focus%term_data.length;
  2240. for (const it of term_data) {
  2241. if(term_input=="" || it.word.indexOf(term_input)==0 || it.en.indexOf(term_input)==0){
  2242. html +="<li ";
  2243. if(focusIndex==index){
  2244. html +="class='trem_focus' "
  2245. }
  2246. html += "onclick=\"term_insert('"+it.word+"')\" ";
  2247. html +=">";
  2248. html += (index+1)+ ". ";
  2249. if(it.exist>0){
  2250. html += "<b>"+it.word+"</b>";
  2251. }else{
  2252. html +=it.word;
  2253. }
  2254. html +="<li>";
  2255. term_filterd_data.push(it.word);
  2256. if(index >= _term_max_menu){
  2257. break;
  2258. }
  2259. index++;
  2260. }
  2261. }
  2262. return html;
  2263. }
  2264. //添加自动格位数据到内存字典
  2265. function term_parent(paliword) {
  2266. let output=[];
  2267. for (const it of gCaseTable) {
  2268. if (it.type != ".v.") {
  2269. let sEnd2 = paliword.slice(0 - it.end2.length);
  2270. if (sEnd2 == it.end2) {
  2271. let wordParent = paliword.slice(0, 0 - it.end2.length) + it.end1;
  2272. output[wordParent]=1;
  2273. }
  2274. }
  2275. }
  2276. return output;
  2277. }