note.js 81 KB

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