note.js 82 KB

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