note.js 74 KB

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