note.js 63 KB

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