note.js 79 KB

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