note.js 72 KB

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