note.js 70 KB

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