note.js 64 KB

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