note.js 74 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728
  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(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. let noPeriod = word[1].split('။');
  1183. noPeriod[0] = myEndingTooltip(noPeriod[0]);
  1184. html += noPeriod.join('။');
  1185. }else{
  1186. html += word[1];
  1187. }
  1188. html += "</span>";
  1189. html += "</span>";
  1190. }else{
  1191. html += iterator;
  1192. }
  1193. html += "\n";
  1194. }
  1195. //html += "</div>";
  1196. return html;
  1197. }
  1198. //缅文语尾高亮和提示气泡
  1199. function myEndingTooltip(inStr){
  1200. let myEnding=[
  1201. {
  1202. id:"my_nom1",
  1203. name:"သည်",
  1204. tooltip:'主语',
  1205. },
  1206. {
  1207. id:"my_nom2",
  1208. name:"ကား",
  1209. tooltip:'主格/主语',
  1210. },
  1211. {
  1212. id:"my_nom3",
  1213. name:"က",
  1214. tooltip:'主格/主语',
  1215. },
  1216. {
  1217. id:"my_acc1",
  1218. name:"ကို",
  1219. tooltip:'宾格/宾语',
  1220. },
  1221. {
  1222. id:"my_acc2",
  1223. name:"သို့",
  1224. tooltip:'宾格/趋向',
  1225. },
  1226. {
  1227. id:"my_inst1",
  1228. name:"ဖြင့်",
  1229. tooltip:'具格/用',
  1230. },
  1231. {
  1232. id:"my_inst2",
  1233. name:"နှင့်",
  1234. tooltip:'具格/与',
  1235. },
  1236. {
  1237. id:"my_inst3",
  1238. name:"ကြောင့်",
  1239. tooltip:'具格/凭借;从格/原因',
  1240. },
  1241. {
  1242. id:"my_dat1",
  1243. name:"အား",
  1244. tooltip:'为格/对象(间接宾语)',
  1245. },
  1246. {
  1247. id:"my_dat2",
  1248. name:"ငှာ",
  1249. tooltip:'为格/目的(为了)',
  1250. },
  1251. {
  1252. id:"my_abl1",
  1253. name:"မှ",
  1254. tooltip:'从格/从',
  1255. },
  1256. {
  1257. id:"my_abl2",
  1258. name:"အောက်",
  1259. tooltip:'从格/比……多',
  1260. },
  1261. {
  1262. id:"my_abl3",
  1263. name:"ထက်",
  1264. tooltip:'从格/比……少',
  1265. },
  1266. {
  1267. id:"my_gen1",
  1268. name:"၏",
  1269. tooltip:'属格/的',
  1270. },
  1271. {
  1272. id:"my_gen2",
  1273. name:"တွင်",
  1274. tooltip:'属格/处(范围)',
  1275. },
  1276. {
  1277. id:"my_loc1",
  1278. name:"၌",
  1279. tooltip:'处格/处(范围)',
  1280. },
  1281. {
  1282. id:"my_loc2",
  1283. name:"ကြောင့်",
  1284. tooltip:'处格/因',
  1285. },
  1286. {
  1287. id:"my_abs",
  1288. name:"၍",
  1289. tooltip:'连续体',
  1290. },
  1291. {
  1292. id:"my_pl",
  1293. name:"တို့",
  1294. tooltip:'复数',
  1295. },
  1296. {
  1297. id:"my_pl",
  1298. name:"များ",
  1299. tooltip:'复数',
  1300. },
  1301. {
  1302. id:"my_pl",
  1303. name:"ကုန်",
  1304. tooltip:'复数',
  1305. },
  1306. {
  1307. id:"my_pl",
  1308. name:"ကြ",
  1309. tooltip:'复数',
  1310. },
  1311. {
  1312. id:"my_time",
  1313. name:"ပတ်လုံး",
  1314. tooltip:'时间的整数',
  1315. },
  1316. {
  1317. id:"my_time",
  1318. name:"လုံလုံး",
  1319. tooltip:'时间的整数',
  1320. },
  1321. {
  1322. id:"my_length",
  1323. name:"တိုင်တိုင်",
  1324. tooltip:'距离,长度的整数',
  1325. },
  1326. {
  1327. id:"my_length",
  1328. name:"တိုင်အောင်",
  1329. tooltip:'距离,长度的整数',
  1330. },
  1331. {
  1332. id:"my_def",
  1333. name:"နေစဉ်",
  1334. tooltip:'同时发生的时间状语(当……的时候)',
  1335. },
  1336. ];
  1337. for (const iterator of myEnding) {
  1338. if(inStr.indexOf(iterator.name)>=0){
  1339. eval("inStr=inStr.replace(/" + iterator.name + " /g,\"<guide gid='grammar_"+iterator.id+"' class='grammar_tag' style='display:unset;'>\"+iterator.name+\"</guide> \");");
  1340. eval("inStr=inStr.replace(/" + iterator.name + "$/g,\"<guide gid='grammar_"+iterator.id+"' class='grammar_tag' style='display:unset;'>\"+iterator.name+\"</guide>\");");
  1341. }
  1342. }
  1343. return inStr;
  1344. }
  1345. function tran_sent_textarea_event_init() {
  1346. let textarea = document.querySelectorAll(".tran_sent_textarea");
  1347. for (let iterator of textarea) {
  1348. iterator.onkeydown = function (e) {
  1349. let menu = document.querySelector("#menu");
  1350. switch (e.key) {
  1351. case "Enter":
  1352. if (menu && menu.style.display == "block") {
  1353. let value = textarea.value;
  1354. let selectionStart = textarea.selectionStart;
  1355. let str1 = value.slice(0, selectionStart);
  1356. let str2 = value.slice(selectionStart);
  1357. textarea.value = str1 + data[menuFocusIndex] + "]]" + str2;
  1358. menu.style.display = "none";
  1359. return false;
  1360. } else {
  1361. if (e.ctrlKey) {
  1362. //回车存盘
  1363. tran_sent_save(e.currentTarget);
  1364. return false;
  1365. }
  1366. }
  1367. break;
  1368. case "Escape":
  1369. tran_sent_edit_cancel(e.currentTarget);
  1370. break;
  1371. default:
  1372. break;
  1373. }
  1374. };
  1375. }
  1376. }
  1377. function render_one_sent_tran(book, para, begin, end, iterator) {
  1378. let output = "";
  1379. output += "<div class='tran' lang='" + iterator.lang + "' style='display:flex;'>";
  1380. //译文工具按钮开始
  1381. output += "<div class='tran_text_tool_botton' onclick='tool_bar_show(this)'>";
  1382. output +=
  1383. "<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>";
  1384. //译文工具栏开始
  1385. output += "<div class='tran_text_tool_bar'>";
  1386. output += "<div style='border-right: solid 1px;margin: 0.3em 0;'><li class = 'tip_buttom' ";
  1387. output +=
  1388. " onclick=\"note_edit_sentence('" +
  1389. book +
  1390. "' ,'" +
  1391. para +
  1392. "' ,'" +
  1393. begin +
  1394. "' ,'" +
  1395. end +
  1396. "' ,'" +
  1397. iterator.channal +
  1398. "')\"";
  1399. output +=
  1400. ">" +
  1401. '<svg class="icon" ><use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#ic_mode_edit"></use></svg>';
  1402. output += gLocal.gui.edit + "</li>";
  1403. output += "<li class = 'tip_buttom' ";
  1404. output += " onclick=\"history_show('" + iterator.id + "')\" >";
  1405. output +=
  1406. '<svg class="icon" ><use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#recent_scan"></use></svg>';
  1407. output += gLocal.gui.timeline + "</li>";
  1408. output +=
  1409. "<li class = 'tip_buttom'>" +
  1410. '<svg class="icon" ><use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#copy"></use></svg>';
  1411. output += gLocal.gui.copy + "</li></div>";
  1412. output +=
  1413. "<div style='border-right: solid 1px;margin: 0.3em 0;'><li class = 'tip_buttom'>" +
  1414. '<svg class="icon" ><use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#like"></use></svg>';
  1415. output += gLocal.gui.like + "</li>";
  1416. output +=
  1417. "<li class = 'tip_buttom'>" +
  1418. '<svg class="icon" ><use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#comment"></use></svg>';
  1419. output += gLocal.gui.comment + "</li>";
  1420. output +=
  1421. "<li class = 'tip_buttom'>" +
  1422. '<svg class="icon" ><use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#ic_shopping_cart"></use></svg>';
  1423. output += gLocal.gui.digest + "</li></div>";
  1424. output +=
  1425. "<div style='margin: 0.3em 0;'><li class = 'tip_buttom'>" +
  1426. '<svg class="icon" ><use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#share_to"></use></svg>';
  1427. output += gLocal.gui.share_to + "</li>";
  1428. output += "</div></div>";
  1429. //译文工具栏结束
  1430. output += "</div>";
  1431. //译文工具按钮结束
  1432. //译文正文开始
  1433. output +=
  1434. "<div class='text' id='tran_text_" +
  1435. book +
  1436. "_" +
  1437. para +
  1438. "_" +
  1439. begin +
  1440. "_" +
  1441. end +
  1442. "_" +
  1443. iterator.channal +
  1444. "'>";
  1445. if (iterator.text == "") {
  1446. output +=
  1447. "<span style='color:var(--border-line-color);'>" +
  1448. iterator.channalinfo.name +
  1449. "-" +
  1450. iterator.channalinfo.lang +
  1451. "</span>";
  1452. } else {
  1453. //note_init处理句子链接
  1454. output += note_init(term_std_str_to_tran(iterator.text, iterator.channal, iterator.editor, iterator.lang));
  1455. }
  1456. output += "</div>";
  1457. //译文正文结束
  1458. output += "</div>";
  1459. //单个channal译文框结束
  1460. return output;
  1461. }
  1462. function hidden_control(obj) {
  1463. if ($(".lang_2")[0].style.display == "none" && $(".lang_3")[0].style.display == "none") {
  1464. $(".lang_2").show();
  1465. $(".lang_3").show();
  1466. obj.innerHTML = "⬅"
  1467. }
  1468. else {
  1469. $(".lang_2").hide();
  1470. $(".lang_3").hide();
  1471. obj.innerHTML = "➡"
  1472. }
  1473. }
  1474. function add_new_tran_button_click(obj) {
  1475. let html = "<div style='display:flex; max-width: 70vw; white-space: normal;'>";
  1476. var first_lang = "";
  1477. for (const iterator of _my_channal) {
  1478. if (iterator.lang) {
  1479. first_lang = iterator.lang;
  1480. break;
  1481. }
  1482. }
  1483. //母语channel列表
  1484. html += "<ul class='channel_list lang_0' >";
  1485. html += "<li>";
  1486. html += gLocal.language[first_lang];
  1487. html += "</li>";
  1488. for (const iterator of _my_channal) {
  1489. if (iterator.status > 0 && first_lang.indexOf(iterator.lang) != -1 && iterator.lang != 0) {
  1490. if (_channal.indexOf(iterator.id) < 0) {
  1491. html += '<li class="channel_name" onclick="';
  1492. html +=
  1493. "new_sentence('" +
  1494. $(obj).parent().attr("book") +
  1495. "' ,'" +
  1496. $(obj).parent().attr("para") +
  1497. "' ,'" +
  1498. $(obj).parent().attr("begin") +
  1499. "' ,'" +
  1500. $(obj).parent().attr("end") +
  1501. "' ,'" +
  1502. iterator.id +
  1503. "',this)";
  1504. html += '" title="' + iterator.nickname;
  1505. html += '">' + iterator.name;
  1506. if (parseInt(iterator.power) < 20) {
  1507. html += "(建议)";
  1508. }
  1509. html += "</li>";
  1510. }
  1511. }
  1512. }
  1513. html += "<li><a href='../channal/my_channal_index.php' target='_blank'><button>" + gLocal.gui.new + "&nbsp;" + gLocal.gui.channel + "</button></a></li>"
  1514. html += "</ul>";
  1515. //非母语channel列表
  1516. html += "<ul class='channel_list lang_1'>";
  1517. html += "<li>";
  1518. html += gLocal.gui.other;
  1519. html += "&nbsp;<button style='height: 1.8em;' onmouseover='hidden_control(this)'>➡</button>"
  1520. html += "</li>";
  1521. for (const iterator of _my_channal) {
  1522. if (iterator.status > 0 && first_lang.indexOf(iterator.lang) == -1 && iterator.lang != 0) {
  1523. if (_channal.indexOf(iterator.id) < 0) {
  1524. html += '<li class="channel_name" onclick="';
  1525. html +=
  1526. "new_sentence('" +
  1527. $(obj).parent().attr("book") +
  1528. "' ,'" +
  1529. $(obj).parent().attr("para") +
  1530. "' ,'" +
  1531. $(obj).parent().attr("begin") +
  1532. "' ,'" +
  1533. $(obj).parent().attr("end") +
  1534. "' ,'" +
  1535. iterator.id +
  1536. "',this)";
  1537. html += '" title="' + iterator.nickname;
  1538. html += '">' + iterator.name;
  1539. if (parseInt(iterator.power) < 20) {
  1540. html += "(建议)";
  1541. }
  1542. html += "</li>";
  1543. }
  1544. }
  1545. }
  1546. html += "</ul>";
  1547. //协作channel列表-带中文
  1548. html += "<ul class='channel_list lang_2' style='display:none;'>";
  1549. html += "<li>";
  1550. html += "协作";
  1551. html += "</li>";
  1552. for (const iterator of _my_channal) {
  1553. if (iterator.status > 0 && iterator.lang == 0 && checkStringIsChinese(iterator.name) == true) {
  1554. if (_channal.indexOf(iterator.id) < 0) {
  1555. html += '<li class="channel_name" onclick="';
  1556. html +=
  1557. "new_sentence('" +
  1558. $(obj).parent().attr("book") +
  1559. "' ,'" +
  1560. $(obj).parent().attr("para") +
  1561. "' ,'" +
  1562. $(obj).parent().attr("begin") +
  1563. "' ,'" +
  1564. $(obj).parent().attr("end") +
  1565. "' ,'" +
  1566. iterator.id +
  1567. "',this)";
  1568. html += '" title="' + iterator.nickname;
  1569. html += '">' + iterator.name;
  1570. if (parseInt(iterator.power) < 20) {
  1571. html += "(建议)";
  1572. }
  1573. html += "</li>";
  1574. }
  1575. }
  1576. }
  1577. html += "</ul>";
  1578. //协作channel列表-不带中文
  1579. html += "<ul class='channel_list lang_3' style='display:none;'>";
  1580. html += "<li>";
  1581. html += "collaborate";
  1582. html += "</li>";
  1583. for (const iterator of _my_channal) {
  1584. if (iterator.status > 0 && iterator.lang == 0 && checkStringIsChinese(iterator.name) == false) {
  1585. if (_channal.indexOf(iterator.id) < 0) {
  1586. html += '<li class="channel_name" onclick="';
  1587. html +=
  1588. "new_sentence('" +
  1589. $(obj).parent().attr("book") +
  1590. "' ,'" +
  1591. $(obj).parent().attr("para") +
  1592. "' ,'" +
  1593. $(obj).parent().attr("begin") +
  1594. "' ,'" +
  1595. $(obj).parent().attr("end") +
  1596. "' ,'" +
  1597. iterator.id +
  1598. "',this)";
  1599. html += '" title="' + iterator.nickname;
  1600. html += '">' + iterator.name;
  1601. if (parseInt(iterator.power) < 20) {
  1602. html += "(建议)";
  1603. }
  1604. html += "</li>";
  1605. }
  1606. }
  1607. }
  1608. html += "</ul>";
  1609. html += "</div>";
  1610. $(obj).parent().children(".tran_text_tool_bar").first().html(html);
  1611. if ($(obj).parent().children(".tran_text_tool_bar").css("display") == "block") {
  1612. $(obj).parent().children(".tran_text_tool_bar").first().hide();
  1613. } else {
  1614. $(obj).parent().children(".tran_text_tool_bar").first().show();
  1615. $(document).one("click", function () {
  1616. $(obj).parent().children(".tran_text_tool_bar").first().hide();
  1617. });
  1618. event.stopPropagation();
  1619. $(obj).parent().show();
  1620. }
  1621. }
  1622. function checkStringIsChinese(str) {
  1623. var pattern = new RegExp("[\u4E00-\u9FA5]+");
  1624. if (pattern.test(str)) {
  1625. return true;
  1626. }
  1627. return false;
  1628. }
  1629. function tool_bar_show(element) {
  1630. if ($(element).find(".tran_text_tool_bar").css("display") == "none") {
  1631. $(element).find(".tran_text_tool_bar").css("display", "flex");
  1632. $(element).find(".icon_expand").css("transform", "rotate(-180deg)");
  1633. $(element).css("background-color", "var(--btn-bg-color)");
  1634. $(element).css("visibility", "visible");
  1635. $(document).one("click", function () {
  1636. $(element).find(".tran_text_tool_bar").hide();
  1637. $(element).css("background-color", "var(--nocolor)");
  1638. $(element).find(".icon_expand").css("transform", "unset");
  1639. $(element).css("visibility", "");
  1640. });
  1641. event.stopPropagation();
  1642. } else {
  1643. $(element).find(".tran_text_tool_bar").hide();
  1644. $(element).css("background-color", "var(--nocolor)");
  1645. $(element).find(".icon_expand").css("transform", "unset");
  1646. $(element).css("visibility", "");
  1647. }
  1648. }
  1649. function new_sentence(book, para, begin, end, channel, obj) {
  1650. let newsent = { id: "", text: "", lang: "", channal: channel };
  1651. for (let iterator of _arrData) {
  1652. if (iterator.book == book && iterator.para == para && iterator.begin == begin && iterator.end == end) {
  1653. let found = false;
  1654. for (const tran of iterator.translation) {
  1655. if (tran.channal == channel) {
  1656. found = true;
  1657. break;
  1658. }
  1659. }
  1660. if (!found) {
  1661. iterator.translation.push(newsent);
  1662. }
  1663. }
  1664. }
  1665. if ($(obj).parent().parent().css("display") == "block") {
  1666. $(obj).parent().parent().hide();
  1667. }
  1668. note_edit_sentence(book, para, begin, end, channel);
  1669. }
  1670. //显示更多译文按钮动作
  1671. function set_more_button_display() {
  1672. $(".other_bar").each(function () {
  1673. const sentid = $(this).attr("sent").split("-");
  1674. const channelType = $(this).attr("channel_type");
  1675. const book = sentid[0];
  1676. const para = sentid[1];
  1677. const begin = sentid[2];
  1678. const end = sentid[3];
  1679. let count = 0;
  1680. let commentaryChannel=0;
  1681. if(channelType=='commentary'){
  1682. for (const iterator of _channal.split(',')) {
  1683. let thisChannel = find_channal(iterator);
  1684. if(thisChannel && thisChannel.type=='commentary'){
  1685. commentaryChannel++;
  1686. }
  1687. }
  1688. }
  1689. for (const iterator of _channalData) {
  1690. if (iterator.final && iterator.type==channelType) {
  1691. for (const onesent of iterator.final) {
  1692. let id = onesent.id.split("-");
  1693. if (book == id[0] && para == id[1] && begin == id[2] && end == id[3] && onesent.final) {
  1694. if(channelType=='commentary'){
  1695. count++;
  1696. }else{
  1697. if (_channal.indexOf(iterator.id) == -1) {
  1698. count++;
  1699. }
  1700. }
  1701. }
  1702. }
  1703. }
  1704. }
  1705. if (count > 0 || commentaryChannel>0)
  1706. {
  1707. $(this).find(".other_tran_num").html(count);
  1708. $(this).find(".other_tran_num").attr("style", "display:inline-flex;");
  1709. $(this).off('click')
  1710. .on('click',function () {
  1711. const sentid = $(this).attr("sent").split("-");
  1712. const channelType = $(this).attr("channel_type");
  1713. const book = sentid[0];
  1714. const para = sentid[1];
  1715. const begin = sentid[2];
  1716. const end = sentid[3];
  1717. let sentId = $(this).attr("sent");
  1718. let otherSentDiv = $(this).parent().parent().siblings(".other_tran").first();
  1719. if (otherSentDiv.css("display") == "none") {
  1720. otherSentDiv.slideDown();
  1721. //加号复位
  1722. //$(this).siblings(".more_tran ").css("transform", "unset");
  1723. $.get(
  1724. "../usent/get.php",
  1725. {
  1726. book: book,
  1727. para: para,
  1728. begin: begin,
  1729. end: end,
  1730. type:channelType,
  1731. },
  1732. function (data, status) {
  1733. let arrSent = JSON.parse(data);
  1734. let html = "<div class='compact "+channelType+"'>";
  1735. if(channelType==='commentary'){
  1736. //先渲染被选择的channel
  1737. if (_channal != "") {
  1738. //for(const channel of _channal.split(","))
  1739. {
  1740. for (const sent of _arrData) {
  1741. if (sent.book == book && sent.para==para && sent.begin==begin && sent.end==end) {
  1742. for (const tran of sent.translation) {
  1743. if(tran.channalinfo.type=='commentary'){
  1744. html += render_one_sent_tran_a(tran);
  1745. }
  1746. }
  1747. break;
  1748. }
  1749. }
  1750. }
  1751. }
  1752. }
  1753. //然后渲染没有被选择的
  1754. for (const iterator of arrSent) {
  1755. if (_channal.indexOf(iterator.channal) == -1) {
  1756. html += render_one_sent_tran_a(iterator);
  1757. }
  1758. }
  1759. html += "</div>";
  1760. otherSentDiv.html(html);
  1761. if(channelType==='commentary'){
  1762. note_refresh_new();
  1763. }
  1764. //初始化文本编辑框消息处理
  1765. tran_sent_textarea_event_init();
  1766. }
  1767. );
  1768. } else {
  1769. otherSentDiv.slideUp();
  1770. $(this).siblings(".more_tran ").css("transform", "rotate(-90deg)");
  1771. }
  1772. return false; // 阻止事件冒泡
  1773. });
  1774. }else
  1775. {
  1776. //隐藏自己
  1777. //$(this).hide();
  1778. $(this).addClass("disable");
  1779. //$(this).find(".more_tran").hide();
  1780. }
  1781. });
  1782. }
  1783. function note_edit_sentence(book, para, begin, end, channal) {
  1784. let channalInfo;
  1785. for (const iterator of _channalData) {
  1786. if (iterator.id == channal) {
  1787. channalInfo = iterator;
  1788. break;
  1789. }
  1790. }
  1791. for (const iterator of _arrData) {
  1792. if (iterator.book == book && iterator.para == para && iterator.begin == begin && iterator.end == end) {
  1793. for (const tran of iterator.translation) {
  1794. if (tran.channal == channal) {
  1795. let html = "";
  1796. html += "<div style='color:blue;'>" + channalInfo.name + "@" + channalInfo.nickname + "</div>";
  1797. html +=
  1798. "<textarea id='edit_dialog_text' sent_id='" +
  1799. tran.id +
  1800. "' book='" +
  1801. book +
  1802. "' para='" +
  1803. para +
  1804. "' begin='" +
  1805. begin +
  1806. "' end='" +
  1807. end +
  1808. "' channal='" +
  1809. channal +
  1810. "' style='width:100%;min-height:260px;'>" +
  1811. tran.text +
  1812. "</textarea>";
  1813. $("#edit_dialog_content").html(html);
  1814. $("#note_sent_edit_dlg").dialog("open");
  1815. return;
  1816. }
  1817. }
  1818. }
  1819. }
  1820. alert("未找到句子");
  1821. }
  1822. function tran_sent_edit_cancel(obj) {
  1823. sent_tran_set_edit_mode(obj, false);
  1824. }
  1825. function tran_sent_save(obj) {
  1826. let sentDiv = find_sent_tran_div(obj);
  1827. if (sentDiv) {
  1828. let textarea = $(sentDiv).children('.sent_tran_inner').first().children('.body').first().children('.edit').find(".tran_sent_textarea").first();
  1829. //let textarea = $(sentDiv).children().find(".tran_sent_textarea").first();
  1830. let isPr = $(textarea).attr("is_pr");
  1831. if (isPr == "true") {
  1832. note_pr_save(textarea);
  1833. } else {
  1834. note_sent_save_a(textarea);
  1835. }
  1836. sent_tran_set_edit_mode(textarea, false);
  1837. } else {
  1838. console.error("sent div not found");
  1839. }
  1840. }
  1841. //保存pr句子 新
  1842. function note_pr_save(obj) {
  1843. let id = $(obj).attr("dbid");
  1844. let sid = $(obj).attr("sid").split("-");
  1845. let book = sid[0];
  1846. let para = sid[1];
  1847. let begin = sid[2];
  1848. let end = sid[3];
  1849. let channel = $(obj).attr("channel");
  1850. let text = $(obj).val();
  1851. let sent_tran_div = find_sent_tran_div(obj);
  1852. $.post(
  1853. "../usent/pr_post.php",
  1854. {
  1855. id: id,
  1856. book: book,
  1857. para: para,
  1858. begin: begin,
  1859. end: end,
  1860. channel: channel,
  1861. text: text,
  1862. },
  1863. sent_save_callback
  1864. );
  1865. if (sent_tran_div) {
  1866. $(sent_tran_div).addClass("loading");
  1867. }
  1868. }
  1869. //保存译文句子 新
  1870. function note_sent_save_a(obj) {
  1871. let id = $(obj).attr("dbid");
  1872. let sid = $(obj).attr("sid").split("-");
  1873. let book = sid[0];
  1874. let para = sid[1];
  1875. let begin = sid[2];
  1876. let end = sid[3];
  1877. let channal = $(obj).attr("channel");
  1878. let text = $(obj).val();
  1879. let sent_tran_div = find_sent_tran_div(obj);
  1880. $.ajaxSetup({
  1881. timeout: 5000,
  1882. });
  1883. $.post("../usent/sent_post.php", {
  1884. id: id,
  1885. book: book,
  1886. para: para,
  1887. begin: begin,
  1888. end: end,
  1889. channal: channal,
  1890. text: text,
  1891. lang: "zh",
  1892. })
  1893. .done(function (data) {
  1894. sent_save_callback(data);
  1895. })
  1896. .fail(function (xhr, error, data) {
  1897. let sid = book + "-" + para + "-" + begin + "-" + end;
  1898. let sent_tran_div = $(".sent_tran[channel='" + channal + "'][sid='" + sid + "']");
  1899. if (sent_tran_div) {
  1900. sent_tran_div.removeClass("loading");
  1901. sent_tran_div.addClass("error");
  1902. }
  1903. switch (error) {
  1904. case "timeout":
  1905. alert("服务器长时间没有回应。请稍后重试。");
  1906. break;
  1907. case "error":
  1908. alert("与服务器通讯失败,您可能没有连接到网络。请稍后重试。");
  1909. break;
  1910. case "notmodified":
  1911. break;
  1912. default:
  1913. break;
  1914. }
  1915. });
  1916. if (sent_tran_div) {
  1917. $(sent_tran_div).addClass("loading");
  1918. $(sent_tran_div).removeClass("error");
  1919. }
  1920. }
  1921. function update_sent_tran(sentData) {}
  1922. function sent_save_callback(data) {
  1923. let result;
  1924. try {
  1925. result = JSON.parse(data);
  1926. } catch (e) {
  1927. alert(e.message);
  1928. console.error('sent_save_callback',data);
  1929. return;
  1930. }
  1931. if (result.status > 0) {
  1932. alert("error" + result.message);
  1933. } else {
  1934. let sid = result.book + "-" + result.para + "-" + result.begin + "-" + result.end;
  1935. let sent_tran_div = $(
  1936. ".sent_tran[dbid='" + result.id + "'][channel='" + result.channal + "'][sid='" + sid + "']"
  1937. );
  1938. if (sent_tran_div) {
  1939. sent_tran_div.removeClass("loading");
  1940. }
  1941. if (result.commit_type == 1 || result.commit_type == 2) {
  1942. ntf_show("成功修改");
  1943. if (sent_tran_div) {
  1944. let divPreview = sent_tran_div.find(".preview").first();
  1945. let thisChannel = find_channal(result.channal);
  1946. if (result.text == "") {
  1947. //内容为空
  1948. let channel_info = "Empty";
  1949. if (thisChannel) {
  1950. channel_info = thisChannel.name + "-" + thisChannel.nickname;
  1951. }
  1952. divPreview.html("<span style='color:var(--border-line-color);'>" + channel_info + "</span>");
  1953. } else {
  1954. for (const iterator of _arrData) {
  1955. if (
  1956. iterator.book == result.book &&
  1957. iterator.para == result.para &&
  1958. iterator.begin == result.begin &&
  1959. iterator.end == result.end
  1960. ) {
  1961. for (const tran of iterator.translation) {
  1962. if (tran.channal == result.channal) {
  1963. tran.text = result.text;
  1964. break;
  1965. }
  1966. }
  1967. }
  1968. }
  1969. switch (thisChannel.type) {
  1970. case 'nissaya':
  1971. divPreview.html(renderNissayaPreview(result.text));
  1972. break;
  1973. case 'commentary':
  1974. divPreview.html(
  1975. note_init(result.text, result.channal, result.editor, result.lang)
  1976. );
  1977. note_refresh_new();
  1978. break;
  1979. default:
  1980. divPreview.html(
  1981. marked(term_std_str_to_tran(result.text, result.channal, result.editor, result.lang))
  1982. );
  1983. term_updata_translation();
  1984. break;
  1985. }
  1986. popup_init();
  1987. }
  1988. }
  1989. } else if (result.commit_type == 3) {
  1990. ntf_show("已经提交修改建议");
  1991. } else {
  1992. ntf_show("未提交");
  1993. }
  1994. }
  1995. }
  1996. //保存译文句子
  1997. function note_sent_save() {
  1998. let id = $("#edit_dialog_text").attr("sent_id");
  1999. let book = $("#edit_dialog_text").attr("book");
  2000. let para = $("#edit_dialog_text").attr("para");
  2001. let begin = $("#edit_dialog_text").attr("begin");
  2002. let end = $("#edit_dialog_text").attr("end");
  2003. let channal = $("#edit_dialog_text").attr("channal");
  2004. let text = $("#edit_dialog_text").val();
  2005. $.post(
  2006. "../usent/sent_post.php",
  2007. {
  2008. id: id,
  2009. book: book,
  2010. para: para,
  2011. begin: begin,
  2012. end: end,
  2013. channal: channal,
  2014. text: text,
  2015. lang: "zh",
  2016. },
  2017. function (data) {
  2018. let result = JSON.parse(data);
  2019. if (result.status > 0) {
  2020. alert("error" + result.message);
  2021. } else {
  2022. if (result.commit_type == 1 || result.commit_type == 2) {
  2023. ntf_show("成功修改");
  2024. if (result.text == "") {
  2025. let channel_info = "Empty";
  2026. let thisChannel = find_channal(result.channal);
  2027. if (thisChannel) {
  2028. channel_info = thisChannel.name + "-" + thisChannel.nickname;
  2029. }
  2030. $(
  2031. "#tran_text_" +
  2032. result.book +
  2033. "_" +
  2034. result.para +
  2035. "_" +
  2036. result.begin +
  2037. "_" +
  2038. result.end +
  2039. "_" +
  2040. result.channal
  2041. ).html("<span style='color:var(--border-line-color);'>" + channel_info + "</span>");
  2042. } else {
  2043. $(
  2044. "#tran_text_" +
  2045. result.book +
  2046. "_" +
  2047. result.para +
  2048. "_" +
  2049. result.begin +
  2050. "_" +
  2051. result.end +
  2052. "_" +
  2053. result.channal
  2054. ).html(marked(term_std_str_to_tran(result.text, result.channal, result.editor, result.lang)));
  2055. term_updata_translation();
  2056. for (const iterator of _arrData) {
  2057. if (
  2058. iterator.book == result.book &&
  2059. iterator.para == result.para &&
  2060. iterator.begin == result.begin &&
  2061. iterator.end == result.end
  2062. ) {
  2063. for (const tran of iterator.translation) {
  2064. if (tran.channal == result.channal) {
  2065. tran.text = result.text;
  2066. break;
  2067. }
  2068. }
  2069. }
  2070. }
  2071. }
  2072. } else if (result.commit_type == 3) {
  2073. ntf_show("已经提交修改建议");
  2074. } else {
  2075. ntf_show("未提交");
  2076. }
  2077. }
  2078. }
  2079. );
  2080. }
  2081. function copy_ref(book, para, begin, end) {
  2082. let strRef = "{{" + book + "-" + para + "-" + begin + "-" + end + "}}";
  2083. copy_to_clipboard(strRef);
  2084. }
  2085. function goto_nissaya(book, para, begin = 0, end = 0) {
  2086. window.open("../nissaya/index.php?book=" + book + "&par=" + para + "&begin=" + begin + "&end=" + end, "nissaya");
  2087. }
  2088. function edit_in_studio(book, para, begin, end) {
  2089. wbw_channal_list_open(book, [para]);
  2090. }
  2091. //显示和隐藏某个内容 如 巴利文
  2092. function setVisibility(key, value) {
  2093. switch (key) {
  2094. case "palitext":
  2095. if ($(value).is(":checked")) {
  2096. $(".palitext").show();
  2097. } else {
  2098. $(".palitext").hide();
  2099. }
  2100. break;
  2101. default:
  2102. break;
  2103. }
  2104. }
  2105. function note_show_pali_sim(SentId) {
  2106. pali_sim_dlg_open(SentId, 0, 20);
  2107. }
  2108. function set_pali_script(pos, script) {
  2109. if (script == "none") {
  2110. $(".palitext" + pos).html("");
  2111. } else {
  2112. $(".palitext" + pos).each(function () {
  2113. let html = $(this).siblings(".palitext_roma").first().html();
  2114. $(this).html(html);
  2115. });
  2116. $(".palitext" + pos)
  2117. .find("*")
  2118. .contents()
  2119. .filter(function () {
  2120. return this.nodeType != 1;
  2121. })
  2122. .wrap("<pl" + pos + "></pl" + pos + ">");
  2123. $(".palitext" + pos)
  2124. .contents()
  2125. .filter(function () {
  2126. return this.nodeType != 1;
  2127. })
  2128. .wrap("<pl" + pos + "></pl" + pos + ">");
  2129. $("pl" + pos).html(function (index, oldcontent) {
  2130. switch(script){
  2131. case "မြန်မာ":
  2132. return roman_to_my(oldcontent);
  2133. case "My2Roman":
  2134. return my_to_roman(oldcontent);
  2135. case "සිංහල":
  2136. return roman_to_si(oldcontent);
  2137. case "ᨲ᩠ᩅᩫᨴᩱ᩠ᨿᨵᨾ᩠ᨾ᩼":
  2138. return roman_to_tai(oldcontent);
  2139. case "อักษรไทย":
  2140. return roman_to_thai(oldcontent);
  2141. default:
  2142. return(oldcontent);
  2143. }
  2144. });
  2145. }
  2146. }
  2147. function splite_pali_word() {
  2148. $("pali")
  2149. .contents()
  2150. .filter(function () {
  2151. return this.nodeType != 1;
  2152. })
  2153. .wrap("<pl></pl>");
  2154. $("pl").each(function () {
  2155. let html = $(this).html();
  2156. $(this).html("<w>" + html.replace(/\s/g, "</w> <w>") + "</w>");
  2157. });
  2158. $("w").click(function () {
  2159. let word = com_getPaliReal($(this).text());
  2160. if (gBuildinDictIsOpen) {
  2161. window.open("../dict/index.php?builtin=true&key=" + word, "dict");
  2162. }
  2163. });
  2164. }
  2165. function refresh_pali_script() {
  2166. if (_display && _display == "para") {
  2167. //段落模式
  2168. } else {
  2169. //句子模式
  2170. setting_get("lib.second_script", set_second_scrip);
  2171. }
  2172. }
  2173. function set_second_scrip(value) {
  2174. set_pali_script(2, value);
  2175. }
  2176. function slider_show(obj) {
  2177. $(obj).parent().parent().parent().parent().parent().toggleClass("slider_show_shell");
  2178. }
  2179. function find_sent_tran_div(obj) {
  2180. let jqObj = $(obj);
  2181. while (!jqObj.hasClass("sent_tran")) {
  2182. jqObj = jqObj.parent();
  2183. if (!jqObj) {
  2184. return false;
  2185. }
  2186. }
  2187. return jqObj;
  2188. /*
  2189. let parent = obj.parentNode;
  2190. while (parent.nodeType == 1) {
  2191. if ($(parent).hasClass("sent_tran")) {
  2192. return parent;
  2193. } else if (parent.nodeName == "BODY") {
  2194. return false;
  2195. }
  2196. parent = parent.parentNode;
  2197. }
  2198. return false;
  2199. */
  2200. }
  2201. //显示或隐藏pr数据
  2202. function note_pr_show(channel, id) {
  2203. let obj = $(".sent_tran[channel='" + channel + "'][sid='" + id + "']").find(".pr_content");
  2204. let prHtml = obj.first().html();
  2205. if (prHtml == "") {
  2206. note_get_pr(channel, id);
  2207. } else {
  2208. obj.slideUp();
  2209. obj.html("");
  2210. }
  2211. }
  2212. //获取pr数据并显示
  2213. function note_get_pr(channel, id) {
  2214. let sid = id.split("-");
  2215. let book = sid[0];
  2216. let para = sid[1];
  2217. let begin = sid[2];
  2218. let end = sid[3];
  2219. $.post(
  2220. "../usent/get_pr.php",
  2221. {
  2222. book: book,
  2223. para: para,
  2224. begin: begin,
  2225. end: end,
  2226. channel: channel,
  2227. },
  2228. function (data) {
  2229. let result = JSON.parse(data);
  2230. if (result.length > 0) {
  2231. let html = "<div class='compact pr'>";
  2232. for (const iterator of result) {
  2233. html += render_one_sent_tran_a(iterator, true);
  2234. }
  2235. html += "</div>";
  2236. $(".sent_tran[channel='" + channel + "'][sid='" + id + "']")
  2237. .find(".pr_content")
  2238. .html(html);
  2239. $(".sent_tran[channel='" + channel + "'][sid='" + id + "']")
  2240. .find(".pr_content")
  2241. .slideDown();
  2242. } else {
  2243. }
  2244. }
  2245. );
  2246. $(".sent_tran[channel='" + channel + "'][sid='" + id + "']")
  2247. .find(".pr_content")
  2248. .html("loading");
  2249. $(".sent_tran[channel='" + channel + "'][sid='" + id + "']")
  2250. .find(".pr_content")
  2251. .show();
  2252. }
  2253. function get_channel_by_id(id) {
  2254. if (typeof _channalData != "undefined") {
  2255. for (const iterator of _channalData) {
  2256. if (iterator.id == id) {
  2257. return iterator;
  2258. }
  2259. }
  2260. }
  2261. if (typeof _my_channal != "undefined") {
  2262. for (const iterator of _my_channal) {
  2263. if (iterator.id == id) {
  2264. return iterator;
  2265. }
  2266. }
  2267. }
  2268. return false;
  2269. }
  2270. //设置显示方向
  2271. function setDirection(obj) {
  2272. if (obj.value == "row") {
  2273. $("#contents").removeClass("vertical");
  2274. $("#contents").addClass("horizontal");
  2275. _direction = "row";
  2276. } else {
  2277. $("#contents").removeClass("horizontal");
  2278. $("#contents").addClass("vertical");
  2279. _direction = "col";
  2280. }
  2281. }
  2282. //设置逐段或逐句模式
  2283. function setDisplay(obj) {
  2284. if (obj.value == "para") {
  2285. $("#contents").removeClass("sent_mode");
  2286. $("#contents").addClass("para_mode");
  2287. _display = "para";
  2288. } else {
  2289. $("#contents").removeClass("para_mode");
  2290. $("#contents").addClass("sent_mode");
  2291. _display = "sent";
  2292. }
  2293. }
  2294. //获取文章中H 并渲染为目录
  2295. function render_heading_toc() {
  2296. //$(":header")
  2297. }
  2298. //术语输入At
  2299. const _term_max_menu=9;
  2300. function term_set_word_list_data(el){
  2301. let sid = $(el).attr("sid");
  2302. let asid = sid.split("-");
  2303. let words=new Array();
  2304. let tmpWords = [];
  2305. term_data=[];
  2306. for (const it of _arrData) {
  2307. if(it.book==asid[0] && it.para==asid[1] && it.begin==asid[2] && it.end==asid[3]){
  2308. let palitext = it.palitext;
  2309. words = palitext.split(" ");
  2310. }
  2311. }
  2312. console.log("word",words);
  2313. //查询parent
  2314. for (let index = 0; index < words.length; index++) {
  2315. words[index] = com_getPaliReal(words[index]);
  2316. if(words[index]!=""){
  2317. let parents = term_parent(words[index]);
  2318. for (const key in parents) {
  2319. if (parents.hasOwnProperty.call(parents, key)) {
  2320. //term_data.push({word:key,en:com_getPaliEn(key),weight:weight});
  2321. tmpWords[key]={word:key,en:com_getPaliEn(key),weight:3,exist:0};
  2322. }
  2323. }
  2324. }
  2325. }
  2326. for (const iterator of arrTermAllPali) {
  2327. if(tmpWords.hasOwnProperty(iterator.word)){
  2328. tmpWords[iterator.word].weight+=1;
  2329. tmpWords[iterator.word].exist=1;
  2330. }else{
  2331. tmpWords[iterator.word]={word:iterator.word,en:com_getPaliEn(iterator.word),weight:1,exist:1};
  2332. }
  2333. }
  2334. //arrMyTerm 词头查重
  2335. let tmpMyTerm=[];
  2336. for (const iterator of arrMyTerm) {
  2337. tmpMyTerm[iterator.word]=1;
  2338. }
  2339. //加入到列表
  2340. //在我的字典中的排名靠前
  2341. for (const key in tmpMyTerm) {
  2342. if (tmpMyTerm.hasOwnProperty.call(tmpMyTerm, key)) {
  2343. if(tmpWords.hasOwnProperty(key)){
  2344. tmpWords[key].weight+=1;
  2345. tmpWords[key].exist=2;
  2346. }else{
  2347. tmpWords[key]={word:key,en:com_getPaliEn(key),weight:1,exist:2};
  2348. }
  2349. }
  2350. }
  2351. for (const key in tmpWords) {
  2352. if (tmpWords.hasOwnProperty.call(tmpWords, key)) {
  2353. const element = tmpWords[key];
  2354. term_data.push(element);
  2355. }
  2356. }
  2357. term_data.sort(function(a,b){
  2358. return b.weight-a.weight;
  2359. });
  2360. }
  2361. function text_input_textarea_focuse(el){
  2362. term_set_word_list_data(el);
  2363. term_input_text = el;
  2364. term_input_text.onresize = function(){
  2365. term_input_text.parentElement.querySelector(".text_shadow").style.height=term_input_text.clientHeight+"px";
  2366. }
  2367. term_input_text.onkeydown = function (e) {
  2368. let menu = term_input_text.parentElement.querySelector('.menu');
  2369. switch (e.key) {
  2370. case "ArrowDown"://down arrow
  2371. if(menu.style.display=="block"){
  2372. menuFocusIndex++;
  2373. if(menuFocusIndex>_term_max_menu){
  2374. menuFocusIndex=_term_max_menu;
  2375. }
  2376. menu.innerHTML=TermAtRenderMenu({focus:menuFocusIndex});
  2377. return false;
  2378. }
  2379. break;
  2380. case "ArrowUp"://up arrow
  2381. if(menu.style.display=="block"){
  2382. menuFocusIndex--;
  2383. if(menuFocusIndex<0){
  2384. menuFocusIndex=0;
  2385. }
  2386. menu.innerHTML=TermAtRenderMenu({focus:menuFocusIndex});
  2387. return false;
  2388. }
  2389. break;
  2390. case "Enter":
  2391. if(menu.style.display=="block"){
  2392. term_insert(term_filterd_data[menuFocusIndex]);
  2393. return false;
  2394. }
  2395. if (e.ctrlKey) {
  2396. //回车存盘
  2397. tran_sent_save(e.currentTarget);
  2398. return false;
  2399. }
  2400. break;
  2401. case "Escape":
  2402. if(menu.style.display=="block"){
  2403. term_at_menu_hide();
  2404. }else{
  2405. tran_sent_edit_cancel(e.currentTarget);
  2406. }
  2407. break;
  2408. default:
  2409. break;
  2410. }
  2411. }
  2412. term_input_text.onkeyup = function (e) {
  2413. let textHeight = term_input_text.parentElement.querySelector(".text_shadow").scrollHeight;
  2414. let textHeight2 = term_input_text.clientHeight;
  2415. if(textHeight2>textHeight){
  2416. textHeight=textHeight2;
  2417. }
  2418. term_input_text.style.height = textHeight+"px";
  2419. console.log("text height",textHeight);
  2420. let value = term_input_text.value
  2421. let selectionStart = term_input_text.selectionStart
  2422. let str1 = value.slice(0, selectionStart)
  2423. let str2 = value.slice(selectionStart)
  2424. let textNode1 = document.createTextNode(str1)
  2425. let textNode2 = document.createTextNode(str2)
  2426. let cursor = document.createElement('span')
  2427. cursor.innerHTML = '&nbsp;'
  2428. cursor.setAttribute('class','cursor')
  2429. let mirror = term_input_text.parentElement.querySelector('.text_shadow')
  2430. mirror.innerHTML = ''
  2431. mirror.appendChild(textNode1)
  2432. mirror.appendChild(cursor)
  2433. mirror.appendChild(textNode2)
  2434. let menu = term_input_text.parentElement.querySelector('.menu');
  2435. if(str1.slice(-2)=="[[" ){
  2436. if( menu.style.display!="block"){
  2437. menuFocusIndex=0;
  2438. menu.innerHTML=TermAtRenderMenu({focus:0});
  2439. term_at_menu_show(cursor);
  2440. }
  2441. }else{
  2442. if( menu.style.display=="block"){
  2443. let pos1=str1.lastIndexOf("[[");
  2444. let pos2=str1.lastIndexOf("]]");
  2445. if(pos1==-1 || (pos1!=-1 && pos2>pos1)){
  2446. //光标前没有[[ 或 光标在[[]] 之后
  2447. term_at_menu_hide();
  2448. }
  2449. }
  2450. }
  2451. if(menu.style.display=="block"){
  2452. //term_input += e.key;
  2453. let value = term_input_text.value
  2454. let selectionStart = term_input_text.selectionStart
  2455. let str1 = value.slice(0, selectionStart)
  2456. let str2 = value.slice(selectionStart)
  2457. let pos1=str1.lastIndexOf("[[");
  2458. let pos2=str1.lastIndexOf("]]");
  2459. if(pos1!=-1){
  2460. if(pos2==-1 || pos2<pos1){
  2461. //光标
  2462. term_input = str1.slice(str1.lastIndexOf("[[")+2);
  2463. }
  2464. }
  2465. console.log("term_input",term_input);
  2466. menu.innerHTML=TermAtRenderMenu({focus:menuFocusIndex});
  2467. }
  2468. console.log(e.key);
  2469. console.log(cursor.offsetLeft,cursor.offsetTop)
  2470. }
  2471. }
  2472. function term_at_menu_show(cursor){
  2473. menuFocusIndex=0;
  2474. let menu = term_input_text.parentElement.querySelector('.menu');
  2475. menu.style.display="block";
  2476. menu.style.top=cursor.offsetTop+20+"px";
  2477. menu.style.left=cursor.offsetLeft+"px";
  2478. $(document).on("keyup", function (e) {
  2479. if(e.key=="Escape"){
  2480. term_at_menu_hide();
  2481. }
  2482. });
  2483. }
  2484. function term_at_menu_hide(){
  2485. let menu = term_input_text.parentElement.querySelector('.menu');
  2486. menu.style.display="none";
  2487. term_input="";
  2488. }
  2489. function term_insert(strTerm){
  2490. let value = term_input_text.value;
  2491. let selectionStart = term_input_text.selectionStart;
  2492. let str1 = value.slice(0, selectionStart)
  2493. let str2 = value.slice(selectionStart)
  2494. let pos1=str1.lastIndexOf("[[");
  2495. let pos2=str1.lastIndexOf("]]");
  2496. if(pos1!=-1){
  2497. //光标前有[[
  2498. if(pos2==-1 || pos2<pos1){
  2499. //光标在[[之间]]
  2500. str1 = str1.slice(0,str1.lastIndexOf("[[")+2);
  2501. }
  2502. }
  2503. //TODO 光标会跑到最下面
  2504. term_input_text.value = str1+strTerm+"]]"+str2;
  2505. term_at_menu_hide();
  2506. }
  2507. function TermAtRenderMenu(params) {
  2508. term_filterd_data=[];
  2509. let html="";
  2510. html +="<div class='term_at_menu_input'>"+term_input+"|</div>";
  2511. html +="<ul class='term_at_menu_ul'>";
  2512. let index=0;
  2513. let focusIndex = params.focus%term_data.length;
  2514. for (const it of term_data) {
  2515. if(term_input=="" || it.word.indexOf(term_input)==0 || it.en.indexOf(term_input)==0){
  2516. html +="<li ";
  2517. if(focusIndex==index){
  2518. html +="class='trem_focus' "
  2519. }
  2520. html += "onclick=\"term_insert('"+it.word+"')\" ";
  2521. html +=">";
  2522. html += (index+1)+ ". ";
  2523. if(it.exist>0){
  2524. html += "<b>"+it.word+"</b>";
  2525. }else{
  2526. html +=it.word;
  2527. }
  2528. html +="<li>";
  2529. term_filterd_data.push(it.word);
  2530. if(index >= _term_max_menu){
  2531. break;
  2532. }
  2533. index++;
  2534. }
  2535. }
  2536. return html;
  2537. }
  2538. //添加自动格位数据到内存字典
  2539. function term_parent(paliword) {
  2540. let output=[];
  2541. for (const it of gCaseTable) {
  2542. if (it.type != ".v.") {
  2543. let sEnd2 = paliword.slice(0 - it.end2.length);
  2544. if (sEnd2 == it.end2) {
  2545. let wordParent = paliword.slice(0, 0 - it.end2.length) + it.end1;
  2546. output[wordParent]=1;
  2547. }
  2548. }
  2549. }
  2550. return output;
  2551. }
  2552. function setSentToolBarEvent(){
  2553. $('.sent_tran_inner').not('.commentary').off('mouseenter').on('mouseenter',function(){
  2554. $(this).children('.tool_bar').first().children('.right').show();
  2555. });
  2556. $('.sent_tran_inner').not('.commentary').off('mouseleave').on('mouseleave',function(){
  2557. $(this).children('.tool_bar').first().children('.right').hide();
  2558. })
  2559. }