note.js 67 KB

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