note.js 74 KB

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