note.js 84 KB

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