| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274 |
- /*
- {{203-1654-23-45@11@en@*}}
- <note>203-1654-23-45@11@en@*</note>
- <note id=guid book=203 para=1654 begin=23 end=45 author=11 lang=en tag=*></note>
- <note id=guid book=203 para=1654 begin=23 end=45 author=11 lang=en tag=*>
- <div class=text>
- pali text
- </div>
- <tran>
- </tran>
- <ref>
- </ref>
- </note>
- */
- /*
- 解析百科字符串
- {{203-1654-23-45@11@en@*}}
- <note id=12345 info="203-1654-23-45@11@en@*"><note>
- <note id="guid" book=203 para=1654 begin=23 end=45 author=11 lang=en tag=*></note>
- */
- var _word = "";
- var _channal = "";
- var _lang = "";
- var _author = "";
- function note_init(input) {
- let output = "<div>";
- let newString = input.replace(/\{\{/g, '<note info="');
- newString = newString.replace(/\}\}/g, '"></note>');
- output = marked(newString);
- /*
- let arrInput = input.split("\n");
- for (x in arrInput) {
- if (arrInput[x].slice(0, 2) == "==" && arrInput[x].slice(-2) == "==") {
- output += "</div></div>";
- output += '<div class="submenu1">';
- output +=
- '<p class="submenu_title1" onclick="submenu_show_detail(this)">';
- output += arrInput[x].slice(2, -2);
- output += '<svg class="icon" style="transform: rotate(45deg);">';
- output += '<use xlink:href="svg/icon.svg#ic_add"></use>';
- output += "</svg>";
- output += "</p>";
- output += '<div class="submenu_details1" >';
- } else {
- let row = arrInput[x];
- row = row.replace(/\{\{/g, '<note info="');
- row = row.replace(/\}\}/g, '"></note>');
- if (row.match("{") && row.match("}")) {
- row = row.replace("{", "<strong>");
- row = row.replace("}", "</strong>");
- }
- output += row;
- }
- }
- */
- output += "</div>";
- return output;
- }
- function note_update_background_style() {
- var mSentsBook = new Array();
- var mBgIndex = 1;
- $("note").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 == "") {
- id = com_guid();
- iterator.id = id;
- let info = iterator.getAttributeNode("info").value;
- let arrInfo = info.split("-");
- if (arrInfo.length >= 2) {
- let book = arrInfo[0];
- let para = arrInfo[1];
- }
- if (info && info != "") {
- 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 arrData = JSON.parse(data);
- for (const iterator of arrData) {
- let id = iterator.id;
- let strHtml = "<a name='" + id + "'></a>";
- if (_display && _display == "para") {
- let strPalitext = "<pali>" + iterator.palitext + "<pali>";
- let divPali = $("#" + id)
- .parent()
- .children(".palitext");
- if (divPali.length == 0) {
- $("#" + id)
- .parent()
- .prepend("<div class='palitext'></div>");
- }
- $("#" + id)
- .parent()
- .children(".palitext")
- .first()
- .append(strPalitext);
- let htmlTran =
- "<span class='tran'>" +
- marked(term_std_str_to_tran(iterator.tran)) +
- "</span>";
- $("#" + id).html(htmlTran);
- } else {
- strHtml += note_json_html(iterator);
- $("#" + id).html(strHtml);
- }
- }
- $(".palitext").click(function () {
- let sentid = $(this).parent().attr("info").split("-");
- window.open(
- "../pcdl/reader.php?view=sent&book=" +
- sentid[0] +
- "¶=" +
- sentid[1] +
- "&begin=" +
- sentid[2] +
- "&end=" +
- sentid[3]
- );
- });
- note_ref_init();
- term_get_dict();
- note_channal_list();
- } catch (e) {
- console.error(e);
- }
- }
- }
- );
- }
- }
- function note_channal_list() {
- console.log("note_channal_list start");
- let objNotes = document.querySelectorAll("note");
- let arrSentInfo = new Array();
- for (const iterator of objNotes) {
- {
- let info = iterator.getAttributeNode("info").value;
- 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 arrData = JSON.parse(data);
- let strHtml = "";
- for (const iterator of arrData) {
- strHtml += render_channal_list(iterator);
- }
- $("#channal_list").html(strHtml);
- } catch (e) {
- console.error(e);
- }
- }
- }
- );
- }
- }
- function render_channal_list(channalinfo) {
- let output = "";
- output += "<div class='list_with_head'>";
- output += "<div class='head'>";
- output += "<span class='head_img'>";
- output += channalinfo.nickname.slice(0, 2);
- output += "</span>";
- output += "</div>";
- output += "<div>";
- output += "<div>";
- output += "<a href='../wiki/wiki.php?word=" + _word;
- output += "&channal=" + channalinfo.id + "' >";
- output += channalinfo["nickname"];
- output += "/" + channalinfo["name"];
- output += "</a>";
- output += "</div>";
- output += "<div>";
- output += "@" + channalinfo["username"];
- output += "</div>";
- output += "</div>";
- output += "</div>";
- return output;
- }
- function note_ref_init() {
- $("chapter").click(function () {
- let bookid = $(this).attr("book");
- let para = $(this).attr("para");
- window.open(
- "../pcdl/reader.php?view=chapter&book=" + bookid + "¶=" + para,
- "_blank"
- );
- });
- $("para").click(function () {
- let bookid = $(this).attr("book");
- let para = $(this).attr("para");
- window.open(
- "../pcdl/reader.php?view=para&book=" + bookid + "¶=" + para,
- "_blank"
- );
- });
- }
- /*
- id
- palitext
- tran
- ref
- */
- function note_json_html(in_json) {
- let output = "";
- output += "<div class='palitext'>" + in_json.palitext + "</div>";
- output +=
- "<div class='tran'>" +
- marked(term_std_str_to_tran(in_json.tran)) +
- "</div>";
- output += "<div class='ref'>" + in_json.ref + "</div>";
- return output;
- }
|