2
0

note.js 74 KB

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