note.js 74 KB

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