note.js 64 KB

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