note.js 74 KB

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