note.js 64 KB

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