note.js 63 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403
  1. var _display = "para";
  2. var _mode = "read";
  3. var _direction = "row";
  4. var _word = "";
  5. var _channal = "";
  6. var _lang = "";
  7. var _author = "";
  8. var _arrData = new Array();
  9. var _channalData;
  10. var MAX_NOTE_NEST = 2;
  11. var gBuildinDictIsOpen = false;
  12. /*
  13. {{203-1654-23-45@11@en@*}}
  14. <note>203-1654-23-45@11@en@*</note>
  15. <note id=guid book=203 para=1654 begin=23 end=45 author=11 lang=en tag=*></note>
  16. <note id=guid book=203 para=1654 begin=23 end=45 author=11 lang=en tag=*>
  17. <div class=text>
  18. pali text
  19. </div>
  20. <tran>
  21. </tran>
  22. <ref>
  23. </ref>
  24. </note>
  25. */
  26. /*
  27. 解析百科字符串
  28. {{203-1654-23-45@11@en@*}}
  29. <note id=12345 info="203-1654-23-45@11@en@*"><note>
  30. <note id="guid" book=203 para=1654 begin=23 end=45 author=11 lang=en tag=*></note>
  31. */
  32. function note_create() {
  33. $.post("../ucenter/get_setting.php", {}, function (data, status) {
  34. setting = JSON.parse(data);
  35. });
  36. wbw_channal_list_init();
  37. note_sent_edit_dlg_init();
  38. term_edit_dlg_init();
  39. pali_sim_dlg_init();
  40. related_para_dlg_init();
  41. term_get_all_pali();
  42. }
  43. function note_sent_edit_dlg_init() {
  44. $("body").append(
  45. '<div id="note_sent_edit_dlg" title="' +
  46. gLocal.gui.edit +
  47. '"><guide gid="markdown_guide"></guide><div id="edit_dialog_content"></div></div>'
  48. );
  49. guide_init();
  50. $("#note_sent_edit_dlg").dialog({
  51. autoOpen: false,
  52. width: 550,
  53. buttons: [
  54. {
  55. text: gLocal.gui.save,
  56. click: function () {
  57. note_sent_save();
  58. $(this).dialog("close");
  59. },
  60. },
  61. {
  62. text: gLocal.gui.cancel,
  63. click: function () {
  64. $(this).dialog("close");
  65. },
  66. },
  67. ],
  68. });
  69. }
  70. function note_init(input,channel="",editor="",lang="en") {
  71. if (input) {
  72. let output = "<div>";
  73. //output += marked(input);
  74. output += marked(term_std_str_to_tran(input, channel, editor, lang));
  75. output += "</div>";
  76. let newString = output.replace(/\{\{/g, '<span class="note_shell"><note 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 "My2Roman":
  1843. return my_to_roman(oldcontent);
  1844. case "සිංහල":
  1845. return roman_to_si(oldcontent);
  1846. case "ᨲ᩠ᩅᩫᨴᩱ᩠ᨿᨵᨾ᩠ᨾ᩼":
  1847. return roman_to_tai(oldcontent);
  1848. case "อักษรไทย":
  1849. return roman_to_thai(oldcontent);
  1850. default:
  1851. return(oldcontent);
  1852. }
  1853. });
  1854. }
  1855. }
  1856. function splite_pali_word() {
  1857. $("pali")
  1858. .contents()
  1859. .filter(function () {
  1860. return this.nodeType != 1;
  1861. })
  1862. .wrap("<pl></pl>");
  1863. $("pl").each(function () {
  1864. let html = $(this).html();
  1865. $(this).html("<w>" + html.replace(/\s/g, "</w> <w>") + "</w>");
  1866. });
  1867. $("w").click(function () {
  1868. let word = com_getPaliReal($(this).text());
  1869. if (gBuildinDictIsOpen) {
  1870. window.open("../dict/index.php?builtin=true&key=" + word, "dict");
  1871. }
  1872. });
  1873. }
  1874. function refresh_pali_script() {
  1875. if (_display && _display == "para") {
  1876. //段落模式
  1877. } else {
  1878. //句子模式
  1879. setting_get("lib.second_script", set_second_scrip);
  1880. }
  1881. }
  1882. function set_second_scrip(value) {
  1883. set_pali_script(2, value);
  1884. }
  1885. function slider_show(obj) {
  1886. $(obj).parent().parent().parent().parent().parent().toggleClass("slider_show_shell");
  1887. }
  1888. function find_sent_tran_div(obj) {
  1889. let jqObj = $(obj);
  1890. while (!jqObj.hasClass("sent_tran")) {
  1891. jqObj = jqObj.parent();
  1892. if (!jqObj) {
  1893. return false;
  1894. }
  1895. }
  1896. return jqObj;
  1897. /*
  1898. let parent = obj.parentNode;
  1899. while (parent.nodeType == 1) {
  1900. if ($(parent).hasClass("sent_tran")) {
  1901. return parent;
  1902. } else if (parent.nodeName == "BODY") {
  1903. return false;
  1904. }
  1905. parent = parent.parentNode;
  1906. }
  1907. return false;
  1908. */
  1909. }
  1910. //显示或隐藏pr数据
  1911. function note_pr_show(channel, id) {
  1912. let obj = $(".sent_tran[channel='" + channel + "'][sid='" + id + "']").find(".pr_content");
  1913. let prHtml = obj.first().html();
  1914. if (prHtml == "") {
  1915. note_get_pr(channel, id);
  1916. } else {
  1917. obj.slideUp();
  1918. obj.html("");
  1919. }
  1920. }
  1921. //获取pr数据并显示
  1922. function note_get_pr(channel, id) {
  1923. let sid = id.split("-");
  1924. let book = sid[0];
  1925. let para = sid[1];
  1926. let begin = sid[2];
  1927. let end = sid[3];
  1928. $.post(
  1929. "../usent/get_pr.php",
  1930. {
  1931. book: book,
  1932. para: para,
  1933. begin: begin,
  1934. end: end,
  1935. channel: channel,
  1936. },
  1937. function (data) {
  1938. let result = JSON.parse(data);
  1939. if (result.length > 0) {
  1940. let html = "<div class='compact pr'>";
  1941. for (const iterator of result) {
  1942. html += render_one_sent_tran_a(iterator, true);
  1943. }
  1944. html += "</div>";
  1945. $(".sent_tran[channel='" + channel + "'][sid='" + id + "']")
  1946. .find(".pr_content")
  1947. .html(html);
  1948. $(".sent_tran[channel='" + channel + "'][sid='" + id + "']")
  1949. .find(".pr_content")
  1950. .slideDown();
  1951. } else {
  1952. }
  1953. }
  1954. );
  1955. $(".sent_tran[channel='" + channel + "'][sid='" + id + "']")
  1956. .find(".pr_content")
  1957. .html("loading");
  1958. $(".sent_tran[channel='" + channel + "'][sid='" + id + "']")
  1959. .find(".pr_content")
  1960. .show();
  1961. }
  1962. function get_channel_by_id(id) {
  1963. if (typeof _channalData != "undefined") {
  1964. for (const iterator of _channalData) {
  1965. if (iterator.id == id) {
  1966. return iterator;
  1967. }
  1968. }
  1969. }
  1970. if (typeof _my_channal != "undefined") {
  1971. for (const iterator of _my_channal) {
  1972. if (iterator.id == id) {
  1973. return iterator;
  1974. }
  1975. }
  1976. }
  1977. return false;
  1978. }
  1979. //设置显示方向
  1980. function setDirection(obj) {
  1981. if (obj.value == "row") {
  1982. $("#contents").removeClass("vertical");
  1983. $("#contents").addClass("horizontal");
  1984. _direction = "row";
  1985. } else {
  1986. $("#contents").removeClass("horizontal");
  1987. $("#contents").addClass("vertical");
  1988. _direction = "col";
  1989. }
  1990. }
  1991. //设置逐段或逐句模式
  1992. function setDisplay(obj) {
  1993. if (obj.value == "para") {
  1994. $("#contents").removeClass("sent_mode");
  1995. $("#contents").addClass("para_mode");
  1996. _display = "para";
  1997. } else {
  1998. $("#contents").removeClass("para_mode");
  1999. $("#contents").addClass("sent_mode");
  2000. _display = "sent";
  2001. }
  2002. }
  2003. //获取文章中H 并渲染为目录
  2004. function render_heading_toc() {
  2005. //$(":header")
  2006. }
  2007. //术语输入At
  2008. const _term_max_menu=9;
  2009. function term_set_word_list_data(el){
  2010. let sid = $(el).attr("sid");
  2011. let asid = sid.split("-");
  2012. let words=new Array();
  2013. let tmpWords = [];
  2014. term_data=[];
  2015. for (const it of _arrData) {
  2016. if(it.book==asid[0] && it.para==asid[1] && it.begin==asid[2] && it.end==asid[3]){
  2017. let palitext = it.palitext;
  2018. words = palitext.split(" ");
  2019. }
  2020. }
  2021. console.log("word",words);
  2022. //查询parent
  2023. for (let index = 0; index < words.length; index++) {
  2024. words[index] = com_getPaliReal(words[index]);
  2025. if(words[index]!=""){
  2026. let parents = term_parent(words[index]);
  2027. for (const key in parents) {
  2028. if (parents.hasOwnProperty.call(parents, key)) {
  2029. //term_data.push({word:key,en:com_getPaliEn(key),weight:weight});
  2030. tmpWords[key]={word:key,en:com_getPaliEn(key),weight:3,exist:0};
  2031. }
  2032. }
  2033. }
  2034. }
  2035. for (const iterator of arrTermAllPali) {
  2036. if(tmpWords.hasOwnProperty(iterator.word)){
  2037. tmpWords[iterator.word].weight+=1;
  2038. tmpWords[iterator.word].exist=1;
  2039. }else{
  2040. tmpWords[iterator.word]={word:iterator.word,en:com_getPaliEn(iterator.word),weight:1,exist:1};
  2041. }
  2042. }
  2043. //arrMyTerm 词头查重
  2044. let tmpMyTerm=[];
  2045. for (const iterator of arrMyTerm) {
  2046. tmpMyTerm[iterator.word]=1;
  2047. }
  2048. //加入到列表
  2049. //在我的字典中的排名靠前
  2050. for (const key in tmpMyTerm) {
  2051. if (tmpMyTerm.hasOwnProperty.call(tmpMyTerm, key)) {
  2052. if(tmpWords.hasOwnProperty(key)){
  2053. tmpWords[key].weight+=1;
  2054. tmpWords[key].exist=2;
  2055. }else{
  2056. tmpWords[key]={word:key,en:com_getPaliEn(key),weight:1,exist:2};
  2057. }
  2058. }
  2059. }
  2060. for (const key in tmpWords) {
  2061. if (tmpWords.hasOwnProperty.call(tmpWords, key)) {
  2062. const element = tmpWords[key];
  2063. term_data.push(element);
  2064. }
  2065. }
  2066. term_data.sort(function(a,b){
  2067. return b.weight-a.weight;
  2068. });
  2069. }
  2070. function text_input_textarea_focuse(el){
  2071. term_set_word_list_data(el);
  2072. term_input_text = el;
  2073. term_input_text.onresize = function(){
  2074. term_input_text.parentElement.querySelector(".text_shadow").style.height=term_input_text.clientHeight+"px";
  2075. }
  2076. term_input_text.onkeydown = function (e) {
  2077. let menu = term_input_text.parentElement.querySelector('.menu');
  2078. switch (e.key) {
  2079. case "ArrowDown"://down arrow
  2080. if(menu.style.display=="block"){
  2081. menuFocusIndex++;
  2082. if(menuFocusIndex>_term_max_menu){
  2083. menuFocusIndex=_term_max_menu;
  2084. }
  2085. menu.innerHTML=TermAtRenderMenu({focus:menuFocusIndex});
  2086. return false;
  2087. }
  2088. break;
  2089. case "ArrowUp"://up arrow
  2090. if(menu.style.display=="block"){
  2091. menuFocusIndex--;
  2092. if(menuFocusIndex<0){
  2093. menuFocusIndex=0;
  2094. }
  2095. menu.innerHTML=TermAtRenderMenu({focus:menuFocusIndex});
  2096. return false;
  2097. }
  2098. break;
  2099. case "Enter":
  2100. if(menu.style.display=="block"){
  2101. term_insert(term_filterd_data[menuFocusIndex]);
  2102. return false;
  2103. }
  2104. if (e.ctrlKey) {
  2105. //回车存盘
  2106. tran_sent_save(e.currentTarget);
  2107. return false;
  2108. }
  2109. break;
  2110. case "Escape":
  2111. if(menu.style.display=="block"){
  2112. term_at_menu_hide();
  2113. }else{
  2114. tran_sent_edit_cancel(e.currentTarget);
  2115. }
  2116. break;
  2117. default:
  2118. break;
  2119. }
  2120. }
  2121. term_input_text.onkeyup = function (e) {
  2122. let textHeight = term_input_text.parentElement.querySelector(".text_shadow").scrollHeight;
  2123. let textHeight2 = term_input_text.clientHeight;
  2124. if(textHeight2>textHeight){
  2125. textHeight=textHeight2;
  2126. }
  2127. term_input_text.style.height = textHeight+"px";
  2128. console.log("text height",textHeight);
  2129. let value = term_input_text.value
  2130. let selectionStart = term_input_text.selectionStart
  2131. let str1 = value.slice(0, selectionStart)
  2132. let str2 = value.slice(selectionStart)
  2133. let textNode1 = document.createTextNode(str1)
  2134. let textNode2 = document.createTextNode(str2)
  2135. let cursor = document.createElement('span')
  2136. cursor.innerHTML = '&nbsp;'
  2137. cursor.setAttribute('class','cursor')
  2138. let mirror = term_input_text.parentElement.querySelector('.text_shadow')
  2139. mirror.innerHTML = ''
  2140. mirror.appendChild(textNode1)
  2141. mirror.appendChild(cursor)
  2142. mirror.appendChild(textNode2)
  2143. let menu = term_input_text.parentElement.querySelector('.menu');
  2144. if(str1.slice(-2)=="[[" ){
  2145. if( menu.style.display!="block"){
  2146. menuFocusIndex=0;
  2147. menu.innerHTML=TermAtRenderMenu({focus:0});
  2148. term_at_menu_show(cursor);
  2149. }
  2150. }else{
  2151. if( menu.style.display=="block"){
  2152. let pos1=str1.lastIndexOf("[[");
  2153. let pos2=str1.lastIndexOf("]]");
  2154. if(pos1==-1 || (pos1!=-1 && pos2>pos1)){
  2155. //光标前没有[[ 或 光标在[[]] 之后
  2156. term_at_menu_hide();
  2157. }
  2158. }
  2159. }
  2160. if(menu.style.display=="block"){
  2161. //term_input += e.key;
  2162. let value = term_input_text.value
  2163. let selectionStart = term_input_text.selectionStart
  2164. let str1 = value.slice(0, selectionStart)
  2165. let str2 = value.slice(selectionStart)
  2166. let pos1=str1.lastIndexOf("[[");
  2167. let pos2=str1.lastIndexOf("]]");
  2168. if(pos1!=-1){
  2169. if(pos2==-1 || pos2<pos1){
  2170. //光标
  2171. term_input = str1.slice(str1.lastIndexOf("[[")+2);
  2172. }
  2173. }
  2174. console.log("term_input",term_input);
  2175. menu.innerHTML=TermAtRenderMenu({focus:menuFocusIndex});
  2176. }
  2177. console.log(e.key);
  2178. console.log(cursor.offsetLeft,cursor.offsetTop)
  2179. }
  2180. }
  2181. function term_at_menu_show(cursor){
  2182. menuFocusIndex=0;
  2183. let menu = term_input_text.parentElement.querySelector('.menu');
  2184. menu.style.display="block";
  2185. menu.style.top=cursor.offsetTop+20+"px";
  2186. menu.style.left=cursor.offsetLeft+"px";
  2187. $(document).on("keyup", function (e) {
  2188. if(e.key=="Escape"){
  2189. term_at_menu_hide();
  2190. }
  2191. });
  2192. }
  2193. function term_at_menu_hide(){
  2194. let menu = term_input_text.parentElement.querySelector('.menu');
  2195. menu.style.display="none";
  2196. term_input="";
  2197. }
  2198. function term_insert(strTerm){
  2199. let value = term_input_text.value;
  2200. let selectionStart = term_input_text.selectionStart;
  2201. let str1 = value.slice(0, selectionStart)
  2202. let str2 = value.slice(selectionStart)
  2203. let pos1=str1.lastIndexOf("[[");
  2204. let pos2=str1.lastIndexOf("]]");
  2205. if(pos1!=-1){
  2206. //光标前有[[
  2207. if(pos2==-1 || pos2<pos1){
  2208. //光标在[[之间]]
  2209. str1 = str1.slice(0,str1.lastIndexOf("[[")+2);
  2210. }
  2211. }
  2212. //TODO 光标会跑到最下面
  2213. term_input_text.value = str1+strTerm+"]]"+str2;
  2214. term_at_menu_hide();
  2215. }
  2216. function TermAtRenderMenu(params) {
  2217. term_filterd_data=[];
  2218. let html="";
  2219. html +="<div class='term_at_menu_input'>"+term_input+"|</div>";
  2220. html +="<ul class='term_at_menu_ul'>";
  2221. let index=0;
  2222. let focusIndex = params.focus%term_data.length;
  2223. for (const it of term_data) {
  2224. if(term_input=="" || it.word.indexOf(term_input)==0 || it.en.indexOf(term_input)==0){
  2225. html +="<li ";
  2226. if(focusIndex==index){
  2227. html +="class='trem_focus' "
  2228. }
  2229. html += "onclick=\"term_insert('"+it.word+"')\" ";
  2230. html +=">";
  2231. html += (index+1)+ ". ";
  2232. if(it.exist>0){
  2233. html += "<b>"+it.word+"</b>";
  2234. }else{
  2235. html +=it.word;
  2236. }
  2237. html +="<li>";
  2238. term_filterd_data.push(it.word);
  2239. if(index >= _term_max_menu){
  2240. break;
  2241. }
  2242. index++;
  2243. }
  2244. }
  2245. return html;
  2246. }
  2247. //添加自动格位数据到内存字典
  2248. function term_parent(paliword) {
  2249. let output=[];
  2250. for (const it of gCaseTable) {
  2251. if (it.type != ".v.") {
  2252. let sEnd2 = paliword.slice(0 - it.end2.length);
  2253. if (sEnd2 == it.end2) {
  2254. let wordParent = paliword.slice(0, 0 - it.end2.length) + it.end1;
  2255. output[wordParent]=1;
  2256. }
  2257. }
  2258. }
  2259. return output;
  2260. }