note.js 74 KB

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