note.js 86 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229
  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. const meaning = word[word.length-1];
  1280. if (getCookie('language') !="my") {
  1281. let noPeriod = meaning.split('။');
  1282. noPeriod[0] = myEndingTooltip(noPeriod[0]);
  1283. html += noPeriod.join('။');
  1284. }else{
  1285. html += meaning;
  1286. }
  1287. html += "</span>";
  1288. html += "</span>";
  1289. }else{
  1290. html += iterator;
  1291. }
  1292. html += "\n";
  1293. }
  1294. return html;
  1295. }
  1296. //缅文语尾高亮和提示气泡
  1297. function myEndingTooltip(inStr){
  1298. let myEnding=[
  1299. {
  1300. id:"my_nom1",
  1301. name:"သည်",
  1302. tooltip:'主语',
  1303. },
  1304. {
  1305. id:"my_nom2",
  1306. name:"တည်း",
  1307. tooltip:'就是,表示强调',
  1308. },
  1309. {
  1310. id:"my_nama1",
  1311. name:"ကား",
  1312. tooltip:'位于名词、代词、成分助词之后,起强调和对比的作用',
  1313. },
  1314. {
  1315. id:"my_nom3",
  1316. name:"က",
  1317. tooltip:'主格/主语',
  1318. },
  1319. {
  1320. id:"my_acc1",
  1321. name:"ကို",
  1322. tooltip:'宾格/宾语',
  1323. },
  1324. {
  1325. id:"my_acc2",
  1326. name:"သို့",
  1327. tooltip:'宾格/趋向',
  1328. },
  1329. {
  1330. id:"my_inst_imp",
  1331. name:"အစွမ်းဖြင့်",
  1332. tooltip:'vasena',
  1333. },
  1334. {
  1335. id:"my_inst_imp",
  1336. name:"အစွမ်းအားဖြင့်",
  1337. tooltip:'vasena',
  1338. },
  1339. {
  1340. id:"my_imp",
  1341. name:"အားဖြင့်",
  1342. tooltip:'具格/用',
  1343. },
  1344. {
  1345. id:"my_imp",
  1346. name:"ဖြင့်",
  1347. tooltip:'具格/用',
  1348. },
  1349. {
  1350. id:"my_soi",
  1351. name:"နှင့်",
  1352. tooltip:'具格/与',
  1353. },
  1354. {
  1355. id:"my_soi",
  1356. name:"နှင့်",//异体编码
  1357. tooltip:'具格/与',
  1358. },
  1359. {
  1360. id:"my_cau",
  1361. name:"ကြောင့်",
  1362. tooltip:'具格/凭借;从格/原因',
  1363. },
  1364. {
  1365. id:"my_cau",
  1366. name:"ကြောင်း",
  1367. tooltip:'具格/凭借;从格/原因',
  1368. },
  1369. {
  1370. id:"my_dat3",
  1371. name:"အကျိုးငှာ",
  1372. tooltip:'atthāya和atthaṃ',
  1373. },
  1374. {
  1375. id:"my_rec",
  1376. name:"အား",
  1377. tooltip:'目的格/对象(间接宾语),对……来说',
  1378. },
  1379. {
  1380. id:"my_pur",
  1381. name:"ငှာ",
  1382. tooltip:'目的格/表示目的,为了……',
  1383. },
  1384. {
  1385. id:"my_pur",
  1386. name:"ဖို့",
  1387. tooltip:'目的格/表示目的,为了……',
  1388. },
  1389. {
  1390. id:"my_pur",
  1391. name:"ငှါ",
  1392. tooltip:'目的格/表示目的,为了……',
  1393. },
  1394. {
  1395. id:"my_pur",
  1396. name:"အတွက်",
  1397. tooltip:'目的格/表示目的,为了……',
  1398. },
  1399. {
  1400. id:"my_det",
  1401. name:"မှ",
  1402. tooltip:'从格/表示来源,从……',
  1403. },
  1404. {
  1405. id:"my_coc1",
  1406. name:"အောက်",
  1407. tooltip:'从格/表达比较,比……多',
  1408. },
  1409. {
  1410. id:"my_coc0",
  1411. name:"ထက်",
  1412. tooltip:'从格/表达比较,比……少',
  1413. },
  1414. {
  1415. id:"my_pos",
  1416. name:"၏",
  1417. tooltip:'属格/的',
  1418. },
  1419. {
  1420. id:"my_coi",
  1421. name:"တွင်",
  1422. tooltip:'属格/表达范围,……中的',
  1423. },
  1424. {
  1425. id:"my_coi",
  1426. name:"အနက်",
  1427. tooltip:'属格/表达范围,……中的',
  1428. },
  1429. {
  1430. id:"my_coi",
  1431. name:"ထဲမှ",
  1432. tooltip:'属格/表达范围,……中的',
  1433. },
  1434. {
  1435. id:"my_lov",
  1436. name:"၌",
  1437. tooltip:'处格/处(范围)',
  1438. },
  1439. {
  1440. id:"my_loc2",
  1441. name:"အဖို့၌",
  1442. tooltip:'处格/表达动机,因……,旨在……',
  1443. },
  1444. {
  1445. id:"my_iti",
  1446. name:"ဟူ၍",
  1447. tooltip:'引用',
  1448. },
  1449. {
  1450. id:"my_abs",
  1451. name:"၍",
  1452. tooltip:'连续体',
  1453. },
  1454. {
  1455. id:"my_imper",
  1456. name:"ပါစေသတည်း",
  1457. tooltip:'祈愿式',
  1458. },
  1459. {
  1460. id:"my_pl",
  1461. name:"တို့",
  1462. tooltip:'复数',
  1463. },
  1464. {
  1465. id:"my_pl",
  1466. name:"များ",
  1467. tooltip:'复数',
  1468. },
  1469. {
  1470. id:"my_pl",
  1471. name:"ကုန်",
  1472. tooltip:'复数',
  1473. },
  1474. {
  1475. id:"my_pl",
  1476. name:"ကြ",
  1477. tooltip:'复数',
  1478. },
  1479. {
  1480. id:"my_time",
  1481. name:"ပတ်လုံး",
  1482. tooltip:'时间的整数',
  1483. },
  1484. {
  1485. id:"my_time",
  1486. name:"လုံလုံး",
  1487. tooltip:'时间的整数',
  1488. },
  1489. {
  1490. id:"my_time",
  1491. name:"တိုင်တိုင်",
  1492. tooltip:'距离,长度的整数',
  1493. },
  1494. {
  1495. id:"my_time",
  1496. name:"တိုင်အောင်",
  1497. tooltip:'距离,长度的整数',
  1498. },
  1499. {
  1500. id:"my_def",
  1501. name:"စဉ်",
  1502. tooltip:'同时发生的时间状语(当……的时候)',
  1503. },
  1504. {
  1505. id:"my_def",
  1506. name:"နေစဉ်",
  1507. tooltip:'同时发生的时间状语(当……的时候)',
  1508. },
  1509. {
  1510. id:"my_def",
  1511. name:"လျက်",
  1512. tooltip:'同时发生的时间状语(当……的时候)',
  1513. },
  1514. {
  1515. id:"my_def_eva",
  1516. name:"မှသာ",
  1517. tooltip:'只有……才……',
  1518. },
  1519. {
  1520. id:"my_def_eva",
  1521. name:"မှသာလျှင်",
  1522. tooltip:'只有……才……',
  1523. },
  1524. {
  1525. id:"my_eva",
  1526. name:"သာလျှင်",
  1527. tooltip:'就,只是',
  1528. },
  1529. {
  1530. id:"my_eva",
  1531. name:"ပင်",
  1532. tooltip:'就,只是',
  1533. },
  1534. {
  1535. id:"my_eva",
  1536. name:"ပင်လျှင်",
  1537. tooltip:'就,只是',
  1538. },
  1539. {
  1540. id:"my_def",
  1541. name:"လျှင်",
  1542. tooltip:'同时发生的时间状语(当……的时候)',
  1543. },
  1544. {
  1545. id:"my_def",
  1546. name:"သော်",
  1547. tooltip:'同时发生的时间状语(当……的时候)',
  1548. },
  1549. {
  1550. id:"my_api",
  1551. name:"လည်း",
  1552. tooltip:'也',
  1553. },
  1554. {
  1555. id:"my_api",
  1556. name:"ပါ",
  1557. tooltip:'也',
  1558. },
  1559. {
  1560. id:"my_iad",
  1561. name:"သော",
  1562. tooltip:'的(同类修饰)',
  1563. },
  1564. {
  1565. id:"my_iad",
  1566. name:"သည့်",
  1567. tooltip:'的(同类修饰)',
  1568. },
  1569. {
  1570. id:"my_pl_fut",
  1571. name:"ကုန်လတ္တံ့",
  1572. tooltip:'复数将来式',
  1573. },
  1574. {
  1575. id:"my_fut",
  1576. name:"လတ္တံ့",
  1577. tooltip:'将来式',
  1578. },
  1579. {
  1580. id:"my_va",
  1581. name:"သော်၎င်း",
  1582. tooltip:'或',
  1583. },
  1584. {
  1585. id:"my_ca",
  1586. name:"လည်းကောင်း",
  1587. tooltip:'和',
  1588. },
  1589. {
  1590. id:"my_ca",
  1591. name:"၎င်း",
  1592. tooltip:'和',
  1593. },
  1594. {
  1595. id:"my_ca",
  1596. name:"ရယ်",
  1597. tooltip:'和',
  1598. },
  1599. {
  1600. id:"my_pp",
  1601. name:"ပြီ",
  1602. tooltip:'过去分词',
  1603. },
  1604. {
  1605. id:"my_ca",
  1606. name:"လည်း",
  1607. tooltip:'和',
  1608. },
  1609. {
  1610. id:"my_eyya",
  1611. name:"ကောင်း",
  1612. tooltip:'也许',
  1613. },
  1614. {
  1615. id:"my_adv",
  1616. name:"စွာ",
  1617. tooltip:'副词',
  1618. },
  1619. {
  1620. id:"my_num1",
  1621. name:"လုံး",
  1622. tooltip:'整体性',
  1623. },
  1624. {
  1625. id:"my_num1",
  1626. name:"စလုံး",
  1627. tooltip:'整体性',
  1628. },
  1629. ];
  1630. for (const iterator of myEnding) {
  1631. if(inStr.indexOf(iterator.name)>=0){
  1632. eval("inStr=inStr.replace(/" + iterator.name + " /g,\"<guide gid='grammar_"+iterator.id+"' class='grammar_tag' style='display:unset;'>\"+iterator.name+\"</guide> \");");
  1633. eval("inStr=inStr.replace(/" + iterator.name + "$/g,\"<guide gid='grammar_"+iterator.id+"' class='grammar_tag' style='display:unset;'>\"+iterator.name+\"</guide>\");");
  1634. }
  1635. }
  1636. return inStr;
  1637. }
  1638. //渲染pr按钮里面的数字
  1639. function render_pr_number(pr_new,pr_all){
  1640. let html = "";
  1641. if(pr_all > 0){
  1642. html = "<span class='icon'>✋</span><span class='num'>" + pr_new + "/" + pr_all + "</span>";
  1643. }
  1644. return html;
  1645. }
  1646. function tran_sent_textarea_event_init() {
  1647. let textarea = document.querySelectorAll(".tran_sent_textarea");
  1648. for (let iterator of textarea) {
  1649. iterator.onkeydown = function (e) {
  1650. let menu = document.querySelector("#menu");
  1651. switch (e.key) {
  1652. case "Enter":
  1653. if (menu && menu.style.display == "block") {
  1654. let value = textarea.value;
  1655. let selectionStart = textarea.selectionStart;
  1656. let str1 = value.slice(0, selectionStart);
  1657. let str2 = value.slice(selectionStart);
  1658. textarea.value = str1 + data[menuFocusIndex] + "]]" + str2;
  1659. menu.style.display = "none";
  1660. return false;
  1661. } else {
  1662. if (e.ctrlKey) {
  1663. //回车存盘
  1664. tran_sent_save(e.currentTarget);
  1665. return false;
  1666. }
  1667. }
  1668. break;
  1669. case "Escape":
  1670. tran_sent_edit_cancel(e.currentTarget);
  1671. break;
  1672. default:
  1673. break;
  1674. }
  1675. };
  1676. }
  1677. }
  1678. function render_one_sent_tran(book, para, begin, end, iterator) {
  1679. let output = "";
  1680. output += "<div class='tran' lang='" + iterator.lang + "' style='display:flex;'>";
  1681. //译文工具按钮开始
  1682. output += "<div class='tran_text_tool_botton' onclick='tool_bar_show(this)'>";
  1683. output +=
  1684. "<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>";
  1685. //译文工具栏开始
  1686. output += "<div class='tran_text_tool_bar'>";
  1687. output += "<div style='border-right: solid 1px;margin: 0.3em 0;'><li class = 'tip_buttom' ";
  1688. output +=
  1689. " onclick=\"note_edit_sentence('" +
  1690. book +
  1691. "' ,'" +
  1692. para +
  1693. "' ,'" +
  1694. begin +
  1695. "' ,'" +
  1696. end +
  1697. "' ,'" +
  1698. iterator.channal +
  1699. "')\"";
  1700. output +=
  1701. ">" +
  1702. '<svg class="icon" ><use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#ic_mode_edit"></use></svg>';
  1703. output += gLocal.gui.edit + "</li>";
  1704. output += "<li class = 'tip_buttom' ";
  1705. output += " onclick=\"history_show('" + iterator.id + "')\" >";
  1706. output +=
  1707. '<svg class="icon" ><use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#recent_scan"></use></svg>';
  1708. output += gLocal.gui.timeline + "</li>";
  1709. output +=
  1710. "<li class = 'tip_buttom'>" +
  1711. '<svg class="icon" ><use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#copy"></use></svg>';
  1712. output += gLocal.gui.copy + "</li></div>";
  1713. output +=
  1714. "<div style='border-right: solid 1px;margin: 0.3em 0;'><li class = 'tip_buttom'>" +
  1715. '<svg class="icon" ><use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#like"></use></svg>';
  1716. output += gLocal.gui.like + "</li>";
  1717. output +=
  1718. "<li class = 'tip_buttom'>" +
  1719. '<svg class="icon" ><use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#comment"></use></svg>';
  1720. output += gLocal.gui.comment + "</li>";
  1721. output +=
  1722. "<li class = 'tip_buttom'>" +
  1723. '<svg class="icon" ><use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#ic_shopping_cart"></use></svg>';
  1724. output += gLocal.gui.digest + "</li></div>";
  1725. output +=
  1726. "<div style='margin: 0.3em 0;'><li class = 'tip_buttom'>" +
  1727. '<svg class="icon" ><use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#share_to"></use></svg>';
  1728. output += gLocal.gui.share_to + "</li>";
  1729. output += "</div></div>";
  1730. //译文工具栏结束
  1731. output += "</div>";
  1732. //译文工具按钮结束
  1733. //译文正文开始
  1734. output +=
  1735. "<div class='text' id='tran_text_" +
  1736. book +
  1737. "_" +
  1738. para +
  1739. "_" +
  1740. begin +
  1741. "_" +
  1742. end +
  1743. "_" +
  1744. iterator.channal +
  1745. "'>";
  1746. if (iterator.text == "") {
  1747. output +=
  1748. "<span style='color:var(--border-line-color);'>" +
  1749. iterator.channalinfo.name +
  1750. "-" +
  1751. iterator.channalinfo.lang +
  1752. "</span>";
  1753. } else {
  1754. //note_init处理句子链接
  1755. output += note_init(iterator.text, iterator.channal, iterator.editor, iterator.lang);
  1756. }
  1757. output += "</div>";
  1758. //译文正文结束
  1759. output += "</div>";
  1760. //单个channal译文框结束
  1761. return output;
  1762. }
  1763. function hidden_control(obj) {
  1764. if ($(".lang_2")[0].style.display == "none" && $(".lang_3")[0].style.display == "none") {
  1765. $(".lang_2").show();
  1766. $(".lang_3").show();
  1767. obj.innerHTML = "⬅"
  1768. }
  1769. else {
  1770. $(".lang_2").hide();
  1771. $(".lang_3").hide();
  1772. obj.innerHTML = "➡"
  1773. }
  1774. }
  1775. function renderChannelButton(eChannel,obj){
  1776. let html="";
  1777. if (_channal.indexOf(eChannel.uid) < 0) {
  1778. html += '<li class="channel_name" onclick="';
  1779. html +=
  1780. "new_sentence('" +
  1781. $(obj).parent().attr("book") +
  1782. "' ,'" +
  1783. $(obj).parent().attr("para") +
  1784. "' ,'" +
  1785. $(obj).parent().attr("begin") +
  1786. "' ,'" +
  1787. $(obj).parent().attr("end") +
  1788. "' ,'" +
  1789. eChannel.uid +
  1790. "',this)";
  1791. html += '" title="' + eChannel.nickname;
  1792. html += '">' + eChannel.name;
  1793. if (parseInt(eChannel.power) < 20) {
  1794. html += "(建议)";
  1795. }
  1796. html += "</li>";
  1797. }
  1798. return html;
  1799. }
  1800. function add_new_tran_button_click(obj) {
  1801. let html = "<div style='display:flex; max-width: 70vw; white-space: normal;'>";
  1802. var first_lang = "";
  1803. if (Array.isArray(_my_channal)) {
  1804. for (const iterator of _my_channal) {
  1805. if (iterator.lang) {
  1806. first_lang = iterator.lang;
  1807. break;
  1808. }
  1809. }
  1810. }
  1811. //母语channel列表
  1812. html += "<ul class='channel_list lang_0' >";
  1813. html += "<li>";
  1814. html += gLocal.language[first_lang];
  1815. html += "</li>";
  1816. if (Array.isArray(_my_channal)) {
  1817. for (const iterator of _my_channal) {
  1818. if (iterator.status > 0 && first_lang.indexOf(iterator.lang) != -1 && iterator.lang != 0) {
  1819. html += renderChannelButton(iterator,obj);
  1820. }
  1821. }
  1822. }
  1823. html += "<li><a href='../channal/my_channal_index.php' target='_blank'><button>" + gLocal.gui.new + "&nbsp;" + gLocal.gui.channel + "</button></a></li>"
  1824. html += "</ul>";
  1825. //非母语channel列表
  1826. html += "<ul class='channel_list lang_1'>";
  1827. html += "<li>";
  1828. html += gLocal.gui.other;
  1829. html += "&nbsp;<button style='height: 1.8em;' onmouseover='hidden_control(this)'>➡</button>"
  1830. html += "</li>";
  1831. if (Array.isArray(_my_channal)) {
  1832. for (const iterator of _my_channal) {
  1833. if (iterator.status > 0 && first_lang.indexOf(iterator.lang) == -1 && iterator.lang != 0) {
  1834. html += renderChannelButton(iterator,obj);
  1835. }
  1836. }
  1837. }
  1838. html += "</ul>";
  1839. //协作channel列表-带中文
  1840. html += "<ul class='channel_list lang_2' style='display:none;'>";
  1841. html += "<li>";
  1842. html += "协作";
  1843. html += "</li>";
  1844. for (const iterator of _my_channal) {
  1845. if (iterator.status > 0 && iterator.lang == 0 && checkStringIsChinese(iterator.name) == true) {
  1846. html += renderChannelButton(iterator,obj);
  1847. }
  1848. }
  1849. html += "</ul>";
  1850. //协作channel列表-不带中文
  1851. html += "<ul class='channel_list lang_3' style='display:none;'>";
  1852. html += "<li>";
  1853. html += "collaborate";
  1854. html += "</li>";
  1855. if (Array.isArray(_my_channal)) {
  1856. for (const iterator of _my_channal) {
  1857. if (iterator.status > 0 && iterator.lang == 0 && checkStringIsChinese(iterator.name) == false) {
  1858. html += renderChannelButton(iterator,obj);
  1859. }
  1860. }
  1861. }
  1862. html += "</ul>";
  1863. html += "</div>";
  1864. $(obj).parent().children(".tran_text_tool_bar").first().html(html);
  1865. if ($(obj).parent().children(".tran_text_tool_bar").css("display") == "block") {
  1866. $(obj).parent().children(".tran_text_tool_bar").first().hide();
  1867. } else {
  1868. $(obj).parent().children(".tran_text_tool_bar").first().show();
  1869. $(document).one("click", function () {
  1870. $(obj).parent().children(".tran_text_tool_bar").first().hide();
  1871. });
  1872. event.stopPropagation();
  1873. $(obj).parent().show();
  1874. }
  1875. }
  1876. function checkStringIsChinese(str) {
  1877. var pattern = new RegExp("[\u4E00-\u9FA5]+");
  1878. if (pattern.test(str)) {
  1879. return true;
  1880. }
  1881. return false;
  1882. }
  1883. function tool_bar_show(element) {
  1884. if ($(element).find(".tran_text_tool_bar").css("display") == "none") {
  1885. $(element).find(".tran_text_tool_bar").css("display", "flex");
  1886. $(element).find(".icon_expand").css("transform", "rotate(-180deg)");
  1887. $(element).css("background-color", "var(--btn-bg-color)");
  1888. $(element).css("visibility", "visible");
  1889. $(document).one("click", function () {
  1890. $(element).find(".tran_text_tool_bar").hide();
  1891. $(element).css("background-color", "var(--nocolor)");
  1892. $(element).find(".icon_expand").css("transform", "unset");
  1893. $(element).css("visibility", "");
  1894. });
  1895. event.stopPropagation();
  1896. } else {
  1897. $(element).find(".tran_text_tool_bar").hide();
  1898. $(element).css("background-color", "var(--nocolor)");
  1899. $(element).find(".icon_expand").css("transform", "unset");
  1900. $(element).css("visibility", "");
  1901. }
  1902. }
  1903. function new_sentence(book, para, begin, end, channel, obj) {
  1904. let newsent = { id: "", text: "", lang: "", channal: channel };
  1905. for (let iterator of _arrData) {
  1906. if (iterator.book == book && iterator.para == para && iterator.begin == begin && iterator.end == end) {
  1907. let found = false;
  1908. for (const tran of iterator.translation) {
  1909. if (tran.channal == channel) {
  1910. found = true;
  1911. break;
  1912. }
  1913. }
  1914. if (!found) {
  1915. iterator.translation.push(newsent);
  1916. }
  1917. }
  1918. }
  1919. if ($(obj).parent().parent().css("display") == "block") {
  1920. $(obj).parent().parent().hide();
  1921. }
  1922. note_edit_sentence(book, para, begin, end, channel);
  1923. }
  1924. //显示更多译文按钮动作
  1925. function set_more_button_display() {
  1926. $(".other_bar").each(function () {
  1927. const sentid = $(this).attr("sent").split("-");
  1928. const channelType = $(this).attr("channel_type");
  1929. const book = sentid[0];
  1930. const para = sentid[1];
  1931. const begin = sentid[2];
  1932. const end = sentid[3];
  1933. let count = 0;
  1934. let commentaryChannel=0;
  1935. if(channelType=='commentary'){
  1936. for (const iterator of _channal.split(',')) {
  1937. let thisChannel = find_channal(iterator);
  1938. if(thisChannel && thisChannel.type=='commentary'){
  1939. commentaryChannel++;
  1940. }
  1941. }
  1942. }
  1943. for (const iterator of _channalData) {
  1944. if (iterator.final && iterator.type==channelType) {
  1945. for (const onesent of iterator.final) {
  1946. let id = onesent.id.split("-");
  1947. if (book == id[0] && para == id[1] && begin == id[2] && end == id[3] && onesent.final) {
  1948. if(channelType=='commentary'){
  1949. count++;
  1950. }else{
  1951. if (_channal.indexOf(iterator.id) == -1) {
  1952. count++;
  1953. }
  1954. }
  1955. }
  1956. }
  1957. }
  1958. }
  1959. if (count > 0 || commentaryChannel>0)
  1960. {
  1961. $(this).find(".other_tran_num").html(count);
  1962. $(this).find(".other_tran_num").attr("style", "display:inline-flex;");
  1963. $(this).off('click')
  1964. .on('click',function () {
  1965. const sentid = $(this).attr("sent").split("-");
  1966. const channelType = $(this).attr("channel_type");
  1967. const book = sentid[0];
  1968. const para = sentid[1];
  1969. const begin = sentid[2];
  1970. const end = sentid[3];
  1971. let sentId = $(this).attr("sent");
  1972. let otherSentDiv = $(this).parent().parent().siblings(".other_tran").first();
  1973. if (otherSentDiv.css("display") == "none") {
  1974. otherSentDiv.slideDown();
  1975. //加号复位
  1976. //$(this).siblings(".more_tran ").css("transform", "unset");
  1977. $.get(
  1978. "../usent/get.php",
  1979. {
  1980. book: book,
  1981. para: para,
  1982. begin: begin,
  1983. end: end,
  1984. type:channelType,
  1985. },
  1986. function (data, status) {
  1987. let arrSent = JSON.parse(data);
  1988. let html = "<div class='compact "+channelType+"'>";
  1989. if(channelType==='commentary'){
  1990. //先渲染被选择的channel
  1991. if (_channal != "") {
  1992. //for(const channel of _channal.split(","))
  1993. {
  1994. for (const sent of _arrData) {
  1995. if (sent.book == book && sent.para==para && sent.begin==begin && sent.end==end) {
  1996. for (const tran of sent.translation) {
  1997. if(tran.channalinfo.type=='commentary'){
  1998. html += render_one_sent_tran_a(tran);
  1999. }
  2000. }
  2001. break;
  2002. }
  2003. }
  2004. }
  2005. }
  2006. }
  2007. //然后渲染没有被选择的
  2008. for (const iterator of arrSent) {
  2009. if (_channal.indexOf(iterator.channal) == -1) {
  2010. html += render_one_sent_tran_a(iterator);
  2011. }
  2012. }
  2013. html += "</div>";
  2014. otherSentDiv.html(html);
  2015. if(channelType==='commentary'){
  2016. note_refresh_new();
  2017. }
  2018. popup_init();
  2019. guide_init();
  2020. //初始化文本编辑框消息处理
  2021. tran_sent_textarea_event_init();
  2022. }
  2023. );
  2024. } else {
  2025. otherSentDiv.slideUp();
  2026. $(this).siblings(".more_tran ").css("transform", "rotate(-90deg)");
  2027. }
  2028. return false; // 阻止事件冒泡
  2029. });
  2030. }else
  2031. {
  2032. //隐藏自己
  2033. //$(this).hide();
  2034. $(this).addClass("disable");
  2035. //$(this).find(".more_tran").hide();
  2036. }
  2037. });
  2038. }
  2039. function note_edit_sentence(book, para, begin, end, channal) {
  2040. let channalInfo;
  2041. for (const iterator of _channalData) {
  2042. if (iterator.uid == channal) {
  2043. channalInfo = iterator;
  2044. break;
  2045. }
  2046. }
  2047. for (const iterator of _arrData) {
  2048. if (iterator.book == book && iterator.para == para && iterator.begin == begin && iterator.end == end) {
  2049. for (const tran of iterator.translation) {
  2050. if (tran.channal == channal) {
  2051. let html = "";
  2052. html += "<div style='color:blue;'>" + channalInfo.name + "@" + channalInfo.nickname + "</div>";
  2053. html +=
  2054. "<textarea id='edit_dialog_text' sent_id='" +
  2055. tran.id +
  2056. "' book='" +
  2057. book +
  2058. "' para='" +
  2059. para +
  2060. "' begin='" +
  2061. begin +
  2062. "' end='" +
  2063. end +
  2064. "' channal='" +
  2065. channal +
  2066. "' style='width:100%;min-height:260px;'>" +
  2067. tran.text +
  2068. "</textarea>";
  2069. $("#edit_dialog_content").html(html);
  2070. $("#note_sent_edit_dlg").dialog("open");
  2071. return;
  2072. }
  2073. }
  2074. }
  2075. }
  2076. alert("未找到句子");
  2077. }
  2078. function tran_sent_edit_cancel(obj) {
  2079. sent_tran_set_edit_mode(obj, false);
  2080. }
  2081. function tran_sent_save(obj) {
  2082. let sentDiv = find_sent_tran_div(obj);
  2083. if (sentDiv) {
  2084. let textarea = $(sentDiv).children('.sent_tran_inner').first().children('.body').first().children('.edit').find(".tran_sent_textarea").first();
  2085. //let textarea = $(sentDiv).children().find(".tran_sent_textarea").first();
  2086. let isPr = $(textarea).attr("is_pr");
  2087. if(isPr=='true'){
  2088. note_pr_update(textarea);
  2089. }else{
  2090. if (_edit_mode == "pr" ) {
  2091. note_pr_create(textarea);
  2092. } else {
  2093. note_sent_save_a(textarea);
  2094. }
  2095. }
  2096. sent_tran_set_edit_mode(textarea, false);
  2097. } else {
  2098. console.error("sent div not found");
  2099. }
  2100. }
  2101. //保存pr句子 新
  2102. function note_pr_create(obj) {
  2103. console.log("note_pr_create");
  2104. let id = $(obj).attr("dbid");
  2105. let channel_type = $(obj).attr("channel_type");
  2106. let sid = $(obj).attr("sid").split("-");
  2107. let book = sid[0];
  2108. let para = sid[1];
  2109. let begin = sid[2];
  2110. let end = sid[3];
  2111. let channel = $(obj).attr("channel");
  2112. let text = $(obj).val();
  2113. let sent_tran_div = find_sent_tran_div(obj);
  2114. if(channel_type=="original"){
  2115. //原文需要按照语言设定转码
  2116. switch (getCookie('language')) {
  2117. case 'my':
  2118. //缅文
  2119. text = my_to_roman(text);
  2120. break;
  2121. }
  2122. }
  2123. $.post(
  2124. "/api/v2/sentpr",
  2125. {
  2126. id: id,
  2127. book: book,
  2128. para: para,
  2129. begin: begin,
  2130. end: end,
  2131. channel: channel,
  2132. text: text,
  2133. },
  2134. pr_create_callback
  2135. );
  2136. if (sent_tran_div) {
  2137. $(sent_tran_div).addClass("loading");
  2138. }
  2139. }
  2140. //修改pr句子
  2141. function note_pr_update(obj) {
  2142. console.log("note_pr_update ");
  2143. let id = $(obj).attr("dbid");
  2144. let channel_type = $(obj).attr("channel_type");
  2145. let text = $(obj).val();
  2146. let sent_tran_div = find_sent_tran_div(obj);
  2147. if(channel_type=="original"){
  2148. //原文需要按照语言设定转码
  2149. switch (getCookie('language')) {
  2150. case 'my':
  2151. //缅文
  2152. text = my_to_roman(text);
  2153. break;
  2154. }
  2155. }
  2156. fetch('/api/v2/sentpr/'+id,{
  2157. method: 'PUT',
  2158. credentials: 'same-origin',
  2159. headers: {
  2160. 'Content-Type': 'application/json'
  2161. },
  2162. body: JSON.stringify({
  2163. id: id,
  2164. text: text,
  2165. })
  2166. })
  2167. .then(response => response.json())
  2168. .then(function(data){
  2169. pr_update_callback(data);
  2170. });
  2171. if (sent_tran_div) {
  2172. $(sent_tran_div).addClass("loading");
  2173. }
  2174. }
  2175. //修改pr句子
  2176. function note_pr_delete(obj) {
  2177. if(!confirm("要删除此修改建议吗?此操作无法恢复。")){
  2178. return;
  2179. }
  2180. let sent_tran_div = find_sent_tran_div(obj);
  2181. let id = sent_tran_div.attr("dbid");
  2182. fetch('/api/v2/sentpr/'+id,{
  2183. method: 'DELETE',
  2184. credentials: 'same-origin',
  2185. headers: {
  2186. 'Content-Type': 'application/json'
  2187. },
  2188. body: JSON.stringify({
  2189. id: id,
  2190. })
  2191. })
  2192. .then(response => response.json())
  2193. .then(function(data){
  2194. console.log("note_pr_delete",data);
  2195. if(data.ok){
  2196. let sent_tran_parent = find_sent_tran_div(sent_tran_div.parent());
  2197. sent_tran_parent.find(".tag_list").first().children(".pr").first().html(render_pr_number(1,data.data));
  2198. sent_tran_div.removeClass("loading");
  2199. sent_tran_div.parent().html("");
  2200. ntf_show("删除成功");
  2201. }
  2202. });
  2203. if (sent_tran_div) {
  2204. $(sent_tran_div).addClass("loading");
  2205. }
  2206. }
  2207. //保存译文句子 新
  2208. function note_sent_save_a(obj) {
  2209. console.log("note_sent_save_a");
  2210. let id = $(obj).attr("dbid");
  2211. let channel_type = $(obj).attr("channel_type");
  2212. let sid = $(obj).attr("sid").split("-");
  2213. let book = sid[0];
  2214. let para = sid[1];
  2215. let begin = sid[2];
  2216. let end = sid[3];
  2217. let channal = $(obj).attr("channel");
  2218. let text = $(obj).val();
  2219. let sent_tran_div = find_sent_tran_div(obj);
  2220. if(channel_type=="original"){
  2221. //原文需要按照语言设定转码
  2222. switch (getCookie('language')) {
  2223. case 'my':
  2224. //缅文
  2225. text = my_to_roman(text);
  2226. break;
  2227. }
  2228. }
  2229. $.ajaxSetup({
  2230. timeout: 5000,
  2231. });
  2232. $.post("../usent/sent_post.php", {
  2233. id: id,
  2234. book: book,
  2235. para: para,
  2236. begin: begin,
  2237. end: end,
  2238. channal: channal,
  2239. text: text,
  2240. lang: "zh",
  2241. })
  2242. .done(function (data) {
  2243. let result = JSON.parse(data);
  2244. if(result.commit_type==3){
  2245. $.post(
  2246. "/api/v2/sentpr",
  2247. {
  2248. book: book,
  2249. para: para,
  2250. begin: begin,
  2251. end: end,
  2252. channel: channal,
  2253. text: text,
  2254. },
  2255. function(data){
  2256. console.log('pr robot',data);
  2257. }
  2258. );
  2259. }
  2260. sent_save_callback(data);
  2261. })
  2262. .fail(function (xhr, error, data) {
  2263. let sid = book + "-" + para + "-" + begin + "-" + end;
  2264. let sent_tran_div = $(".sent_tran[channel='" + channal + "'][sid='" + sid + "']");
  2265. if (sent_tran_div) {
  2266. sent_tran_div.removeClass("loading");
  2267. sent_tran_div.addClass("error");
  2268. }
  2269. switch (error) {
  2270. case "timeout":
  2271. alert("服务器长时间没有回应。请稍后重试。");
  2272. break;
  2273. case "error":
  2274. alert("与服务器通讯失败,您可能没有连接到网络。请稍后重试。");
  2275. break;
  2276. case "notmodified":
  2277. break;
  2278. default:
  2279. break;
  2280. }
  2281. });
  2282. if (sent_tran_div) {
  2283. $(sent_tran_div).addClass("loading");
  2284. $(sent_tran_div).removeClass("error");
  2285. }
  2286. }
  2287. function update_sent_tran(sentData) {}
  2288. function sent_save_callback(data) {
  2289. let result;
  2290. try {
  2291. result = JSON.parse(data);
  2292. } catch (e) {
  2293. alert(e.message);
  2294. console.error('sent_save_callback',data);
  2295. return;
  2296. }
  2297. if (result.status > 0) {
  2298. alert("error" + result.message);
  2299. } else {
  2300. let sid = result.book + "-" + result.para + "-" + result.begin + "-" + result.end;
  2301. let sent_tran_div = $(
  2302. ".sent_tran[dbid='" + result.id + "'][channel='" + result.channal + "'][sid='" + sid + "']"
  2303. );
  2304. if (sent_tran_div) {
  2305. sent_tran_div.removeClass("loading");
  2306. }
  2307. if (result.commit_type == 1 || result.commit_type == 2) {
  2308. ntf_show("成功修改");
  2309. if (sent_tran_div) {
  2310. update_sent_text(sent_tran_div,result);
  2311. }
  2312. } else if (result.commit_type == 3) {
  2313. ntf_show("已经提交修改建议");
  2314. } else {
  2315. ntf_show("未提交");
  2316. }
  2317. }
  2318. }
  2319. function update_sent_text(sent_tran_div,result){
  2320. let divPreview = sent_tran_div.find(".preview").first();
  2321. let objTextarea = sent_tran_div.find(".text_input").children("textarea").first();
  2322. let thisChannel = find_channal(result.channal);
  2323. objTextarea.val(result.text);
  2324. if (result.text == "") {
  2325. //内容为空
  2326. let channel_info = "Empty";
  2327. if (thisChannel) {
  2328. channel_info = thisChannel.name + "-" + thisChannel.nickname;
  2329. }
  2330. divPreview.html("<span style='color:var(--border-line-color);'>" + channel_info + "</span>");
  2331. } else {
  2332. for (const iterator of _arrData) {
  2333. if (
  2334. iterator.book == result.book &&
  2335. iterator.para == result.para &&
  2336. iterator.begin == result.begin &&
  2337. iterator.end == result.end
  2338. ) {
  2339. for (const tran of iterator.translation) {
  2340. if (tran.channal == result.channal) {
  2341. tran.text = result.text;
  2342. break;
  2343. }
  2344. }
  2345. }
  2346. }
  2347. switch (thisChannel.type) {
  2348. case 'nissaya':
  2349. let nissayaHtml = "";
  2350. nissayaHtml += "<div class='nissaya'>";
  2351. nissayaHtml += note_init(renderNissayaPreview(result.text), result.channal, result.editor, result.lang);
  2352. nissayaHtml += "</div>";
  2353. divPreview.html(nissayaHtml);
  2354. break;
  2355. case 'commentary':
  2356. divPreview.html(
  2357. note_init(result.text, result.channal, result.editor, result.lang)
  2358. );
  2359. note_refresh_new();
  2360. break;
  2361. case 'original':
  2362. switch (getCookie('language')) {
  2363. case 'my':
  2364. //缅文
  2365. result.text = roman_to_my(result.text);
  2366. objTextarea.val(result.text);
  2367. break;
  2368. }
  2369. default:
  2370. divPreview.html(
  2371. note_init(result.text, result.channal, result.editor, result.lang)
  2372. );
  2373. term_updata_translation();
  2374. break;
  2375. }
  2376. popup_init();
  2377. //初始化气泡
  2378. guide_init();
  2379. }
  2380. }
  2381. function pr_create_callback(data) {
  2382. let response;
  2383. if(typeof data=="string"){
  2384. try {
  2385. response = JSON.parse(data);
  2386. } catch (e) {
  2387. alert(e.message);
  2388. console.error('pr_create_callback',data);
  2389. return;
  2390. }
  2391. }else{
  2392. response = data;
  2393. }
  2394. if (!response.ok) {
  2395. ntf_show("修改建议提交失败");
  2396. console.log("pr_create_callback", response.message);
  2397. return;
  2398. }
  2399. let result = response.data.new;
  2400. {
  2401. let sid = result.book_id + "-" + result.paragraph + "-" + result.word_start + "-" + result.word_end;
  2402. let sent_tran_div = $(
  2403. ".sent_tran[channel='" + result.channel_uid + "'][sid='" + sid + "']"
  2404. );
  2405. if (sent_tran_div) {
  2406. sent_tran_div.removeClass("loading");
  2407. sent_tran_div.find(".tag_list").first().children(".pr").first().html(render_pr_number(1,response.data.count));
  2408. }
  2409. ntf_show("成功提交修改建议");
  2410. }
  2411. }
  2412. function pr_update_callback(data) {
  2413. let response;
  2414. if(typeof data=="string"){
  2415. try {
  2416. response = JSON.parse(data);
  2417. } catch (e) {
  2418. alert(e.message);
  2419. console.error('pr_create_callback',data);
  2420. return;
  2421. }
  2422. }else{
  2423. response = data;
  2424. }
  2425. if (!response.ok) {
  2426. ntf_show("修改建议更新失败");
  2427. console.log("pr_update_callback", response.message);
  2428. return;
  2429. }
  2430. let result = response.data;
  2431. {
  2432. let sid = result.book_id + "-" + result.paragraph + "-" + result.word_start + "-" + result.word_end;
  2433. let sent_tran_div = $(
  2434. ".sent_tran[dbid='" + result.id + "']"
  2435. );
  2436. if (sent_tran_div) {
  2437. sent_tran_div.removeClass("loading");
  2438. let orgText = "";
  2439. for (const oneSent of _arrData) {
  2440. if (
  2441. oneSent.book == result.book_id &&
  2442. oneSent.para == result.paragraph &&
  2443. oneSent.begin == result.word_start &&
  2444. oneSent.end == result.word_end
  2445. ) {
  2446. for (const tran of oneSent.translation) {
  2447. if (tran.channal == result.channel_uid) {
  2448. orgText = tran.text;
  2449. break;
  2450. }
  2451. }
  2452. break;
  2453. }
  2454. }
  2455. let tranText = str_diff(orgText, result.content);
  2456. sent_tran_div.find(".preview").html(tranText);
  2457. }
  2458. ntf_show("成功更新修改建议");
  2459. }
  2460. }
  2461. //保存译文句子
  2462. function note_sent_save() {
  2463. let id = $("#edit_dialog_text").attr("sent_id");
  2464. let book = $("#edit_dialog_text").attr("book");
  2465. let para = $("#edit_dialog_text").attr("para");
  2466. let begin = $("#edit_dialog_text").attr("begin");
  2467. let end = $("#edit_dialog_text").attr("end");
  2468. let channal = $("#edit_dialog_text").attr("channal");
  2469. let text = $("#edit_dialog_text").val();
  2470. $.post(
  2471. "../usent/sent_post.php",
  2472. {
  2473. id: id,
  2474. book: book,
  2475. para: para,
  2476. begin: begin,
  2477. end: end,
  2478. channal: channal,
  2479. text: text,
  2480. lang: "zh",
  2481. },
  2482. function (data) {
  2483. let result = JSON.parse(data);
  2484. if (result.status > 0) {
  2485. alert("error" + result.message);
  2486. } else {
  2487. if (result.commit_type == 1 || result.commit_type == 2) {
  2488. ntf_show("成功修改");
  2489. if (result.text == "") {
  2490. let channel_info = "Empty";
  2491. let thisChannel = find_channal(result.channal);
  2492. if (thisChannel) {
  2493. channel_info = thisChannel.name + "-" + thisChannel.nickname;
  2494. }
  2495. $(
  2496. "#tran_text_" +
  2497. result.book +
  2498. "_" +
  2499. result.para +
  2500. "_" +
  2501. result.begin +
  2502. "_" +
  2503. result.end +
  2504. "_" +
  2505. result.channal
  2506. ).html("<span style='color:var(--border-line-color);'>" + channel_info + "</span>");
  2507. } else {
  2508. $(
  2509. "#tran_text_" +
  2510. result.book +
  2511. "_" +
  2512. result.para +
  2513. "_" +
  2514. result.begin +
  2515. "_" +
  2516. result.end +
  2517. "_" +
  2518. result.channal
  2519. ).html(marked(term_std_str_to_tran(result.text, result.channal, result.editor, result.lang)));
  2520. term_updata_translation();
  2521. for (const iterator of _arrData) {
  2522. if (
  2523. iterator.book == result.book &&
  2524. iterator.para == result.para &&
  2525. iterator.begin == result.begin &&
  2526. iterator.end == result.end
  2527. ) {
  2528. for (const tran of iterator.translation) {
  2529. if (tran.channal == result.channal) {
  2530. tran.text = result.text;
  2531. break;
  2532. }
  2533. }
  2534. }
  2535. }
  2536. }
  2537. } else if (result.commit_type == 3) {
  2538. ntf_show("已经提交修改建议");
  2539. } else {
  2540. ntf_show("未提交");
  2541. }
  2542. }
  2543. }
  2544. );
  2545. }
  2546. function copy_ref(book, para, begin, end) {
  2547. let strRef = "{{" + book + "-" + para + "-" + begin + "-" + end + "}}";
  2548. copy_to_clipboard(strRef);
  2549. }
  2550. function goto_nissaya(book, para, begin = 0, end = 0) {
  2551. window.open("../nissaya/index.php?book=" + book + "&par=" + para + "&begin=" + begin + "&end=" + end, "nissaya");
  2552. }
  2553. function edit_in_studio(book, para, begin, end) {
  2554. wbw_channal_list_open(book, [para]);
  2555. }
  2556. //显示和隐藏某个内容 如 巴利文
  2557. function setVisibility(key, value) {
  2558. switch (key) {
  2559. case "palitext":
  2560. if ($(value).is(":checked")) {
  2561. $(".palitext").show();
  2562. } else {
  2563. $(".palitext").hide();
  2564. }
  2565. break;
  2566. default:
  2567. break;
  2568. }
  2569. }
  2570. function note_show_pali_sim(SentId) {
  2571. pali_sim_dlg_open(SentId, 0, 20);
  2572. }
  2573. function set_pali_script(pos, script) {
  2574. if (script == "none") {
  2575. $(".palitext" + pos).html("");
  2576. } else {
  2577. $(".palitext" + pos).each(function () {
  2578. let html = $(this).siblings(".palitext_roma").first().html();
  2579. $(this).html(html);
  2580. });
  2581. $(".palitext" + pos)
  2582. .find("*")
  2583. .contents()
  2584. .filter(function () {
  2585. return this.nodeType != 1;
  2586. })
  2587. .wrap("<pl" + pos + "></pl" + pos + ">");
  2588. $(".palitext" + pos)
  2589. .contents()
  2590. .filter(function () {
  2591. return this.nodeType != 1;
  2592. })
  2593. .wrap("<pl" + pos + "></pl" + pos + ">");
  2594. $("pl" + pos).html(function (index, oldcontent) {
  2595. switch(script){
  2596. case "မြန်မာ":
  2597. return roman_to_my(oldcontent);
  2598. case "My2Roman":
  2599. return my_to_roman(oldcontent);
  2600. case "සිංහල":
  2601. return roman_to_si(oldcontent);
  2602. case "ᨲ᩠ᩅᩫᨴᩱ᩠ᨿᨵᨾ᩠ᨾ᩼":
  2603. return roman_to_tai(oldcontent);
  2604. case "อักษรไทย":
  2605. return roman_to_thai(oldcontent);
  2606. default:
  2607. return(oldcontent);
  2608. }
  2609. });
  2610. }
  2611. }
  2612. function splite_pali_word() {
  2613. $("pali")
  2614. .contents()
  2615. .filter(function () {
  2616. return this.nodeType != 1;
  2617. })
  2618. .wrap("<pl></pl>");
  2619. $("pl").each(function () {
  2620. let html = $(this).html();
  2621. $(this).html("<w>" + html.replace(/\s/g, "</w> <w>") + "</w>");
  2622. });
  2623. $("w").click(function () {
  2624. let word = com_getPaliReal($(this).text());
  2625. if (gBuildinDictIsOpen) {
  2626. window.open("../dict/index.php?builtin=true&key=" + word, "dict");
  2627. }
  2628. });
  2629. }
  2630. function refresh_pali_script() {
  2631. if (_display && _display == "para") {
  2632. //段落模式
  2633. } else {
  2634. //句子模式
  2635. setting_get("lib.second_script", set_second_scrip);
  2636. }
  2637. }
  2638. function set_second_scrip(value) {
  2639. set_pali_script(2, value);
  2640. }
  2641. function slider_show(obj) {
  2642. $(obj).parent().parent().parent().parent().parent().toggleClass("slider_show_shell");
  2643. }
  2644. function find_sent_tran_div(obj) {
  2645. let jqObj = $(obj);
  2646. while (!jqObj.hasClass("sent_tran")) {
  2647. jqObj = jqObj.parent();
  2648. if (!jqObj) {
  2649. return false;
  2650. }
  2651. }
  2652. return jqObj;
  2653. /*
  2654. let parent = obj.parentNode;
  2655. while (parent.nodeType == 1) {
  2656. if ($(parent).hasClass("sent_tran")) {
  2657. return parent;
  2658. } else if (parent.nodeName == "BODY") {
  2659. return false;
  2660. }
  2661. parent = parent.parentNode;
  2662. }
  2663. return false;
  2664. */
  2665. }
  2666. //显示或隐藏pr数据
  2667. function note_pr_show(channel, id) {
  2668. let obj = $(".sent_tran[channel='" + channel + "'][sid='" + id + "']").find(".pr_content");
  2669. let prHtml = obj.first().html();
  2670. if (prHtml == "") {
  2671. note_get_pr(channel, id);
  2672. } else {
  2673. obj.slideUp();
  2674. obj.html("");
  2675. }
  2676. }
  2677. //获取pr数据并显示
  2678. function note_get_pr(channel, id) {
  2679. let sid = id.split("-");
  2680. let book = sid[0];
  2681. let para = sid[1];
  2682. let begin = sid[2];
  2683. let end = sid[3];
  2684. $.post(
  2685. "../usent/get_pr.php",
  2686. {
  2687. book: book,
  2688. para: para,
  2689. begin: begin,
  2690. end: end,
  2691. channel: channel,
  2692. },
  2693. function (data) {
  2694. let result = JSON.parse(data);
  2695. if (result.length > 0) {
  2696. let html = "<div class='compact pr'>";
  2697. for (const iterator of result) {
  2698. html += "<div class='pr_shell'>";
  2699. html += render_one_sent_tran_a(iterator, true);
  2700. html += "</div>";
  2701. }
  2702. html += "</div>";
  2703. $(".sent_tran[channel='" + channel + "'][sid='" + id + "']")
  2704. .find(".pr_content")
  2705. .html(html);
  2706. $(".sent_tran[channel='" + channel + "'][sid='" + id + "']")
  2707. .find(".pr_content")
  2708. .slideDown();
  2709. } else {
  2710. }
  2711. }
  2712. );
  2713. $(".sent_tran[channel='" + channel + "'][sid='" + id + "']")
  2714. .find(".pr_content")
  2715. .html("loading");
  2716. $(".sent_tran[channel='" + channel + "'][sid='" + id + "']")
  2717. .find(".pr_content")
  2718. .show();
  2719. }
  2720. function get_channel_by_id(id) {
  2721. if (Array.isArray(_channalData)) {
  2722. for (const iterator of _channalData) {
  2723. if (iterator.id == id) {
  2724. return iterator;
  2725. }
  2726. }
  2727. }
  2728. if (Array.isArray(_my_channal)) {
  2729. for (const iterator of _my_channal) {
  2730. if (iterator.id == id) {
  2731. return iterator;
  2732. }
  2733. }
  2734. }
  2735. return false;
  2736. }
  2737. //设置显示方向
  2738. function setDirection(obj) {
  2739. if (obj.value == "row") {
  2740. $("#contents").removeClass("vertical");
  2741. $("#contents").addClass("horizontal");
  2742. _direction = "row";
  2743. } else {
  2744. $("#contents").removeClass("horizontal");
  2745. $("#contents").addClass("vertical");
  2746. _direction = "col";
  2747. }
  2748. }
  2749. //设置逐段或逐句模式
  2750. function setDisplay(obj) {
  2751. if (obj.value == "para") {
  2752. $("#contents").removeClass("sent_mode");
  2753. $("#contents").addClass("para_mode");
  2754. _display = "para";
  2755. } else {
  2756. $("#contents").removeClass("para_mode");
  2757. $("#contents").addClass("sent_mode");
  2758. _display = "sent";
  2759. }
  2760. }
  2761. //获取文章中H 并渲染为目录
  2762. function render_heading_toc() {
  2763. //$(":header")
  2764. }
  2765. //术语输入At
  2766. const _term_max_menu=9;
  2767. function term_set_word_list_data(el){
  2768. let sid = $(el).attr("sid");
  2769. let asid = sid.split("-");
  2770. let words=new Array();
  2771. let tmpWords = [];
  2772. term_data=[];
  2773. for (const it of _arrData) {
  2774. if(it.book==asid[0] && it.para==asid[1] && it.begin==asid[2] && it.end==asid[3]){
  2775. let palitext = it.palitext;
  2776. words = palitext.split(" ");
  2777. }
  2778. }
  2779. console.log("word",words);
  2780. //查询parent
  2781. for (let index = 0; index < words.length; index++) {
  2782. words[index] = com_getPaliReal(words[index]);
  2783. if(words[index]!=""){
  2784. let parents = term_parent(words[index]);
  2785. for (const key in parents) {
  2786. if (parents.hasOwnProperty.call(parents, key)) {
  2787. //term_data.push({word:key,en:com_getPaliEn(key),weight:weight});
  2788. tmpWords[key]={word:key,en:com_getPaliEn(key),weight:3,exist:0};
  2789. }
  2790. }
  2791. }
  2792. }
  2793. for (const iterator of arrTermAllPali) {
  2794. if(tmpWords.hasOwnProperty(iterator.word)){
  2795. tmpWords[iterator.word].weight+=1;
  2796. tmpWords[iterator.word].exist=1;
  2797. }else{
  2798. tmpWords[iterator.word]={word:iterator.word,en:com_getPaliEn(iterator.word),weight:1,exist:1};
  2799. }
  2800. }
  2801. //arrMyTerm 词头查重
  2802. let tmpMyTerm=[];
  2803. for (const iterator of arrMyTerm) {
  2804. tmpMyTerm[iterator.word]=1;
  2805. }
  2806. //加入到列表
  2807. //在我的字典中的排名靠前
  2808. for (const key in tmpMyTerm) {
  2809. if (tmpMyTerm.hasOwnProperty.call(tmpMyTerm, key)) {
  2810. if(tmpWords.hasOwnProperty(key)){
  2811. tmpWords[key].weight+=1;
  2812. tmpWords[key].exist=2;
  2813. }else{
  2814. tmpWords[key]={word:key,en:com_getPaliEn(key),weight:1,exist:2};
  2815. }
  2816. }
  2817. }
  2818. for (const key in tmpWords) {
  2819. if (tmpWords.hasOwnProperty.call(tmpWords, key)) {
  2820. const element = tmpWords[key];
  2821. term_data.push(element);
  2822. }
  2823. }
  2824. term_data.sort(function(a,b){
  2825. return b.weight-a.weight;
  2826. });
  2827. }
  2828. function text_input_textarea_focuse(el){
  2829. term_set_word_list_data(el);
  2830. term_input_text = el;
  2831. term_input_text.onresize = function(){
  2832. term_input_text.parentElement.querySelector(".text_shadow").style.height=term_input_text.clientHeight+"px";
  2833. }
  2834. term_input_text.onkeydown = function (e) {
  2835. let menu = term_input_text.parentElement.querySelector('.menu');
  2836. switch (e.key) {
  2837. case "ArrowDown"://down arrow
  2838. if(menu.style.display=="block"){
  2839. menuFocusIndex++;
  2840. if(menuFocusIndex>_term_max_menu){
  2841. menuFocusIndex=_term_max_menu;
  2842. }
  2843. menu.innerHTML=TermAtRenderMenu({focus:menuFocusIndex});
  2844. return false;
  2845. }
  2846. break;
  2847. case "ArrowUp"://up arrow
  2848. if(menu.style.display=="block"){
  2849. menuFocusIndex--;
  2850. if(menuFocusIndex<0){
  2851. menuFocusIndex=0;
  2852. }
  2853. menu.innerHTML=TermAtRenderMenu({focus:menuFocusIndex});
  2854. return false;
  2855. }
  2856. break;
  2857. case "Enter":
  2858. if(menu.style.display=="block"){
  2859. term_insert(term_filterd_data[menuFocusIndex]);
  2860. return false;
  2861. }
  2862. if (e.ctrlKey) {
  2863. //回车存盘
  2864. tran_sent_save(e.currentTarget);
  2865. return false;
  2866. }
  2867. break;
  2868. case "Escape":
  2869. if(menu.style.display=="block"){
  2870. term_at_menu_hide();
  2871. }else{
  2872. tran_sent_edit_cancel(e.currentTarget);
  2873. }
  2874. break;
  2875. default:
  2876. break;
  2877. }
  2878. }
  2879. term_input_text.onkeyup = function (e) {
  2880. let textHeight = term_input_text.parentElement.querySelector(".text_shadow").scrollHeight;
  2881. let textHeight2 = term_input_text.clientHeight;
  2882. if(textHeight2>textHeight){
  2883. textHeight=textHeight2;
  2884. }
  2885. term_input_text.style.height = textHeight+"px";
  2886. console.log("text height",textHeight);
  2887. let value = term_input_text.value
  2888. let selectionStart = term_input_text.selectionStart
  2889. let str1 = value.slice(0, selectionStart)
  2890. let str2 = value.slice(selectionStart)
  2891. let textNode1 = document.createTextNode(str1)
  2892. let textNode2 = document.createTextNode(str2)
  2893. let cursor = document.createElement('span')
  2894. cursor.innerHTML = '&nbsp;'
  2895. cursor.setAttribute('class','cursor')
  2896. let mirror = term_input_text.parentElement.querySelector('.text_shadow')
  2897. mirror.innerHTML = ''
  2898. mirror.appendChild(textNode1)
  2899. mirror.appendChild(cursor)
  2900. mirror.appendChild(textNode2)
  2901. let menu = term_input_text.parentElement.querySelector('.menu');
  2902. if(str1.slice(-2)=="[[" ){
  2903. if( menu.style.display!="block"){
  2904. menuFocusIndex=0;
  2905. menu.innerHTML=TermAtRenderMenu({focus:0});
  2906. term_at_menu_show(cursor);
  2907. }
  2908. }else{
  2909. if( menu.style.display=="block"){
  2910. let pos1=str1.lastIndexOf("[[");
  2911. let pos2=str1.lastIndexOf("]]");
  2912. if(pos1==-1 || (pos1!=-1 && pos2>pos1)){
  2913. //光标前没有[[ 或 光标在[[]] 之后
  2914. term_at_menu_hide();
  2915. }
  2916. }
  2917. }
  2918. if(menu.style.display=="block"){
  2919. //term_input += e.key;
  2920. let value = term_input_text.value
  2921. let selectionStart = term_input_text.selectionStart
  2922. let str1 = value.slice(0, selectionStart)
  2923. let str2 = value.slice(selectionStart)
  2924. let pos1=str1.lastIndexOf("[[");
  2925. let pos2=str1.lastIndexOf("]]");
  2926. if(pos1!=-1){
  2927. if(pos2==-1 || pos2<pos1){
  2928. //光标
  2929. term_input = str1.slice(str1.lastIndexOf("[[")+2);
  2930. }
  2931. }
  2932. console.log("term_input",term_input);
  2933. menu.innerHTML=TermAtRenderMenu({focus:menuFocusIndex});
  2934. }
  2935. console.log(e.key);
  2936. console.log(cursor.offsetLeft,cursor.offsetTop)
  2937. }
  2938. }
  2939. function term_at_menu_show(cursor){
  2940. menuFocusIndex=0;
  2941. let menu = term_input_text.parentElement.querySelector('.menu');
  2942. menu.style.display="block";
  2943. menu.style.top=cursor.offsetTop+20+"px";
  2944. menu.style.left=cursor.offsetLeft+"px";
  2945. $(document).on("keyup", function (e) {
  2946. if(e.key=="Escape"){
  2947. term_at_menu_hide();
  2948. }
  2949. });
  2950. }
  2951. function term_at_menu_hide(){
  2952. let menu = term_input_text.parentElement.querySelector('.menu');
  2953. menu.style.display="none";
  2954. term_input="";
  2955. }
  2956. function term_insert(strTerm){
  2957. let value = term_input_text.value;
  2958. let selectionStart = term_input_text.selectionStart;
  2959. let str1 = value.slice(0, selectionStart)
  2960. let str2 = value.slice(selectionStart)
  2961. let pos1=str1.lastIndexOf("[[");
  2962. let pos2=str1.lastIndexOf("]]");
  2963. if(pos1!=-1){
  2964. //光标前有[[
  2965. if(pos2==-1 || pos2<pos1){
  2966. //光标在[[之间]]
  2967. str1 = str1.slice(0,str1.lastIndexOf("[[")+2);
  2968. }
  2969. }
  2970. //TODO 光标会跑到最下面
  2971. term_input_text.value = str1+strTerm+"]]"+str2;
  2972. term_at_menu_hide();
  2973. }
  2974. function TermAtRenderMenu(params) {
  2975. term_filterd_data=[];
  2976. let html="";
  2977. html +="<div class='term_at_menu_input'>"+term_input+"|</div>";
  2978. html +="<ul class='term_at_menu_ul'>";
  2979. let index=0;
  2980. let focusIndex = params.focus%term_data.length;
  2981. for (const it of term_data) {
  2982. if(term_input=="" || it.word.indexOf(term_input)==0 || it.en.indexOf(term_input)==0){
  2983. html +="<li ";
  2984. if(focusIndex==index){
  2985. html +="class='trem_focus' "
  2986. }
  2987. html += "onclick=\"term_insert('"+it.word+"')\" ";
  2988. html +=">";
  2989. html += (index+1)+ ". ";
  2990. if(it.exist>0){
  2991. html += "<b>"+it.word+"</b>";
  2992. }else{
  2993. html +=it.word;
  2994. }
  2995. html +="<li>";
  2996. term_filterd_data.push(it.word);
  2997. if(index >= _term_max_menu){
  2998. break;
  2999. }
  3000. index++;
  3001. }
  3002. }
  3003. return html;
  3004. }
  3005. //添加自动格位数据到内存字典
  3006. function term_parent(paliword) {
  3007. let output=[];
  3008. for (const it of gCaseTable) {
  3009. if (it.type != ".v.") {
  3010. let sEnd2 = paliword.slice(0 - it.end2.length);
  3011. if (sEnd2 == it.end2) {
  3012. let wordParent = paliword.slice(0, 0 - it.end2.length) + it.end1;
  3013. output[wordParent]=1;
  3014. }
  3015. }
  3016. }
  3017. return output;
  3018. }
  3019. function setSentToolBarEvent(){
  3020. $('.sent_tran_inner').not('.commentary').off('mouseenter').on('mouseenter',function(){
  3021. $(this).children('.tool_bar').first().children('.right').show();
  3022. });
  3023. $('.sent_tran_inner').not('.commentary').off('mouseleave').on('mouseleave',function(){
  3024. $(this).children('.tool_bar').first().children('.right').hide();
  3025. })
  3026. }