note.js 82 KB

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