var _display = ""; var _word = ""; var _channal = ""; var _lang = ""; var _author = ""; var _arrData = new Array(); var _channalData; var MAX_NOTE_NEST = 2; var gBuildinDictIsOpen = false; /* {{203-1654-23-45@11@en@*}} 203-1654-23-45@11@en@*
pali text
*/ /* 解析百科字符串 {{203-1654-23-45@11@en@*}} */ function note_create() { wbw_channal_list_init(); note_sent_edit_dlg_init(); term_edit_dlg_init(); pali_sim_dlg_init(); related_para_dlg_init(); } function note_sent_edit_dlg_init() { $("body").append( '
' ); guide_init(); $("#note_sent_edit_dlg").dialog({ autoOpen: false, width: 550, buttons: [ { text: gLocal.gui.save, click: function () { note_sent_save(); $(this).dialog("close"); }, }, { text: gLocal.gui.cancel, click: function () { $(this).dialog("close"); }, }, ], }); } function note_init(input) { if (input) { let newString = input.replace(/\{\{/g, '
'); let output = "
"; output += marked(newString); output += "
"; return output; } else { return ""; } } function note_update_background_style() { var mSentsBook = new Array(); var mBgIndex = 1; $("note[info]").each(function () { let info = $(this).attr("info").split("-"); if (info.length >= 2) { let book = info[0]; $(this).attr("book", book); if (!mSentsBook[book]) { mSentsBook[book] = mBgIndex; mBgIndex++; } $(this).addClass("bg_color_" + mSentsBook[book]); } }); } // function note_refresh_new() { note_update_background_style(); let objNotes = document.querySelectorAll("note"); let arrSentInfo = new Array(); for (const iterator of objNotes) { let id = iterator.id; if (id == null || id == "") { //查看这个节点是第几层note嵌套。大于预定层数退出。 let layout = 1; let parent = iterator.parentNode; while (parent.nodeType == 1) { if (parent.nodeName == "NOTE") { layout++; if (layout > MAX_NOTE_NEST) { return false; } } else if (parent.nodeName == "BODY") { break; } parent = parent.parentNode; } id = com_guid(); iterator.id = id; if (iterator.hasAttribute("info")) { let info = iterator.getAttribute("info"); if (info != null || info != "") { /* let arrInfo = info.split("-"); if (arrInfo.length >= 2) { let book = arrInfo[0]; let para = arrInfo[1]; } */ arrSentInfo.push({ id: id, data: info }); } } } } if (arrSentInfo.length > 0) { let setting = new Object(); setting.lang = ""; setting.channal = _channal; $.post( "../term/note.php", { setting: JSON.stringify(setting), data: JSON.stringify(arrSentInfo), }, function (data, status) { if (status == "success") { try { let sentData = JSON.parse(data); for (const iterator of sentData) { let id = iterator.id; let strHtml = ""; if (_display && _display == "para") { //段落模式 let strPalitext = "" + iterator.palitext + ""; let divPali = $("#" + id) .parent() .children(".palitext"); if (divPali.length == 0) { if (_channal != "") { let arrChannal = _channal.split(","); for (let index = arrChannal.length - 1; index >= 0; index--) { const iChannal = arrChannal[index]; $("#" + id) .parent() .prepend("
"); } } $("#" + id) .parent() .prepend("
"); } $("#" + id) .parent() .children(".palitext") .first() .append(strPalitext); let htmlTran = ""; for (const oneTran of iterator.translation) { let html = ""; html += marked( term_std_str_to_tran( oneTran.text, oneTran.channal, oneTran.editor, oneTran.lang ) ); html += ""; if (_channal == "") { htmlTran += html; } else { $("#" + id) .siblings(".tran_div[channal='" + oneTran.channal + "']") .append(html); } } $("#" + id).html(htmlTran); } else { //句子模式 strHtml += note_json_html(iterator); $("#" + id).html(strHtml); } } //处理标签作为气泡注释 popup_init(); //刷新句子链接递归,有加层数限制。 //note_refresh_new(); //将新的数据添加到数据总表 _arrData = _arrData.concat(sentData); note_ref_init(); //获取术语字典 term_get_dict(); //刷新channel列表 note_channal_list(); //显示不同的巴利语脚本 refresh_pali_script(); //把巴利语单词用分隔用于点词查询等 splite_pali_word(); } catch (e) { console.error(e); } } } ); } else { //term_get_dict(); } } //生成channel列表 function note_channal_list() { console.log("note_channal_list start"); let arrSentInfo = new Array(); $("note").each(function () { let info = $(this).attr("info"); if (info && info != "") { arrSentInfo.push({ id: "", data: info }); } }); if (arrSentInfo.length > 0) { $.post( "../term/channal_list.php", { setting: "", data: JSON.stringify(arrSentInfo), }, function (data, status) { if (status == "success") { try { let active = JSON.parse(data); _channalData = active; for (const iterator of _my_channal) { let found = false; for (const one of active) { if (iterator.id == one.id) { found = true; break; } } if (found == false) { _channalData.push(iterator); } } let strHtml = ""; for (const iterator of _channalData) { if (_channal.indexOf(iterator.id) >= 0) { strHtml += render_channal_list(iterator); } } for (const iterator of _channalData) { if (_channal.indexOf(iterator.id) == -1) { strHtml += render_channal_list(iterator); } } $("#channal_list").html(strHtml); set_more_button_display(); } catch (e) { console.error(e); } } } ); } } function find_channal(id) { for (const iterator of _channalData) { if (id == iterator.id) { return iterator; } } return false; } function render_channal_list(channalinfo) { let output = ""; let checked = ""; let selected = "noselect"; if (_channal.indexOf(channalinfo.id) >= 0) { checked = "checked"; selected = "selected"; } output += "
"; output += '
"; output += "
"; output += ""; if (parseInt(channalinfo.power) == 30) { output += gLocal.gui.your.slice(0, 1); } else { output += channalinfo.nickname.slice(0, 1); } output += ""; output += "
"; output += "
"; output += ""; output += "
"; output += channalinfo["username"]; output += "
"; if (channalinfo["final"]) { //进度 output += "
"; let article_len = channalinfo["article_len"]; let svg_width = article_len; let svg_height = parseInt(article_len / 10); output += ''; let curr_x = 0; let allFinal = 0; for (const iterator of channalinfo["final"]) { let stroke_width = parseInt(iterator.len); output += ""; output += ""; output += ''; output += channalinfo["count"] + "/" + channalinfo["all"] + "@" + curr_x; output += ""; output += ""; output += "
"; //进度结束 } output += "
"; output += "
"; return output; } function onChannelMultiSelectStart() { $(".channel_select").show(); } function onChannelMultiSelectCancel() { $(".channel_select").hide(); } function onChannelChange() { let channal_list = new Array(); $("[channal_id]").each(function () { if (this.checked) { channal_list.push($(this).attr("channal_id")); } }); set_channal(channal_list.join()); } //点击引用 需要响应的事件 function note_ref_init() { $("chapter").click(function () { let bookid = $(this).attr("book"); let para = $(this).attr("para"); window.open("../reader/?view=chapter&book=" + bookid + "¶=" + para, "_blank"); }); $("para").click(function () { let bookid = $(this).attr("book"); let para = $(this).attr("para"); window.open("../reader/?view=para&book=" + bookid + "¶=" + para, "_blank"); }); } /* id palitext tran ref */ function note_json_html(in_json) { let output = ""; output += '
'; output += '
'; output += ""; output += ""; output += ""; output += "
"; if (typeof _reader_view != "undefined" && _reader_view != "sent") { output += "" + gLocal.gui.jump_to_this_sent + ""; } output += "" + gLocal.gui.related_para + ""; output += "" + gLocal.gui.show_nissaya + ""; output += "" + gLocal.gui.copy_link + ""; output += "" + gLocal.gui.copy + "“" + gLocal.gui.pāli + "”"; output += "" + gLocal.gui.edit_now + ""; output += "" + gLocal.gui.add_to_edit_list + ""; output += "Slider Show"; output += "
"; output += "
"; output += "
"; output += "
" + in_json.palitext + "
"; output += "
"; output += "
"; //output += "
"; for (const iterator of in_json.translation) { output += render_one_sent_tran_a(iterator); //output += render_one_sent_tran(in_json.book, in_json.para, in_json.begin, in_json.end, iterator); } //所选全部译文结束 //output += "
"; //未选择的其他译文开始 output += "
"; output += "
"; output += ""; //第一个按钮 //新增译文按钮开始 output += ""; output += "
"; output += "
"; output += "
"; //新增译文按钮结束 output += ""; //第二个按钮 output += ""; //其他译文工具条 output += ""; output += "🧲" + gLocal.gui.translation + ""; output += ""; output += ""; output += ""; //手工义注 output += ""; output += "🪔" + gLocal.gui.commentary + ""; output += ""; output += ""; output += ""; //第三个按钮 相似句 if (parseInt(in_json.sim) > 0) { output += ""; output += "🧬" + gLocal.gui.similar + ""; output += "" + in_json.sim + ""; output += ""; output += ""; } //第三个按钮 相似句结束 output += ""; output += ""; //出处路径开始 output += "" + in_json.ref; output += ""; output += in_json.book + "-" + in_json.para + "-" + in_json.begin + "-" + in_json.end; output += ""; output += ""; //出处路径结束 output += ""; output += "
"; //工具栏结束 //未选择的其他译文开始 output += "
"; output += "
"; output += "
"; return output; } function sent_tran_edit(obj) { let jqObj = $(obj); while (!jqObj.hasClass("sent_tran")) { jqObj = jqObj.parent(); if (!jqObj) { return; } } if (jqObj.hasClass("edit_mode")) { jqObj.removeClass("edit_mode"); } else { $(".sent_tran").removeClass("edit_mode"); jqObj.addClass("edit_mode"); } } function sent_pr_merge(id) { $.post( "../usent/sent_pr_merge.php", { id: id, }, function (data) { let result = JSON.parse(data); if (result.status > 0) { alert("error" + result.message); } else { ntf_show("成功采纳"); } } ); } function sent_commit(src, id) { commit_init({ src: src, sent: [id], express: true, }); } function render_one_sent_tran_a(iterator) { let mChannel = get_channel_by_id(iterator.channal); let tranText; let sid = iterator.book + "-" + iterator.para + "-" + iterator.begin + "-" + iterator.end; if (iterator.text == "") { if (typeof iterator.channalinfo == "undefined") { tranText = "" + "空" + "@" + iterator.editor_name.nickname + ""; } else { tranText = "" + iterator.channalinfo.name + "-" + iterator.channalinfo.lang + ""; } } else { //note_init处理句子链接 tranText = note_init(term_std_str_to_tran(iterator.text, iterator.channal, iterator.editor, iterator.lang)); } let html = ""; html += "
"; html += "
"; html += '
'; html += '
'; //句子菜单 html += '
'; if (typeof iterator.is_pr != "undefined" && iterator.is_pr == true) { //在pr 列表中的译文 if (typeof iterator.is_pr_editor != "undefined" && iterator.is_pr_editor == true) { //提交人 //修改按钮 html += ""; //删除按钮 html += ""; } else { //非提交人 if (parseInt(iterator.mypower) >= 20) { //有权限 采纳按钮 html += ""; } //点赞按钮 html += ""; } } else { //非pr列表里的句子 //编辑按钮 html += ""; //推送按钮 let commitIcon = ""; let commitTipText = ""; if (parseInt(iterator.mypower) >= 30 && parseInt(iterator.status) < 30) { //我的私有资源 公开发布 commitIcon = "publish"; commitTipText = gLocal.gui.publish; } else { if (parseInt(iterator.mypower) < 20) { //只读资源 采纳 commitIcon = "accept_copy"; commitTipText = gLocal.gui.accept_copy; } else { //其他资源 复制到 commitIcon = "copy"; commitTipText = gLocal.gui.copy_to; } } html += ""; //推送按钮结束 //更多按钮 html += '"; //更多按钮结束 } html += "
"; //句子菜单结束 html += "
"; html += "
"; //tool_bar 结束 html += '
'; html += '
'; if (iterator.id != "") { html += '' + iterator.editor_name.nickname.slice(0, 1) + ""; } html += "
"; html += '
' + getDataTime(iterator.update_time) + "
"; html += "
"; html += '
'; html += '
'; html += '
'; html += '' + iterator.editor_name.nickname + ""; html += '' + getPassDataTime(iterator.update_time) + ""; html += "
"; html += "
" + tranText + "
"; html += "
"; html += '
'; html += '
'; html += ""; $("#edit_dialog_content").html(html); $("#note_sent_edit_dlg").dialog("open"); return; } } } } alert("未找到句子"); } function update_note_sent_tran(obj) {} //保存pr句子 新 function note_pr_save(obj) { let id = $(obj).attr("dbid"); let sid = $(obj).attr("sid").split("-"); let book = sid[0]; let para = sid[1]; let begin = sid[2]; let end = sid[3]; let channel = $(obj).attr("channel"); let text = $(obj).val(); let sent_tran_div = find_sent_tran_div(obj); $.post( "../usent/pr_post.php", { id: id, book: book, para: para, begin: begin, end: end, channel: channel, text: text, }, sent_save_callback ); if (sent_tran_div) { $(sent_tran_div).find(".preview").addClass("loading"); } } //保存译文句子 新 function note_sent_save_a(obj) { let id = $(obj).attr("dbid"); let sid = $(obj).attr("sid").split("-"); let book = sid[0]; let para = sid[1]; let begin = sid[2]; let end = sid[3]; let channal = $(obj).attr("channel"); let text = $(obj).val(); let sent_tran_div = find_sent_tran_div(obj); $.post( "../usent/sent_post.php", { id: id, book: book, para: para, begin: begin, end: end, channal: channal, text: text, lang: "zh", }, sent_save_callback ); if (sent_tran_div) { $(sent_tran_div).find(".preview").addClass("loading"); } } function sent_save_callback(data) { let result = JSON.parse(data); if (result.status > 0) { alert("error" + result.message); } else { let sid = result.book + "-" + result.para + "-" + result.begin + "-" + result.end; let sent_tran_div = $( ".sent_tran[dbid='" + result.id + "'][channel='" + result.channal + "'][sid='" + sid + "']" ); if (result.commit_type == 1 || result.commit_type == 2) { ntf_show("成功修改"); if (sent_tran_div) { let divPreview = sent_tran_div.find(".preview").first(); if (result.text == "") { let channel_info = "Empty"; let thisChannel = find_channal(result.channal); if (thisChannel) { channel_info = thisChannel.name + "-" + thisChannel.nickname; } divPreview.html("" + channel_info + ""); } else { divPreview.html( marked(term_std_str_to_tran(result.text, result.channal, result.editor, result.lang)) ); term_updata_translation(); popup_init(); for (const iterator of _arrData) { if ( iterator.book == result.book && iterator.para == result.para && iterator.begin == result.begin && iterator.end == result.end ) { for (const tran of iterator.translation) { if (tran.channal == result.channal) { tran.text = result.text; break; } } } } } sent_tran_div.find(".preview").removeClass("loading"); } } else if (result.commit_type == 3) { ntf_show("已经提交修改建议"); } else { ntf_show("未提交"); } } } //保存译文句子 function note_sent_save() { let id = $("#edit_dialog_text").attr("sent_id"); let book = $("#edit_dialog_text").attr("book"); let para = $("#edit_dialog_text").attr("para"); let begin = $("#edit_dialog_text").attr("begin"); let end = $("#edit_dialog_text").attr("end"); let channal = $("#edit_dialog_text").attr("channal"); let text = $("#edit_dialog_text").val(); $.post( "../usent/sent_post.php", { id: id, book: book, para: para, begin: begin, end: end, channal: channal, text: text, lang: "zh", }, function (data) { let result = JSON.parse(data); if (result.status > 0) { alert("error" + result.message); } else { if (result.commit_type == 1 || result.commit_type == 2) { ntf_show("成功修改"); if (result.text == "") { let channel_info = "Empty"; let thisChannel = find_channal(result.channal); if (thisChannel) { channel_info = thisChannel.name + "-" + thisChannel.nickname; } $( "#tran_text_" + result.book + "_" + result.para + "_" + result.begin + "_" + result.end + "_" + result.channal ).html("" + channel_info + ""); } else { $( "#tran_text_" + result.book + "_" + result.para + "_" + result.begin + "_" + result.end + "_" + result.channal ).html(marked(term_std_str_to_tran(result.text, result.channal, result.editor, result.lang))); term_updata_translation(); for (const iterator of _arrData) { if ( iterator.book == result.book && iterator.para == result.para && iterator.begin == result.begin && iterator.end == result.end ) { for (const tran of iterator.translation) { if (tran.channal == result.channal) { tran.text = result.text; break; } } } } } } else if (result.commit_type == 3) { ntf_show("已经提交修改建议"); } else { ntf_show("未提交"); } } } ); } function copy_ref(book, para, begin, end) { let strRef = "{{" + book + "-" + para + "-" + begin + "-" + end + "}}"; copy_to_clipboard(strRef); } function goto_nissaya(book, para, begin = 0, end = 0) { window.open("../nissaya/index.php?book=" + book + "¶=" + para + "&begin=" + begin + "&end=" + end, "nissaya"); } function edit_in_studio(book, para, begin, end) { wbw_channal_list_open(book, [para]); } //显示和隐藏某个内容 如 巴利文 function setVisibility(key, value) { switch (key) { case "palitext": if ($(value).is(":checked")) { $(".palitext").show(); } else { $(".palitext").hide(); } break; default: break; } } function note_show_pali_sim(SentId) { pali_sim_dlg_open(SentId, 0, 20); } function set_pali_script(pos, script) { if (script == "none") { $(".palitext" + pos).html(""); } else { $(".palitext" + pos).each(function () { let html = $(this).siblings(".palitext_roma").first().html(); $(this).html(html); }); $(".palitext" + pos) .find("*") .contents() .filter(function () { return this.nodeType != 1; }) .wrap(""); $(".palitext" + pos) .contents() .filter(function () { return this.nodeType != 1; }) .wrap(""); $("pl" + pos).html(function (index, oldcontent) { return roman_to_my(oldcontent); }); } } function splite_pali_word() { $("pali") .contents() .filter(function () { return this.nodeType != 1; }) .wrap(""); $("pl").each(function () { let html = $(this).html(); $(this).html("" + html.replace(/\s/g, " ") + ""); }); $("w").click(function () { let word = com_getPaliReal($(this).text()); if (gBuildinDictIsOpen) { window.open("../dict/index.php?builtin=true&key=" + word, "dict"); } }); } function refresh_pali_script() { if (_display && _display == "para") { //段落模式 } else { //句子模式 setting_get("lib.second_script", set_second_scrip); } } function set_second_scrip(value) { set_pali_script(2, value); } function slider_show(obj) { $(obj).parent().parent().parent().parent().parent().toggleClass("slider_show_shell"); } function find_sent_tran_div(obj) { let parent = obj.parentNode; while (parent.nodeType == 1) { if ($(parent).hasClass("sent_tran")) { return parent; } else if (parent.nodeName == "BODY") { return false; } parent = parent.parentNode; } return false; } //显示或隐藏pr数据 function note_pr_show(channel, id) { let obj = $(".sent_tran[channel='" + channel + "'][sid='" + id + "']").find(".pr_content"); let prHtml = obj.first().html(); if (prHtml == "") { note_get_pr(channel, id); } else { obj.slideUp(); obj.html(""); } } //获取pr数据并显示 function note_get_pr(channel, id) { let sid = id.split("-"); let book = sid[0]; let para = sid[1]; let begin = sid[2]; let end = sid[3]; $.post( "../usent/get_pr.php", { book: book, para: para, begin: begin, end: end, channel: channel, }, function (data) { let result = JSON.parse(data); if (result.length > 0) { let html = "
"; for (const iterator of result) { html += render_one_sent_tran_a(iterator); } html += "
"; $(".sent_tran[channel='" + channel + "'][sid='" + id + "']") .find(".pr_content") .html(html); $(".sent_tran[channel='" + channel + "'][sid='" + id + "']") .find(".pr_content") .slideDown(); } else { } } ); $(".sent_tran[channel='" + channel + "'][sid='" + id + "']") .find(".pr_content") .html("loading"); $(".sent_tran[channel='" + channel + "'][sid='" + id + "']") .find(".pr_content") .show(); } function get_channel_by_id(id) { if (typeof _channalData != "undefined") { for (const iterator of _channalData) { if (iterator.id == id) { return iterator; } } } if (typeof _my_channal != "undefined") { for (const iterator of _my_channal) { if (iterator.id == id) { return iterator; } } } return false; }