note.js 82 KB

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