note.js 82 KB

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