note.js 68 KB

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