note.js 69 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552
  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. //初始化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. if(iterator.channalinfo.type != "commentary"){
  664. output += render_one_sent_tran_a(iterator);
  665. }
  666. }
  667. output += "</div>";
  668. //译文结束
  669. output += "</div>"; /**note_body end */
  670. //工具栏开始
  671. let sent_id = in_json.book + "-" + in_json.para + "-" + in_json.begin + "-" + in_json.end;
  672. output += "<div class='other_tran_div' sent='" + sent_id + "' >";
  673. output += "<div class='tool_bar' sent='" + sent_id + "' >";
  674. output += "<span class='tool_left'>";
  675. //第一个按钮
  676. //新增译文按钮开始
  677. output += "<span class='' ";
  678. output += "book='" + in_json.book + "' ";
  679. output += "para='" + in_json.para + "' ";
  680. output += "begin='" + in_json.begin + "' ";
  681. output += "end='" + in_json.end + "' ";
  682. output += " >";
  683. output += "<span class='' onclick='add_new_tran_button_click(this)' title='" + gLocal.gui.add_tran + "'>➕</span>";
  684. output += "<div class='tran_text_tool_bar'>";
  685. output += "</div>";
  686. output += "</span>";
  687. //新增译文按钮结束
  688. //分隔线
  689. output += "<span class='separate_line'></span>";
  690. output += "<span class='more_tran icon_expand'></span>";
  691. //第二个按钮其他译文
  692. output += "<span class='other_bar' sent='"+sent_id+"' channel_type='translation'>";
  693. output +=
  694. "<span class='other_tran_span' title='" +
  695. gLocal.gui.other +
  696. gLocal.gui.translation +
  697. "'>";
  698. output += "<svg class='icon' style='fill: var(--box-bg-color1)'>";
  699. output += "<use xlink:href='../../node_modules/bootstrap-icons/bootstrap-icons.svg#translate'>";
  700. output += "</svg>" ;
  701. output += gLocal.gui.translation ;
  702. output += "</span>";
  703. output += "<span class='other_tran_num'></span>";
  704. output += "</span>";
  705. //第二个按钮结束
  706. //分割线
  707. output += "<span class='separate_line'></span>";
  708. //nissaya
  709. output += "<span class='other_bar' sent='"+sent_id+"' channel_type='nissaya' >";
  710. output +=
  711. "<span class='other_nissaya_span' title='" +
  712. gLocal.gui.other +
  713. gLocal.gui.translation +
  714. "'>";
  715. output += "<svg class='icon' style='fill: var(--box-bg-color1)'>";
  716. output += "<use xlink:href='../../node_modules/bootstrap-icons/bootstrap-icons.svg#sun'>";
  717. output += "</svg>" ;
  718. output += "Nissaya" ;
  719. output += "</span>";
  720. output += "<span class='other_tran_num'></span>";
  721. output += "</span>";
  722. //分割线
  723. output += "<span class='separate_line'></span>";
  724. //手工义注
  725. output += "<span class='other_bar' sent='"+sent_id+"' channel_type='commentary' >";
  726. output +=
  727. "<span class='other_tran_span commentray' title='📔" +
  728. gLocal.gui.vannana +
  729. "'>";
  730. output += "<svg class='icon' style='fill: var(--box-bg-color1)'>";
  731. output += "<use xlink:href='../public/images/svg/oil-lamp.svg#oil-lamp'>";
  732. output += "</svg>" ;
  733. output += gLocal.gui.commentary +
  734. "</span>";
  735. output += "<span class='other_tran_num'></span>";
  736. output += "</span>";
  737. //分割线
  738. output += "<span class='separate_line'></span>";
  739. //第三个按钮 相似句
  740. if (parseInt(in_json.sim) > 0) {
  741. output += "<span class='sim_bar' >";
  742. output +=
  743. "<span class='similar_sent_span' onclick=\"note_show_pali_sim('" +
  744. in_json.pali_sent_id +
  745. "')\" title='" +
  746. gLocal.gui.similar_sentences +
  747. "'>";
  748. output += "<svg class='icon' style='fill: var(--box-bg-color1)'>";
  749. output += "<use xlink:href='../../node_modules/bootstrap-icons/bootstrap-icons.svg#hdd-stack'>";
  750. output += "</svg>" ;
  751. output += gLocal.gui.similar + "</span>";
  752. output += "<span class='similar_sent_num'>" + in_json.sim + "</span>";
  753. output += "</span>";
  754. output += "<span class='separate_line'></span>";
  755. }
  756. //第三个按钮 相似句结束
  757. output += "</span>";
  758. output += "<span class='tool_right'>";
  759. //出处路径开始
  760. output += "<span class='ref'>";
  761. output += "<span class='book_name tooltip'>" + in_json.booktitle;
  762. output += "<span class='tooltiptext tooltip-bottom'>";
  763. output += in_json.ref;
  764. output += "</span>";
  765. output += "<span class='sent_no'>";
  766. output += in_json.book + "-" + in_json.para + "-" + in_json.begin + "-" + in_json.end;
  767. output += "<span>";
  768. output += "</span>";
  769. output += "</span>";
  770. //出处路径结束
  771. output += "</span>";
  772. output += "</div>";
  773. //工具栏结束
  774. //未选择的其他译文开始
  775. output += "<div class='other_tran'>";
  776. output += "</div>";
  777. output += "</div>";
  778. return output;
  779. }
  780. //设置取消输入框的编辑模式
  781. function sent_tran_set_edit_mode(obj, isEditMode) {
  782. $(".sent_tran").removeClass("edit_mode");
  783. if (isEditMode) {
  784. let jqObj = $(obj);
  785. while (!jqObj.hasClass("sent_tran")) {
  786. jqObj = jqObj.parent();
  787. if (!jqObj) {
  788. return;
  789. }
  790. }
  791. jqObj.addClass("edit_mode");
  792. }
  793. }
  794. function sent_tran_edit(obj) {
  795. let jqObj = $(obj);
  796. while (!jqObj.hasClass("sent_tran")) {
  797. jqObj = jqObj.parent();
  798. if (!jqObj) {
  799. return;
  800. }
  801. }
  802. if (jqObj.hasClass("edit_mode")) {
  803. jqObj.removeClass("edit_mode");
  804. } else {
  805. $(".sent_tran").removeClass("edit_mode");
  806. jqObj.addClass("edit_mode");
  807. }
  808. }
  809. //采纳 pr
  810. function sent_pr_merge(id) {
  811. $.post(
  812. "../usent/sent_pr_merge.php",
  813. {
  814. id: id,
  815. },
  816. function (data) {
  817. let result = JSON.parse(data);
  818. if (result.status > 0) {
  819. alert("error" + result.message);
  820. } else {
  821. ntf_show("成功采纳");
  822. }
  823. }
  824. );
  825. }
  826. function sent_commit(src, id) {
  827. commit_init({
  828. src: src,
  829. sent: [id],
  830. express: false,
  831. });
  832. }
  833. function render_icon_button(icon_id, event, tiptitle) {
  834. let html = "";
  835. html += "<button class='icon_btn tooltip' onclick=\"" + event + '">';
  836. html += '<svg class="icon" >';
  837. html += '<use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#' + icon_id + '"></use>';
  838. html += "</svg>";
  839. html += "<span class='tooltiptext tooltip-top'>";
  840. html += tiptitle;
  841. html += "</span>";
  842. html += "</button>";
  843. return html;
  844. }
  845. var menuFocusIndex=0;
  846. var term_data=["amanussa","anadhiṭṭhita","anantarāya","anissaṭṭha","aniyata","antaravāsaka"];
  847. var term_filterd_data=[];
  848. var term_input_text ;
  849. var term_input="";
  850. function TermRenderSentTranTextarea(text,dbId,sentId,channelId,isPr){
  851. let html="";
  852. html += '<div class="text_input" >';
  853. html += '<div class="menu"></div>';
  854. html += '<div class="textarea text_shadow"></div>';
  855. html += "<textarea class='textarea tran_sent_textarea' onfocus=\"text_input_textarea_focuse(this)\"";
  856. html += " dbid='" + dbId + "' ";
  857. html += "sid='" + sentId + "' ";
  858. html += "channel='" + channelId + "' ";
  859. if (typeof isPr != "undefined" && isPr == true) {
  860. html += ' is_pr="true" "';
  861. } else {
  862. html += 'is_pr="false"';
  863. }
  864. html += ">" ;
  865. html += text;
  866. html += "</textarea>";
  867. html += '</div>';
  868. return html;
  869. }
  870. function render_one_sent_tran_a(iterator, diff = false) {
  871. let mChannel = get_channel_by_id(iterator.channal);
  872. let tranText;
  873. let sid = iterator.book + "-" + iterator.para + "-" + iterator.begin + "-" + iterator.end;
  874. //将绝对链接转换为 用户连接的主机链接
  875. //let showText = iterator.text.replace(/www-[A-z]*.wikipali.org/g,location.host);
  876. let showText = iterator.text;
  877. if (iterator.text == "") {
  878. if (typeof iterator.channalinfo == "undefined") {
  879. tranText =
  880. "<span style='color:var(--border-line-color);'>" +
  881. "空" +
  882. "@" +
  883. iterator.editor_name.nickname +
  884. "</span>";
  885. } else {
  886. tranText =
  887. "<span style='color:var(--border-line-color);'>" +
  888. iterator.channalinfo.name +
  889. "-" +
  890. iterator.channalinfo.lang +
  891. "</span>";
  892. }
  893. } else {
  894. if (diff) {
  895. let orgText = "";
  896. for (const oneSent of _arrData) {
  897. if (
  898. oneSent.book == iterator.book &&
  899. oneSent.para == iterator.para &&
  900. oneSent.begin == iterator.begin &&
  901. oneSent.end == iterator.end
  902. ) {
  903. for (const tran of oneSent.translation) {
  904. if (tran.channal == iterator.channal) {
  905. orgText = tran.text;
  906. break;
  907. }
  908. }
  909. break;
  910. }
  911. }
  912. tranText = str_diff(orgText, iterator.text);
  913. } else {
  914. //note_init处理句子链接
  915. if(iterator.type=='nissaya' || iterator.channalinfo.type=='nissaya'){
  916. tranText = renderNissayaPreview(iterator.text);
  917. }else{
  918. tranText = iterator.text;
  919. }
  920. tranText = note_init(term_std_str_to_tran(tranText, iterator.channal, iterator.editor, iterator.lang));
  921. if(iterator.type=='nissaya' || iterator.channalinfo.type=='nissaya'){
  922. tranText = "<div class='nissaya'>"+tranText+"</div>";
  923. }
  924. }
  925. }
  926. let html = "";
  927. html += "<div class='sent_tran ";
  928. if (typeof iterator.is_pr != "undefined" && iterator.is_pr == true) {
  929. html += " pr ";
  930. }
  931. html += "' dbid='" + iterator.id + "' channel='" + iterator.channal + "' sid='" + sid + "'>";
  932. html += "<div class='sent_tran_inner'>";
  933. html += '<div class="tool_bar">';
  934. html += ' <div class="right">';
  935. //句子菜单
  936. html += '<div class="pop_menu">';
  937. if (typeof iterator.is_pr != "undefined" && iterator.is_pr == true) {
  938. //在pr 列表中的译文
  939. if (typeof iterator.is_pr_editor != "undefined" && iterator.is_pr_editor == true) {
  940. //提交人
  941. //修改按钮
  942. html += render_icon_button("ic_mode_edit", "sent_tran_edit(this)", gLocal.gui.modify);
  943. //删除按钮
  944. html += render_icon_button("ic_delete", "sent_pr_del(this)", gLocal.gui.delete);
  945. } else {
  946. //非提交人
  947. if (parseInt(iterator.mypower) >= 20) {
  948. //有权限 采纳按钮
  949. html += render_icon_button(
  950. "accept_copy",
  951. "sent_pr_merge('" + iterator.id + "')",
  952. gLocal.gui.accept_copy
  953. );
  954. }
  955. //点赞按钮
  956. html += render_icon_button("like", "sent_pr_like(this)", gLocal.gui.like);
  957. }
  958. } else {
  959. //非pr列表里的句子
  960. //编辑按钮
  961. if (parseInt(iterator.mypower) < 20) {
  962. html += render_icon_button("my_idea", "sent_tran_edit(this)", gLocal.gui.suggest);
  963. } else {
  964. html += render_icon_button("ic_mode_edit", "sent_tran_edit(this)", gLocal.gui.edit);
  965. }
  966. //推送按钮
  967. let commitIcon = "";
  968. let commitTipText = "";
  969. if (parseInt(iterator.mypower) >= 30 && parseInt(iterator.status) < 30) {
  970. //我的私有资源 公开发布
  971. commitIcon = "publish";
  972. commitTipText = gLocal.gui.publish;
  973. } else {
  974. if (parseInt(iterator.mypower) < 20) {
  975. //只读资源 采纳
  976. commitIcon = "accept_copy";
  977. commitTipText = gLocal.gui.accept_copy;
  978. } else {
  979. //其他资源 复制到
  980. commitIcon = "copy";
  981. commitTipText = gLocal.gui.copy_to;
  982. }
  983. }
  984. html += render_icon_button(commitIcon, "sent_commit('" + iterator.channal + "','" + sid + "')", commitTipText);
  985. //推送按钮结束
  986. //更多按钮
  987. html += '<div class="case_dropdown">';
  988. html += "<button class='icon_btn'>";
  989. html += '<svg class="icon" >';
  990. html += '<use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#ic_more"></use>';
  991. html += "</svg>";
  992. html += "</button>";
  993. html += '<div class="case_dropdown-content menu_space_between" style="right:0;">';
  994. //时间线
  995. html += "<a onclick=\"history_show('" + iterator.id + "')\">";
  996. html += "<span>" + gLocal.gui.timeline + "</span>";
  997. html += '<svg class="icon" >';
  998. html += '<use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#recent_scan"></use>';
  999. html += "</svg>";
  1000. html += "</a>";
  1001. //复制
  1002. html += "<a onclick=\"history_show('" + iterator.id + "')\">";
  1003. html += "<span>" + gLocal.gui.copy + "</span>";
  1004. html += '<svg class="icon" >';
  1005. html += '<use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#copy"></use>';
  1006. html += "</svg>";
  1007. html += "</a>";
  1008. //点赞
  1009. html += "<a onclick=\"history_show('" + iterator.id + "')\">";
  1010. html += "<span>" + gLocal.gui.like + "</span>";
  1011. html += '<svg class="icon" >';
  1012. html += '<use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#like"></use>';
  1013. html += "</svg>";
  1014. html += "</a>";
  1015. //分享
  1016. html += "<a onclick=\"history_show('" + iterator.id + "')\">";
  1017. html += "<span>" + gLocal.gui.share_to + "</span>";
  1018. html += '<svg class="icon" >';
  1019. html += '<use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#share_to"></use>';
  1020. html += "</svg>";
  1021. html += "</a>";
  1022. html += "</div>";
  1023. html += "</div>";
  1024. //更多按钮结束
  1025. }
  1026. html += "</div>";
  1027. //句子菜单结束
  1028. html += "</div>";
  1029. html += "</div>";
  1030. //tool_bar 结束
  1031. html += '<div class="left_bar" >';
  1032. html += "<span class='icon_sent_status icon_sent_loading'>";
  1033. html +=
  1034. "<svg class='icon icon_spin' style='fill: var(--detail-color); '>" +
  1035. "<use xlink='http://www.w3.org/1999/xlink' href='../studio/svg/icon.svg#loading'></use>" +
  1036. "</svg>";
  1037. html += "</span>";
  1038. html += "<span class='icon_sent_status icon_sent_error' title='再次发送' onclick='tran_sent_save(this)'>";
  1039. html +=
  1040. "<svg class='icon' style='fill: red; '>" +
  1041. "<use xlink='http://www.w3.org/1999/xlink' href='../term/error.svg'></use>" +
  1042. "</svg>";
  1043. html += "</span>";
  1044. html += ' <div class="face">';
  1045. if (iterator.id != "") {
  1046. html += '<span class="head_img">' + iterator.editor_name.nickname.slice(0, 1) + "</span>";
  1047. }
  1048. html += "</div>";
  1049. html +=
  1050. '<div class="date" title="' +
  1051. getFullDataTime(iterator.update_time) +
  1052. '">' +
  1053. getDataTime(iterator.update_time) +
  1054. "</div>";
  1055. html += "</div>";
  1056. html += '<div class="body">';
  1057. html += '<div class="head_bar">';
  1058. html += '<div class="info">';
  1059. html += '<span class="name channel_name" title="' + iterator.editor_name.nickname + gLocal.gui.recent_update + '">';
  1060. if (typeof iterator.channalinfo == "undefined") {
  1061. html += "unkown";
  1062. } else {
  1063. html += iterator.channalinfo.name;
  1064. }
  1065. html += "</span>";
  1066. html += '<span class="name editor_name" ';
  1067. if (typeof iterator.channalinfo == "undefined") {
  1068. html += ">";
  1069. html += "unkown";
  1070. } else {
  1071. html += 'title="' + iterator.channalinfo.name + gLocal.gui.recent_update + '">';
  1072. html += iterator.editor_name.nickname;
  1073. }
  1074. html += "</span>";
  1075. html += '<span class="date">' + getPassDataTime(iterator.update_time) + "</span>";
  1076. html += "</div>";
  1077. html += "<div class='preview'>" + tranText + "</div>";
  1078. html += "</div>";
  1079. html += '<div class="edit">';
  1080. html += '<div class="input">';
  1081. //输入框
  1082. html += TermRenderSentTranTextarea(iterator.text,iterator.id,sid,iterator.channal,iterator.is_pr);
  1083. html += "</div>";
  1084. html += '<div class="edit_tool">';
  1085. //html += ""
  1086. html += '<span style="display: inline-flex;">';
  1087. html += '<span class="keybutton" >ESC</span> = ';
  1088. html += "<a onclick='tran_sent_edit_cancel(this)'>" + gLocal.gui.cancel + "</a>";
  1089. html += "</span>";
  1090. html += "<span style='display: inline-flex;'>";
  1091. html += '<span class="keybutton" >Ctrl/⌘</span>';
  1092. html += "➕";
  1093. html += '<span class="keybutton" >Enter</span> = ';
  1094. if (parseInt(iterator.mypower) < 20) {
  1095. html += "<a onclick='tran_sent_save(this)'>";
  1096. html += gLocal.gui.submit + "<b>" + gLocal.gui.suggest + gLocal.gui.translation + "</b>";
  1097. html += "</a></span><span style='display: inline-flex;'>";
  1098. } else {
  1099. html += "<a onclick='tran_sent_save(this)'>";
  1100. html += gLocal.gui.save;
  1101. html += "</a></span><span style='display: inline-flex;'>";
  1102. }
  1103. html += '<span class="keybutton" >Enter</span> = ';
  1104. html += gLocal.gui.next_line;
  1105. html += "</span><span style='display: inline-flex;'>MarkDown✅</span>";
  1106. html += "</div>";
  1107. html += "</div>";
  1108. html += '<div class="foot_bar">';
  1109. html += '<div class="info">';
  1110. if (iterator.id != "") {
  1111. html += '<span class="date"> ' + getPassDataTime(iterator.update_time) + "</span>";
  1112. }
  1113. if (iterator.id != "") {
  1114. html += '<span class="name">' + iterator.editor_name.nickname + "</span>";
  1115. }
  1116. if (iterator.id != "") {
  1117. html += '<span class="channel">' + gLocal.gui.updated + " ";
  1118. if (typeof iterator.channalinfo == "undefined") {
  1119. html += "unkown";
  1120. } else {
  1121. html += "<a title='" + iterator.channalinfo.summary + "'>" + iterator.channalinfo.name + "@</a>";
  1122. }
  1123. html += "</span>";
  1124. } else {
  1125. html += '<span class="channel">' + gLocal.gui.no_updated + " @";
  1126. if (typeof iterator.channalinfo == "undefined") {
  1127. html += "unkown";
  1128. } else {
  1129. html += "<a title='" + iterator.channalinfo.owner + "'>" + iterator.channalinfo.name + "@</a>";
  1130. }
  1131. html += "</span>";
  1132. }
  1133. html += '<ul class="tag_list">';
  1134. if (iterator.pr_all && parseInt(iterator.pr_all) > 0) {
  1135. html +=
  1136. "<li onclick=\"note_pr_show('" +
  1137. iterator.channal +
  1138. "','" +
  1139. sid +
  1140. "')\"><span class='icon'>✋</span><span class='num'>" +
  1141. iterator.pr_new +
  1142. "/" +
  1143. iterator.pr_all +
  1144. "</span></li>";
  1145. }
  1146. html += "</ul>";
  1147. html += "</div>"; //end of info
  1148. html += "</div>"; //end of foot bar
  1149. html += "</div>";
  1150. html += "</div>";
  1151. //sent_tran_inner结束
  1152. html += '<div class="pr_content"></div>';
  1153. html += "</div>";
  1154. return html;
  1155. }
  1156. function renderNissayaPreview(str){
  1157. let html ='';
  1158. //html +="<div class='nissaya'>";
  1159. const sent = str.split("\n");
  1160. for (const iterator of sent) {
  1161. const word = iterator.split("=");
  1162. if(iterator.indexOf('=')>=0){
  1163. html += "<span class='nsy_word'>"
  1164. html += "<span class='org'>";
  1165. switch (getCookie('language')) {
  1166. case 'my':
  1167. html += $.trim(word[0]) + "၊";
  1168. break;
  1169. default:
  1170. html += my_to_roman(word[0]);
  1171. break;
  1172. }
  1173. html += "</span>";
  1174. html += "<span class='meaning'>"+ word[1]+"</span>";
  1175. html += "</span>";
  1176. }else{
  1177. html += iterator;
  1178. }
  1179. }
  1180. //html += "</div>";
  1181. return html;
  1182. }
  1183. function tran_sent_textarea_event_init() {
  1184. let textarea = document.querySelectorAll(".tran_sent_textarea");
  1185. for (let iterator of textarea) {
  1186. iterator.onkeydown = function (e) {
  1187. let menu = document.querySelector("#menu");
  1188. switch (e.key) {
  1189. case "Enter":
  1190. if (menu && menu.style.display == "block") {
  1191. let value = textarea.value;
  1192. let selectionStart = textarea.selectionStart;
  1193. let str1 = value.slice(0, selectionStart);
  1194. let str2 = value.slice(selectionStart);
  1195. textarea.value = str1 + data[menuFocusIndex] + "]]" + str2;
  1196. menu.style.display = "none";
  1197. return false;
  1198. } else {
  1199. if (e.ctrlKey) {
  1200. //回车存盘
  1201. tran_sent_save(e.currentTarget);
  1202. return false;
  1203. }
  1204. }
  1205. break;
  1206. case "Escape":
  1207. tran_sent_edit_cancel(e.currentTarget);
  1208. break;
  1209. default:
  1210. break;
  1211. }
  1212. };
  1213. }
  1214. }
  1215. function render_one_sent_tran(book, para, begin, end, iterator) {
  1216. let output = "";
  1217. output += "<div class='tran' lang='" + iterator.lang + "' style='display:flex;'>";
  1218. //译文工具按钮开始
  1219. output += "<div class='tran_text_tool_botton' onclick='tool_bar_show(this)'>";
  1220. output +=
  1221. "<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>";
  1222. //译文工具栏开始
  1223. output += "<div class='tran_text_tool_bar'>";
  1224. output += "<div style='border-right: solid 1px;margin: 0.3em 0;'><li class = 'tip_buttom' ";
  1225. output +=
  1226. " onclick=\"note_edit_sentence('" +
  1227. book +
  1228. "' ,'" +
  1229. para +
  1230. "' ,'" +
  1231. begin +
  1232. "' ,'" +
  1233. end +
  1234. "' ,'" +
  1235. iterator.channal +
  1236. "')\"";
  1237. output +=
  1238. ">" +
  1239. '<svg class="icon" ><use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#ic_mode_edit"></use></svg>';
  1240. output += gLocal.gui.edit + "</li>";
  1241. output += "<li class = 'tip_buttom' ";
  1242. output += " onclick=\"history_show('" + iterator.id + "')\" >";
  1243. output +=
  1244. '<svg class="icon" ><use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#recent_scan"></use></svg>';
  1245. output += gLocal.gui.timeline + "</li>";
  1246. output +=
  1247. "<li class = 'tip_buttom'>" +
  1248. '<svg class="icon" ><use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#copy"></use></svg>';
  1249. output += gLocal.gui.copy + "</li></div>";
  1250. output +=
  1251. "<div style='border-right: solid 1px;margin: 0.3em 0;'><li class = 'tip_buttom'>" +
  1252. '<svg class="icon" ><use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#like"></use></svg>';
  1253. output += gLocal.gui.like + "</li>";
  1254. output +=
  1255. "<li class = 'tip_buttom'>" +
  1256. '<svg class="icon" ><use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#comment"></use></svg>';
  1257. output += gLocal.gui.comment + "</li>";
  1258. output +=
  1259. "<li class = 'tip_buttom'>" +
  1260. '<svg class="icon" ><use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#ic_shopping_cart"></use></svg>';
  1261. output += gLocal.gui.digest + "</li></div>";
  1262. output +=
  1263. "<div style='margin: 0.3em 0;'><li class = 'tip_buttom'>" +
  1264. '<svg class="icon" ><use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#share_to"></use></svg>';
  1265. output += gLocal.gui.share_to + "</li>";
  1266. output += "</div></div>";
  1267. //译文工具栏结束
  1268. output += "</div>";
  1269. //译文工具按钮结束
  1270. //译文正文开始
  1271. output +=
  1272. "<div class='text' id='tran_text_" +
  1273. book +
  1274. "_" +
  1275. para +
  1276. "_" +
  1277. begin +
  1278. "_" +
  1279. end +
  1280. "_" +
  1281. iterator.channal +
  1282. "'>";
  1283. if (iterator.text == "") {
  1284. output +=
  1285. "<span style='color:var(--border-line-color);'>" +
  1286. iterator.channalinfo.name +
  1287. "-" +
  1288. iterator.channalinfo.lang +
  1289. "</span>";
  1290. } else {
  1291. //note_init处理句子链接
  1292. output += note_init(term_std_str_to_tran(iterator.text, iterator.channal, iterator.editor, iterator.lang));
  1293. }
  1294. output += "</div>";
  1295. //译文正文结束
  1296. output += "</div>";
  1297. //单个channal译文框结束
  1298. return output;
  1299. }
  1300. function hidden_control(obj) {
  1301. if ($(".lang_2")[0].style.display == "none" && $(".lang_3")[0].style.display == "none") {
  1302. $(".lang_2").show();
  1303. $(".lang_3").show();
  1304. obj.innerHTML = "⬅"
  1305. }
  1306. else {
  1307. $(".lang_2").hide();
  1308. $(".lang_3").hide();
  1309. obj.innerHTML = "➡"
  1310. }
  1311. }
  1312. function add_new_tran_button_click(obj) {
  1313. let html = "<div style='display:flex; max-width: 70vw; white-space: normal;'>";
  1314. var first_lang = "";
  1315. for (const iterator of _my_channal) {
  1316. if (iterator.lang) {
  1317. first_lang = iterator.lang;
  1318. break;
  1319. }
  1320. }
  1321. //母语channel列表
  1322. html += "<ul class='channel_list lang_0' >";
  1323. html += "<li>";
  1324. html += gLocal.language[first_lang];
  1325. html += "</li>";
  1326. for (const iterator of _my_channal) {
  1327. if (iterator.status > 0 && first_lang.indexOf(iterator.lang) != -1 && iterator.lang != 0) {
  1328. if (_channal.indexOf(iterator.id) < 0) {
  1329. html += '<li class="channel_name" onclick="';
  1330. html +=
  1331. "new_sentence('" +
  1332. $(obj).parent().attr("book") +
  1333. "' ,'" +
  1334. $(obj).parent().attr("para") +
  1335. "' ,'" +
  1336. $(obj).parent().attr("begin") +
  1337. "' ,'" +
  1338. $(obj).parent().attr("end") +
  1339. "' ,'" +
  1340. iterator.id +
  1341. "',this)";
  1342. html += '" title="' + iterator.nickname;
  1343. html += '">' + iterator.name;
  1344. if (parseInt(iterator.power) < 20) {
  1345. html += "(建议)";
  1346. }
  1347. html += "</li>";
  1348. }
  1349. }
  1350. }
  1351. html += "<li><a href='../channal/my_channal_index.php' target='_blank'><button>" + gLocal.gui.new + "&nbsp;" + gLocal.gui.channel + "</button></a></li>"
  1352. html += "</ul>";
  1353. //非母语channel列表
  1354. html += "<ul class='channel_list lang_1'>";
  1355. html += "<li>";
  1356. html += gLocal.gui.other;
  1357. html += "&nbsp;<button style='height: 1.8em;' onmouseover='hidden_control(this)'>➡</button>"
  1358. html += "</li>";
  1359. for (const iterator of _my_channal) {
  1360. if (iterator.status > 0 && first_lang.indexOf(iterator.lang) == -1 && iterator.lang != 0) {
  1361. if (_channal.indexOf(iterator.id) < 0) {
  1362. html += '<li class="channel_name" onclick="';
  1363. html +=
  1364. "new_sentence('" +
  1365. $(obj).parent().attr("book") +
  1366. "' ,'" +
  1367. $(obj).parent().attr("para") +
  1368. "' ,'" +
  1369. $(obj).parent().attr("begin") +
  1370. "' ,'" +
  1371. $(obj).parent().attr("end") +
  1372. "' ,'" +
  1373. iterator.id +
  1374. "',this)";
  1375. html += '" title="' + iterator.nickname;
  1376. html += '">' + iterator.name;
  1377. if (parseInt(iterator.power) < 20) {
  1378. html += "(建议)";
  1379. }
  1380. html += "</li>";
  1381. }
  1382. }
  1383. }
  1384. html += "</ul>";
  1385. //协作channel列表-带中文
  1386. html += "<ul class='channel_list lang_2' style='display:none;'>";
  1387. html += "<li>";
  1388. html += "协作";
  1389. html += "</li>";
  1390. for (const iterator of _my_channal) {
  1391. if (iterator.status > 0 && iterator.lang == 0 && checkStringIsChinese(iterator.name) == true) {
  1392. if (_channal.indexOf(iterator.id) < 0) {
  1393. html += '<li class="channel_name" onclick="';
  1394. html +=
  1395. "new_sentence('" +
  1396. $(obj).parent().attr("book") +
  1397. "' ,'" +
  1398. $(obj).parent().attr("para") +
  1399. "' ,'" +
  1400. $(obj).parent().attr("begin") +
  1401. "' ,'" +
  1402. $(obj).parent().attr("end") +
  1403. "' ,'" +
  1404. iterator.id +
  1405. "',this)";
  1406. html += '" title="' + iterator.nickname;
  1407. html += '">' + iterator.name;
  1408. if (parseInt(iterator.power) < 20) {
  1409. html += "(建议)";
  1410. }
  1411. html += "</li>";
  1412. }
  1413. }
  1414. }
  1415. html += "</ul>";
  1416. //协作channel列表-不带中文
  1417. html += "<ul class='channel_list lang_3' style='display:none;'>";
  1418. html += "<li>";
  1419. html += "collaborate";
  1420. html += "</li>";
  1421. for (const iterator of _my_channal) {
  1422. if (iterator.status > 0 && iterator.lang == 0 && checkStringIsChinese(iterator.name) == false) {
  1423. if (_channal.indexOf(iterator.id) < 0) {
  1424. html += '<li class="channel_name" onclick="';
  1425. html +=
  1426. "new_sentence('" +
  1427. $(obj).parent().attr("book") +
  1428. "' ,'" +
  1429. $(obj).parent().attr("para") +
  1430. "' ,'" +
  1431. $(obj).parent().attr("begin") +
  1432. "' ,'" +
  1433. $(obj).parent().attr("end") +
  1434. "' ,'" +
  1435. iterator.id +
  1436. "',this)";
  1437. html += '" title="' + iterator.nickname;
  1438. html += '">' + iterator.name;
  1439. if (parseInt(iterator.power) < 20) {
  1440. html += "(建议)";
  1441. }
  1442. html += "</li>";
  1443. }
  1444. }
  1445. }
  1446. html += "</ul>";
  1447. html += "</div>";
  1448. $(obj).parent().children(".tran_text_tool_bar").first().html(html);
  1449. if ($(obj).parent().children(".tran_text_tool_bar").css("display") == "block") {
  1450. $(obj).parent().children(".tran_text_tool_bar").first().hide();
  1451. } else {
  1452. $(obj).parent().children(".tran_text_tool_bar").first().show();
  1453. $(document).one("click", function () {
  1454. $(obj).parent().children(".tran_text_tool_bar").first().hide();
  1455. });
  1456. event.stopPropagation();
  1457. $(obj).parent().show();
  1458. }
  1459. }
  1460. function checkStringIsChinese(str) {
  1461. var pattern = new RegExp("[\u4E00-\u9FA5]+");
  1462. if (pattern.test(str)) {
  1463. return true;
  1464. }
  1465. return false;
  1466. }
  1467. function tool_bar_show(element) {
  1468. if ($(element).find(".tran_text_tool_bar").css("display") == "none") {
  1469. $(element).find(".tran_text_tool_bar").css("display", "flex");
  1470. $(element).find(".icon_expand").css("transform", "rotate(-180deg)");
  1471. $(element).css("background-color", "var(--btn-bg-color)");
  1472. $(element).css("visibility", "visible");
  1473. $(document).one("click", function () {
  1474. $(element).find(".tran_text_tool_bar").hide();
  1475. $(element).css("background-color", "var(--nocolor)");
  1476. $(element).find(".icon_expand").css("transform", "unset");
  1477. $(element).css("visibility", "");
  1478. });
  1479. event.stopPropagation();
  1480. } else {
  1481. $(element).find(".tran_text_tool_bar").hide();
  1482. $(element).css("background-color", "var(--nocolor)");
  1483. $(element).find(".icon_expand").css("transform", "unset");
  1484. $(element).css("visibility", "");
  1485. }
  1486. }
  1487. function new_sentence(book, para, begin, end, channel, obj) {
  1488. let newsent = { id: "", text: "", lang: "", channal: channel };
  1489. for (let iterator of _arrData) {
  1490. if (iterator.book == book && iterator.para == para && iterator.begin == begin && iterator.end == end) {
  1491. let found = false;
  1492. for (const tran of iterator.translation) {
  1493. if (tran.channal == channel) {
  1494. found = true;
  1495. break;
  1496. }
  1497. }
  1498. if (!found) {
  1499. iterator.translation.push(newsent);
  1500. }
  1501. }
  1502. }
  1503. if ($(obj).parent().parent().css("display") == "block") {
  1504. $(obj).parent().parent().hide();
  1505. }
  1506. note_edit_sentence(book, para, begin, end, channel);
  1507. }
  1508. //显示更多译文按钮动作
  1509. function set_more_button_display() {
  1510. $(".other_bar").each(function () {
  1511. const sentid = $(this).attr("sent").split("-");
  1512. const channelType = $(this).attr("channel_type");
  1513. const book = sentid[0];
  1514. const para = sentid[1];
  1515. const begin = sentid[2];
  1516. const end = sentid[3];
  1517. let count = 0;
  1518. let commentaryChannel=0;
  1519. if(channelType=='commentary'){
  1520. for (const iterator of _channal.split(',')) {
  1521. let thisChannel = find_channal(iterator);
  1522. if(thisChannel && thisChannel.type=='commentary'){
  1523. commentaryChannel++;
  1524. }
  1525. }
  1526. }
  1527. for (const iterator of _channalData) {
  1528. if (iterator.final && iterator.type==channelType) {
  1529. for (const onesent of iterator.final) {
  1530. let id = onesent.id.split("-");
  1531. if (book == id[0] && para == id[1] && begin == id[2] && end == id[3] && onesent.final) {
  1532. if(channelType=='commentary'){
  1533. count++;
  1534. }else{
  1535. if (_channal.indexOf(iterator.id) == -1) {
  1536. count++;
  1537. }
  1538. }
  1539. }
  1540. }
  1541. }
  1542. }
  1543. if (count > 0 || commentaryChannel>0)
  1544. {
  1545. $(this).find(".other_tran_num").html(count);
  1546. $(this).find(".other_tran_num").attr("style", "display:inline-flex;");
  1547. $(this)
  1548. .click(function () {
  1549. const sentid = $(this).attr("sent").split("-");
  1550. const channelType = $(this).attr("channel_type");
  1551. const book = sentid[0];
  1552. const para = sentid[1];
  1553. const begin = sentid[2];
  1554. const end = sentid[3];
  1555. let sentId = $(this).attr("sent");
  1556. let otherSentDiv = $(this).parent().parent().siblings(".other_tran").first();
  1557. if (otherSentDiv.css("display") == "none") {
  1558. otherSentDiv.show();
  1559. //加号复位
  1560. //$(this).siblings(".more_tran ").css("transform", "unset");
  1561. $.get(
  1562. "../usent/get.php",
  1563. {
  1564. book: book,
  1565. para: para,
  1566. begin: begin,
  1567. end: end,
  1568. type:channelType,
  1569. },
  1570. function (data, status) {
  1571. let arrSent = JSON.parse(data);
  1572. let html = "<div class='compact "+channelType+"'>";
  1573. if(channelType==='commentary'){
  1574. //先渲染被选择的channel
  1575. if (_channal != "") {
  1576. //for(const channel of _channal.split(","))
  1577. {
  1578. for (const sent of _arrData) {
  1579. if (sent.book == book && sent.para==para && sent.begin==begin && sent.end==end) {
  1580. for (const tran of sent.translation) {
  1581. if(tran.channalinfo.type=='commentary'){
  1582. html += render_one_sent_tran_a(tran);
  1583. }
  1584. }
  1585. break;
  1586. }
  1587. }
  1588. }
  1589. }
  1590. }
  1591. //然后渲染没有被选择的
  1592. for (const iterator of arrSent) {
  1593. if (_channal.indexOf(iterator.channal) == -1) {
  1594. html += render_one_sent_tran_a(iterator);
  1595. }
  1596. }
  1597. html += "</div>";
  1598. otherSentDiv.html(html);
  1599. if(channelType==='commentary'){
  1600. note_refresh_new(function(){
  1601. otherSentDiv.show();
  1602. });
  1603. }
  1604. //不知道为什么加上note_refresh_new后div下拉后会收回。所以加了这个弥补。但是视觉效果不好。数据加载后收回,然后再弹出。
  1605. otherSentDiv.show();
  1606. //初始化文本编辑框消息处理
  1607. tran_sent_textarea_event_init();
  1608. }
  1609. );
  1610. } else {
  1611. otherSentDiv.hide();
  1612. $(this).siblings(".more_tran ").css("transform", "rotate(-90deg)");
  1613. }
  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().find(".tran_sent_textarea").first();
  1670. let isPr = $(textarea).attr("is_pr");
  1671. if (isPr == "true") {
  1672. note_pr_save(textarea);
  1673. } else {
  1674. note_sent_save_a(textarea);
  1675. }
  1676. sent_tran_set_edit_mode(textarea, false);
  1677. } else {
  1678. console.error("sent div not found");
  1679. }
  1680. }
  1681. //保存pr句子 新
  1682. function note_pr_save(obj) {
  1683. let id = $(obj).attr("dbid");
  1684. let sid = $(obj).attr("sid").split("-");
  1685. let book = sid[0];
  1686. let para = sid[1];
  1687. let begin = sid[2];
  1688. let end = sid[3];
  1689. let channel = $(obj).attr("channel");
  1690. let text = $(obj).val();
  1691. let sent_tran_div = find_sent_tran_div(obj);
  1692. $.post(
  1693. "../usent/pr_post.php",
  1694. {
  1695. id: id,
  1696. book: book,
  1697. para: para,
  1698. begin: begin,
  1699. end: end,
  1700. channel: channel,
  1701. text: text,
  1702. },
  1703. sent_save_callback
  1704. );
  1705. if (sent_tran_div) {
  1706. $(sent_tran_div).addClass("loading");
  1707. }
  1708. }
  1709. //保存译文句子 新
  1710. function note_sent_save_a(obj) {
  1711. let id = $(obj).attr("dbid");
  1712. let sid = $(obj).attr("sid").split("-");
  1713. let book = sid[0];
  1714. let para = sid[1];
  1715. let begin = sid[2];
  1716. let end = sid[3];
  1717. let channal = $(obj).attr("channel");
  1718. let text = $(obj).val();
  1719. let sent_tran_div = find_sent_tran_div(obj);
  1720. $.ajaxSetup({
  1721. timeout: 5000,
  1722. });
  1723. $.post("../usent/sent_post.php", {
  1724. id: id,
  1725. book: book,
  1726. para: para,
  1727. begin: begin,
  1728. end: end,
  1729. channal: channal,
  1730. text: text,
  1731. lang: "zh",
  1732. })
  1733. .done(function (data) {
  1734. sent_save_callback(data);
  1735. })
  1736. .fail(function (xhr, error, data) {
  1737. let sid = book + "-" + para + "-" + begin + "-" + end;
  1738. let sent_tran_div = $(".sent_tran[channel='" + channal + "'][sid='" + sid + "']");
  1739. if (sent_tran_div) {
  1740. sent_tran_div.removeClass("loading");
  1741. sent_tran_div.addClass("error");
  1742. }
  1743. switch (error) {
  1744. case "timeout":
  1745. alert("服务器长时间没有回应。请稍后重试。");
  1746. break;
  1747. case "error":
  1748. alert("与服务器通讯失败,您可能没有连接到网络。请稍后重试。");
  1749. break;
  1750. case "notmodified":
  1751. break;
  1752. default:
  1753. break;
  1754. }
  1755. });
  1756. if (sent_tran_div) {
  1757. $(sent_tran_div).addClass("loading");
  1758. $(sent_tran_div).removeClass("error");
  1759. }
  1760. }
  1761. function update_sent_tran(sentData) {}
  1762. function sent_save_callback(data) {
  1763. let result;
  1764. try {
  1765. result = JSON.parse(data);
  1766. } catch (e) {
  1767. alert(e.message);
  1768. console.error('sent_save_callback',data);
  1769. return;
  1770. }
  1771. if (result.status > 0) {
  1772. alert("error" + result.message);
  1773. } else {
  1774. let sid = result.book + "-" + result.para + "-" + result.begin + "-" + result.end;
  1775. let sent_tran_div = $(
  1776. ".sent_tran[dbid='" + result.id + "'][channel='" + result.channal + "'][sid='" + sid + "']"
  1777. );
  1778. if (sent_tran_div) {
  1779. sent_tran_div.removeClass("loading");
  1780. }
  1781. if (result.commit_type == 1 || result.commit_type == 2) {
  1782. ntf_show("成功修改");
  1783. if (sent_tran_div) {
  1784. let divPreview = sent_tran_div.find(".preview").first();
  1785. let thisChannel = find_channal(result.channal);
  1786. if (result.text == "") {
  1787. //内容为空
  1788. let channel_info = "Empty";
  1789. if (thisChannel) {
  1790. channel_info = thisChannel.name + "-" + thisChannel.nickname;
  1791. }
  1792. divPreview.html("<span style='color:var(--border-line-color);'>" + channel_info + "</span>");
  1793. } else {
  1794. for (const iterator of _arrData) {
  1795. if (
  1796. iterator.book == result.book &&
  1797. iterator.para == result.para &&
  1798. iterator.begin == result.begin &&
  1799. iterator.end == result.end
  1800. ) {
  1801. for (const tran of iterator.translation) {
  1802. if (tran.channal == result.channal) {
  1803. tran.text = result.text;
  1804. break;
  1805. }
  1806. }
  1807. }
  1808. }
  1809. switch (thisChannel.type) {
  1810. case 'nissaya':
  1811. divPreview.html(renderNissayaPreview(result.text));
  1812. break;
  1813. default:
  1814. divPreview.html(
  1815. marked(term_std_str_to_tran(result.text, result.channal, result.editor, result.lang))
  1816. );
  1817. term_updata_translation();
  1818. break;
  1819. }
  1820. popup_init();
  1821. }
  1822. }
  1823. } else if (result.commit_type == 3) {
  1824. ntf_show("已经提交修改建议");
  1825. } else {
  1826. ntf_show("未提交");
  1827. }
  1828. }
  1829. }
  1830. //保存译文句子
  1831. function note_sent_save() {
  1832. let id = $("#edit_dialog_text").attr("sent_id");
  1833. let book = $("#edit_dialog_text").attr("book");
  1834. let para = $("#edit_dialog_text").attr("para");
  1835. let begin = $("#edit_dialog_text").attr("begin");
  1836. let end = $("#edit_dialog_text").attr("end");
  1837. let channal = $("#edit_dialog_text").attr("channal");
  1838. let text = $("#edit_dialog_text").val();
  1839. $.post(
  1840. "../usent/sent_post.php",
  1841. {
  1842. id: id,
  1843. book: book,
  1844. para: para,
  1845. begin: begin,
  1846. end: end,
  1847. channal: channal,
  1848. text: text,
  1849. lang: "zh",
  1850. },
  1851. function (data) {
  1852. let result = JSON.parse(data);
  1853. if (result.status > 0) {
  1854. alert("error" + result.message);
  1855. } else {
  1856. if (result.commit_type == 1 || result.commit_type == 2) {
  1857. ntf_show("成功修改");
  1858. if (result.text == "") {
  1859. let channel_info = "Empty";
  1860. let thisChannel = find_channal(result.channal);
  1861. if (thisChannel) {
  1862. channel_info = thisChannel.name + "-" + thisChannel.nickname;
  1863. }
  1864. $(
  1865. "#tran_text_" +
  1866. result.book +
  1867. "_" +
  1868. result.para +
  1869. "_" +
  1870. result.begin +
  1871. "_" +
  1872. result.end +
  1873. "_" +
  1874. result.channal
  1875. ).html("<span style='color:var(--border-line-color);'>" + channel_info + "</span>");
  1876. } else {
  1877. $(
  1878. "#tran_text_" +
  1879. result.book +
  1880. "_" +
  1881. result.para +
  1882. "_" +
  1883. result.begin +
  1884. "_" +
  1885. result.end +
  1886. "_" +
  1887. result.channal
  1888. ).html(marked(term_std_str_to_tran(result.text, result.channal, result.editor, result.lang)));
  1889. term_updata_translation();
  1890. for (const iterator of _arrData) {
  1891. if (
  1892. iterator.book == result.book &&
  1893. iterator.para == result.para &&
  1894. iterator.begin == result.begin &&
  1895. iterator.end == result.end
  1896. ) {
  1897. for (const tran of iterator.translation) {
  1898. if (tran.channal == result.channal) {
  1899. tran.text = result.text;
  1900. break;
  1901. }
  1902. }
  1903. }
  1904. }
  1905. }
  1906. } else if (result.commit_type == 3) {
  1907. ntf_show("已经提交修改建议");
  1908. } else {
  1909. ntf_show("未提交");
  1910. }
  1911. }
  1912. }
  1913. );
  1914. }
  1915. function copy_ref(book, para, begin, end) {
  1916. let strRef = "{{" + book + "-" + para + "-" + begin + "-" + end + "}}";
  1917. copy_to_clipboard(strRef);
  1918. }
  1919. function goto_nissaya(book, para, begin = 0, end = 0) {
  1920. window.open("../nissaya/index.php?book=" + book + "&par=" + para + "&begin=" + begin + "&end=" + end, "nissaya");
  1921. }
  1922. function edit_in_studio(book, para, begin, end) {
  1923. wbw_channal_list_open(book, [para]);
  1924. }
  1925. //显示和隐藏某个内容 如 巴利文
  1926. function setVisibility(key, value) {
  1927. switch (key) {
  1928. case "palitext":
  1929. if ($(value).is(":checked")) {
  1930. $(".palitext").show();
  1931. } else {
  1932. $(".palitext").hide();
  1933. }
  1934. break;
  1935. default:
  1936. break;
  1937. }
  1938. }
  1939. function note_show_pali_sim(SentId) {
  1940. pali_sim_dlg_open(SentId, 0, 20);
  1941. }
  1942. function set_pali_script(pos, script) {
  1943. if (script == "none") {
  1944. $(".palitext" + pos).html("");
  1945. } else {
  1946. $(".palitext" + pos).each(function () {
  1947. let html = $(this).siblings(".palitext_roma").first().html();
  1948. $(this).html(html);
  1949. });
  1950. $(".palitext" + pos)
  1951. .find("*")
  1952. .contents()
  1953. .filter(function () {
  1954. return this.nodeType != 1;
  1955. })
  1956. .wrap("<pl" + pos + "></pl" + pos + ">");
  1957. $(".palitext" + pos)
  1958. .contents()
  1959. .filter(function () {
  1960. return this.nodeType != 1;
  1961. })
  1962. .wrap("<pl" + pos + "></pl" + pos + ">");
  1963. $("pl" + pos).html(function (index, oldcontent) {
  1964. switch(script){
  1965. case "မြန်မာ":
  1966. return roman_to_my(oldcontent);
  1967. case "My2Roman":
  1968. return my_to_roman(oldcontent);
  1969. case "සිංහල":
  1970. return roman_to_si(oldcontent);
  1971. case "ᨲ᩠ᩅᩫᨴᩱ᩠ᨿᨵᨾ᩠ᨾ᩼":
  1972. return roman_to_tai(oldcontent);
  1973. case "อักษรไทย":
  1974. return roman_to_thai(oldcontent);
  1975. default:
  1976. return(oldcontent);
  1977. }
  1978. });
  1979. }
  1980. }
  1981. function splite_pali_word() {
  1982. $("pali")
  1983. .contents()
  1984. .filter(function () {
  1985. return this.nodeType != 1;
  1986. })
  1987. .wrap("<pl></pl>");
  1988. $("pl").each(function () {
  1989. let html = $(this).html();
  1990. $(this).html("<w>" + html.replace(/\s/g, "</w> <w>") + "</w>");
  1991. });
  1992. $("w").click(function () {
  1993. let word = com_getPaliReal($(this).text());
  1994. if (gBuildinDictIsOpen) {
  1995. window.open("../dict/index.php?builtin=true&key=" + word, "dict");
  1996. }
  1997. });
  1998. }
  1999. function refresh_pali_script() {
  2000. if (_display && _display == "para") {
  2001. //段落模式
  2002. } else {
  2003. //句子模式
  2004. setting_get("lib.second_script", set_second_scrip);
  2005. }
  2006. }
  2007. function set_second_scrip(value) {
  2008. set_pali_script(2, value);
  2009. }
  2010. function slider_show(obj) {
  2011. $(obj).parent().parent().parent().parent().parent().toggleClass("slider_show_shell");
  2012. }
  2013. function find_sent_tran_div(obj) {
  2014. let jqObj = $(obj);
  2015. while (!jqObj.hasClass("sent_tran")) {
  2016. jqObj = jqObj.parent();
  2017. if (!jqObj) {
  2018. return false;
  2019. }
  2020. }
  2021. return jqObj;
  2022. /*
  2023. let parent = obj.parentNode;
  2024. while (parent.nodeType == 1) {
  2025. if ($(parent).hasClass("sent_tran")) {
  2026. return parent;
  2027. } else if (parent.nodeName == "BODY") {
  2028. return false;
  2029. }
  2030. parent = parent.parentNode;
  2031. }
  2032. return false;
  2033. */
  2034. }
  2035. //显示或隐藏pr数据
  2036. function note_pr_show(channel, id) {
  2037. let obj = $(".sent_tran[channel='" + channel + "'][sid='" + id + "']").find(".pr_content");
  2038. let prHtml = obj.first().html();
  2039. if (prHtml == "") {
  2040. note_get_pr(channel, id);
  2041. } else {
  2042. obj.slideUp();
  2043. obj.html("");
  2044. }
  2045. }
  2046. //获取pr数据并显示
  2047. function note_get_pr(channel, id) {
  2048. let sid = id.split("-");
  2049. let book = sid[0];
  2050. let para = sid[1];
  2051. let begin = sid[2];
  2052. let end = sid[3];
  2053. $.post(
  2054. "../usent/get_pr.php",
  2055. {
  2056. book: book,
  2057. para: para,
  2058. begin: begin,
  2059. end: end,
  2060. channel: channel,
  2061. },
  2062. function (data) {
  2063. let result = JSON.parse(data);
  2064. if (result.length > 0) {
  2065. let html = "<div class='compact pr'>";
  2066. for (const iterator of result) {
  2067. html += render_one_sent_tran_a(iterator, true);
  2068. }
  2069. html += "</div>";
  2070. $(".sent_tran[channel='" + channel + "'][sid='" + id + "']")
  2071. .find(".pr_content")
  2072. .html(html);
  2073. $(".sent_tran[channel='" + channel + "'][sid='" + id + "']")
  2074. .find(".pr_content")
  2075. .slideDown();
  2076. } else {
  2077. }
  2078. }
  2079. );
  2080. $(".sent_tran[channel='" + channel + "'][sid='" + id + "']")
  2081. .find(".pr_content")
  2082. .html("loading");
  2083. $(".sent_tran[channel='" + channel + "'][sid='" + id + "']")
  2084. .find(".pr_content")
  2085. .show();
  2086. }
  2087. function get_channel_by_id(id) {
  2088. if (typeof _channalData != "undefined") {
  2089. for (const iterator of _channalData) {
  2090. if (iterator.id == id) {
  2091. return iterator;
  2092. }
  2093. }
  2094. }
  2095. if (typeof _my_channal != "undefined") {
  2096. for (const iterator of _my_channal) {
  2097. if (iterator.id == id) {
  2098. return iterator;
  2099. }
  2100. }
  2101. }
  2102. return false;
  2103. }
  2104. //设置显示方向
  2105. function setDirection(obj) {
  2106. if (obj.value == "row") {
  2107. $("#contents").removeClass("vertical");
  2108. $("#contents").addClass("horizontal");
  2109. _direction = "row";
  2110. } else {
  2111. $("#contents").removeClass("horizontal");
  2112. $("#contents").addClass("vertical");
  2113. _direction = "col";
  2114. }
  2115. }
  2116. //设置逐段或逐句模式
  2117. function setDisplay(obj) {
  2118. if (obj.value == "para") {
  2119. $("#contents").removeClass("sent_mode");
  2120. $("#contents").addClass("para_mode");
  2121. _display = "para";
  2122. } else {
  2123. $("#contents").removeClass("para_mode");
  2124. $("#contents").addClass("sent_mode");
  2125. _display = "sent";
  2126. }
  2127. }
  2128. //获取文章中H 并渲染为目录
  2129. function render_heading_toc() {
  2130. //$(":header")
  2131. }
  2132. //术语输入At
  2133. const _term_max_menu=9;
  2134. function term_set_word_list_data(el){
  2135. let sid = $(el).attr("sid");
  2136. let asid = sid.split("-");
  2137. let words=new Array();
  2138. let tmpWords = [];
  2139. term_data=[];
  2140. for (const it of _arrData) {
  2141. if(it.book==asid[0] && it.para==asid[1] && it.begin==asid[2] && it.end==asid[3]){
  2142. let palitext = it.palitext;
  2143. words = palitext.split(" ");
  2144. }
  2145. }
  2146. console.log("word",words);
  2147. //查询parent
  2148. for (let index = 0; index < words.length; index++) {
  2149. words[index] = com_getPaliReal(words[index]);
  2150. if(words[index]!=""){
  2151. let parents = term_parent(words[index]);
  2152. for (const key in parents) {
  2153. if (parents.hasOwnProperty.call(parents, key)) {
  2154. //term_data.push({word:key,en:com_getPaliEn(key),weight:weight});
  2155. tmpWords[key]={word:key,en:com_getPaliEn(key),weight:3,exist:0};
  2156. }
  2157. }
  2158. }
  2159. }
  2160. for (const iterator of arrTermAllPali) {
  2161. if(tmpWords.hasOwnProperty(iterator.word)){
  2162. tmpWords[iterator.word].weight+=1;
  2163. tmpWords[iterator.word].exist=1;
  2164. }else{
  2165. tmpWords[iterator.word]={word:iterator.word,en:com_getPaliEn(iterator.word),weight:1,exist:1};
  2166. }
  2167. }
  2168. //arrMyTerm 词头查重
  2169. let tmpMyTerm=[];
  2170. for (const iterator of arrMyTerm) {
  2171. tmpMyTerm[iterator.word]=1;
  2172. }
  2173. //加入到列表
  2174. //在我的字典中的排名靠前
  2175. for (const key in tmpMyTerm) {
  2176. if (tmpMyTerm.hasOwnProperty.call(tmpMyTerm, key)) {
  2177. if(tmpWords.hasOwnProperty(key)){
  2178. tmpWords[key].weight+=1;
  2179. tmpWords[key].exist=2;
  2180. }else{
  2181. tmpWords[key]={word:key,en:com_getPaliEn(key),weight:1,exist:2};
  2182. }
  2183. }
  2184. }
  2185. for (const key in tmpWords) {
  2186. if (tmpWords.hasOwnProperty.call(tmpWords, key)) {
  2187. const element = tmpWords[key];
  2188. term_data.push(element);
  2189. }
  2190. }
  2191. term_data.sort(function(a,b){
  2192. return b.weight-a.weight;
  2193. });
  2194. }
  2195. function text_input_textarea_focuse(el){
  2196. term_set_word_list_data(el);
  2197. term_input_text = el;
  2198. term_input_text.onresize = function(){
  2199. term_input_text.parentElement.querySelector(".text_shadow").style.height=term_input_text.clientHeight+"px";
  2200. }
  2201. term_input_text.onkeydown = function (e) {
  2202. let menu = term_input_text.parentElement.querySelector('.menu');
  2203. switch (e.key) {
  2204. case "ArrowDown"://down arrow
  2205. if(menu.style.display=="block"){
  2206. menuFocusIndex++;
  2207. if(menuFocusIndex>_term_max_menu){
  2208. menuFocusIndex=_term_max_menu;
  2209. }
  2210. menu.innerHTML=TermAtRenderMenu({focus:menuFocusIndex});
  2211. return false;
  2212. }
  2213. break;
  2214. case "ArrowUp"://up arrow
  2215. if(menu.style.display=="block"){
  2216. menuFocusIndex--;
  2217. if(menuFocusIndex<0){
  2218. menuFocusIndex=0;
  2219. }
  2220. menu.innerHTML=TermAtRenderMenu({focus:menuFocusIndex});
  2221. return false;
  2222. }
  2223. break;
  2224. case "Enter":
  2225. if(menu.style.display=="block"){
  2226. term_insert(term_filterd_data[menuFocusIndex]);
  2227. return false;
  2228. }
  2229. if (e.ctrlKey) {
  2230. //回车存盘
  2231. tran_sent_save(e.currentTarget);
  2232. return false;
  2233. }
  2234. break;
  2235. case "Escape":
  2236. if(menu.style.display=="block"){
  2237. term_at_menu_hide();
  2238. }else{
  2239. tran_sent_edit_cancel(e.currentTarget);
  2240. }
  2241. break;
  2242. default:
  2243. break;
  2244. }
  2245. }
  2246. term_input_text.onkeyup = function (e) {
  2247. let textHeight = term_input_text.parentElement.querySelector(".text_shadow").scrollHeight;
  2248. let textHeight2 = term_input_text.clientHeight;
  2249. if(textHeight2>textHeight){
  2250. textHeight=textHeight2;
  2251. }
  2252. term_input_text.style.height = textHeight+"px";
  2253. console.log("text height",textHeight);
  2254. let value = term_input_text.value
  2255. let selectionStart = term_input_text.selectionStart
  2256. let str1 = value.slice(0, selectionStart)
  2257. let str2 = value.slice(selectionStart)
  2258. let textNode1 = document.createTextNode(str1)
  2259. let textNode2 = document.createTextNode(str2)
  2260. let cursor = document.createElement('span')
  2261. cursor.innerHTML = '&nbsp;'
  2262. cursor.setAttribute('class','cursor')
  2263. let mirror = term_input_text.parentElement.querySelector('.text_shadow')
  2264. mirror.innerHTML = ''
  2265. mirror.appendChild(textNode1)
  2266. mirror.appendChild(cursor)
  2267. mirror.appendChild(textNode2)
  2268. let menu = term_input_text.parentElement.querySelector('.menu');
  2269. if(str1.slice(-2)=="[[" ){
  2270. if( menu.style.display!="block"){
  2271. menuFocusIndex=0;
  2272. menu.innerHTML=TermAtRenderMenu({focus:0});
  2273. term_at_menu_show(cursor);
  2274. }
  2275. }else{
  2276. if( menu.style.display=="block"){
  2277. let pos1=str1.lastIndexOf("[[");
  2278. let pos2=str1.lastIndexOf("]]");
  2279. if(pos1==-1 || (pos1!=-1 && pos2>pos1)){
  2280. //光标前没有[[ 或 光标在[[]] 之后
  2281. term_at_menu_hide();
  2282. }
  2283. }
  2284. }
  2285. if(menu.style.display=="block"){
  2286. //term_input += e.key;
  2287. let value = term_input_text.value
  2288. let selectionStart = term_input_text.selectionStart
  2289. let str1 = value.slice(0, selectionStart)
  2290. let str2 = value.slice(selectionStart)
  2291. let pos1=str1.lastIndexOf("[[");
  2292. let pos2=str1.lastIndexOf("]]");
  2293. if(pos1!=-1){
  2294. if(pos2==-1 || pos2<pos1){
  2295. //光标
  2296. term_input = str1.slice(str1.lastIndexOf("[[")+2);
  2297. }
  2298. }
  2299. console.log("term_input",term_input);
  2300. menu.innerHTML=TermAtRenderMenu({focus:menuFocusIndex});
  2301. }
  2302. console.log(e.key);
  2303. console.log(cursor.offsetLeft,cursor.offsetTop)
  2304. }
  2305. }
  2306. function term_at_menu_show(cursor){
  2307. menuFocusIndex=0;
  2308. let menu = term_input_text.parentElement.querySelector('.menu');
  2309. menu.style.display="block";
  2310. menu.style.top=cursor.offsetTop+20+"px";
  2311. menu.style.left=cursor.offsetLeft+"px";
  2312. $(document).on("keyup", function (e) {
  2313. if(e.key=="Escape"){
  2314. term_at_menu_hide();
  2315. }
  2316. });
  2317. }
  2318. function term_at_menu_hide(){
  2319. let menu = term_input_text.parentElement.querySelector('.menu');
  2320. menu.style.display="none";
  2321. term_input="";
  2322. }
  2323. function term_insert(strTerm){
  2324. let value = term_input_text.value;
  2325. let selectionStart = term_input_text.selectionStart;
  2326. let str1 = value.slice(0, selectionStart)
  2327. let str2 = value.slice(selectionStart)
  2328. let pos1=str1.lastIndexOf("[[");
  2329. let pos2=str1.lastIndexOf("]]");
  2330. if(pos1!=-1){
  2331. //光标前有[[
  2332. if(pos2==-1 || pos2<pos1){
  2333. //光标在[[之间]]
  2334. str1 = str1.slice(0,str1.lastIndexOf("[[")+2);
  2335. }
  2336. }
  2337. //TODO 光标会跑到最下面
  2338. term_input_text.value = str1+strTerm+"]]"+str2;
  2339. term_at_menu_hide();
  2340. }
  2341. function TermAtRenderMenu(params) {
  2342. term_filterd_data=[];
  2343. let html="";
  2344. html +="<div class='term_at_menu_input'>"+term_input+"|</div>";
  2345. html +="<ul class='term_at_menu_ul'>";
  2346. let index=0;
  2347. let focusIndex = params.focus%term_data.length;
  2348. for (const it of term_data) {
  2349. if(term_input=="" || it.word.indexOf(term_input)==0 || it.en.indexOf(term_input)==0){
  2350. html +="<li ";
  2351. if(focusIndex==index){
  2352. html +="class='trem_focus' "
  2353. }
  2354. html += "onclick=\"term_insert('"+it.word+"')\" ";
  2355. html +=">";
  2356. html += (index+1)+ ". ";
  2357. if(it.exist>0){
  2358. html += "<b>"+it.word+"</b>";
  2359. }else{
  2360. html +=it.word;
  2361. }
  2362. html +="<li>";
  2363. term_filterd_data.push(it.word);
  2364. if(index >= _term_max_menu){
  2365. break;
  2366. }
  2367. index++;
  2368. }
  2369. }
  2370. return html;
  2371. }
  2372. //添加自动格位数据到内存字典
  2373. function term_parent(paliword) {
  2374. let output=[];
  2375. for (const it of gCaseTable) {
  2376. if (it.type != ".v.") {
  2377. let sEnd2 = paliword.slice(0 - it.end2.length);
  2378. if (sEnd2 == it.end2) {
  2379. let wordParent = paliword.slice(0, 0 - it.end2.length) + it.end1;
  2380. output[wordParent]=1;
  2381. }
  2382. }
  2383. }
  2384. return output;
  2385. }