//import {Like,LikeRefresh} from '../widget/like.js';
var _view = "";
var _id = "";
var _articel_id = "";
var _channal = "";
var _lang = "";
var _author = "";
var _display = "";
var _collection_id = "";
var _book=0,_par=0,_start=0,_end=0;
var _sent_data;
var _article_date;
function article_onload() {
historay_init();
}
function articel_load(id, collection_id) {
if (id == "") {
return;
}
$.get(
"../article/get.php",
{
id: id,
collection_id: collection_id,
setting: "",
},
function (data, status) {
if (status == "success") {
try {
let result = JSON.parse(data);
if (result) {
_article_date = result;
$("#article_title").html(result.title);
$("#article_path_title").html(result.title);
$("#page_title").text(result.title);
$("#article_subtitle").html(result.subtitle);
let article_author = result.username.nickname + "@" + result.username.username;
if(result.lang !== "false"){
article_author += result.lang;
}else{
result.lang = "en";
}
$("#article_author").html( article_author );
//将绝对链接转换为 用户连接的主机链接
result.content = result.content.replace(/[A-z]*.wikipali.org/g,WWW_DOMAIN_NAME);
$("#contents").html(note_init(result.content,"",result.owner,result.lang));
note_refresh_new();
guide_init();
}
} catch (e) {
console.error(e);
}
} else {
console.error("ajex error");
}
}
);
}
function collect_load(id) {
if (id == "") {
return;
}
$.get(
"../article/collect_get.php",
{
id: id,
setting: "",
},
function (data, status) {
if (status == "success") {
try {
let result = JSON.parse(data);
if (result) {
$("#article_title").html(result.title);
$("#page_title").text(result.title);
if (result.subtitle) {
$("#article_subtitle").html(result.subtitle);
}
$("#article_author").html(result.username.nickname + "@" + result.username.username);
let htmlLike = "";
htmlLike += "";
htmlLike += "";
$("#like_div").html(htmlLike);
$("#summary").html(result.summary);
$("#contents").html("
目录
");
let article_list = JSON.parse(result.article_list);
render_article_list(article_list);
render_article_list_in_content(article_list);
$("#content_toc").fancytree("getRootNode").visit(function(node){
node.setExpanded(true);
});
Like();
}
} catch (e) {
console.error(e);
}
} else {
console.error("ajex error");
}
}
);
}
function articel_load_article_list(articleId,collectionId) {
$.get(
"../article/collect_get.php",
{
id: collectionId,
setting: "",
},
function (data, status) {
if (status == "success") {
try {
let result = JSON.parse(data);
if (result) {
let article_list = JSON.parse(result.article_list);
render_article_list(article_list,collectionId,articleId);
articleFillFootNavButton(article_list,articleId);
let strTitle = "" + result.title + " / ";
for (const iterator of tocActivePath) {
strTitle += "" + iterator.title + " / ";
}
$("#article_path").html(strTitle);
}
} catch (e) {
console.error(e);
}
} else {
console.error("ajex error");
}
}
);
}
var prevArticle=0,nextArticle=0;
function articleFillFootNavButton(article_list,curr_article){
for (let index = 0; index < article_list.length; index++) {
const element = article_list[index];
if(element.article==curr_article){
if(index!=0){
$("#contents_nav_left_inner").html(article_list[index-1].title);
prevArticle = article_list[index-1].article;
}else{
$("#contents_nav_left_inner").html("无");
}
if(index!=article_list.length-1){
$("#contents_nav_right_inner").html(article_list[index+1].title);
nextArticle = article_list[index+1].article;
}else{
$("#contents_nav_right_inner").html("无");
}
}
}
}
function goto_prev() {
switch (_view) {
case "article":
if(prevArticle==0){
alert("已经到达开始");
}else{
gotoArticle(prevArticle);
}
break;
case "collection":
break;
case "sent":
case "para":
gotoPara(_par-1);
case "chapter":
if(prevChapter>0){
gotoChapter(prevChapter);
}else{
alert("已经到达开始");
}
break;
case "book":
case "series":
break;
case "simsent":
case "sim":
break;
default:
break;
}
}
function goto_next() {
switch (_view) {
case "article":
if(nextArticle==0){
alert("已经到达最后");
}else{
gotoArticle(nextArticle);
}
break;
case "collection":
break;
case "sent":
case "para":
gotoPara(_par+1);
break;
case "chapter":
if(nextChapter>0){
gotoChapter(nextChapter);
}else{
alert("已经到达最后");
}
break;
case "book":
case "series":
break;
case "simsent":
case "sim":
break;
default:
break;
}
}
//在collect 中 的article列表
function render_article_list(article_list,collectId="",articleId="") {
$("#toc_content").fancytree({
autoScroll: true,
source: tocGetTreeData(article_list,articleId),
activate: function(e, data) {
gotoArticle(data.node.key,collectId);
return false;
}
});
}
//在 正文中的目录
function render_article_list_in_content(article_list,collectId="",articleId="") {
$("#content_toc").fancytree({
autoScroll: true,
source: tocGetTreeData(article_list,articleId),
activate: function(e, data) {
gotoArticle(data.node.key,collectId);
return false;
}
});
}
function set_channal(channalid) {
let url = "../article/index.php?";
if (_view != "") {
url += "view=" + _view;
}
if (_id != "") {
url += "&id=" + _id;
}
if (_book != 0) {
url += "&book=" + _book;
}
if (_par != 0) {
url += "&par=" + _par;
}
if (_start != 0) {
url += "&start=" + _start;
}
if (_end != 0) {
url += "&end=" + _end;
}
if (_collection_id != "") {
url += "&collection=" + _collection_id;
}
if (channalid != "") {
url += "&channal=" + channalid;
}
if (_display != "") {
url += "&display=" + _display;
}
if (_mode != "") {
url += "&mode=" + _mode;
}
if (_direction != "") {
url += "&direction=" + _direction;
}
location.assign(url);
}
function setMode(mode = "read") {
let url = "../article/index.php?";
if (_view != "") {
url += "view=" + _view;
}
if (_id != "") {
url += "&id=" + _id;
}
if (_book != 0) {
url += "&book=" + _book;
}
if (_par != 0) {
url += "&par=" + _par;
}
if (_start != 0) {
url += "&start=" + _start;
}
if (_end != 0) {
url += "&end=" + _end;
}
if (_collection_id != "") {
url += "&collection=" + _collection_id;
}
if (_channal != "") {
url += "&channal=" + _channal;
}
if (_display != "") {
if (mode == "read") {
url += "&display=" + _display;
} else {
url += "&display=sent";
}
}
if (mode != "") {
url += "&mode=" + mode;
}
if (_direction != "") {
url += "&direction=" + _direction;
}
location.assign(url);
}
//跳转到另外一个文章
function gotoArticle(articleId) {
let url = "../article/index.php?view=article&id=" + articleId;
if (_collection_id != "") {
url += "&collection=" + _collection_id;
}
if (_channal != "") {
url += "&channal=" + _channal;
}
if (_display != "") {
url += "&display=" + _display;
}
if (_mode != "") {
url += "&mode=" + _mode;
}
if (_direction != "") {
url += "&direction=" + _direction;
}
location.assign(url);
}
function palicanon_load() {
let param;
switch (_view) {
case "sent":
case "para":
case "chapter":
param = {
view: _view,
book: _book,
par: _par,
start: _start,
end: _end,
}
break;
case "simsent":
case "sim":
param = {view: _view,id:_id};
break;
default:
break;
}
$.get(
"../reader/get_para1.php",
param,
function (data, status) {
if (status == "success") {
try {
let result = JSON.parse(data);
if (result) {
_sent_data=result;
$("#article_title").html(result.title);
$("#article_path_title").html(result.title);
$("#page_title").text(result.title);
$("#article_subtitle").html(result.subtitle);
$("#article_author").html(result.username.nickname + "@" + result.username.username);
$("#contents").html(note_init(result.content));
note_refresh_new(function () {
document.querySelector("#para_focus").scrollIntoView({
block: "end",
behavior: "smooth",
});
});
reader_draw_para_menu();
guide_init();
}
} catch (e) {
console.error(e);
}
} else {
console.error("ajex error");
}
}
);
}
function reader_get_path() {
$.get(
"../reader/get_path.php",
{
book: _book,
para: _par,
},
function (data) {
$("#article_path").html(data);
var bookTitle = $("chapter").first().html();
let suttaTitle = $("chapter").last().html();
$("#pali_pedia").html(bookTitle);
$("#article_title").html(suttaTitle);
$("#page_title").text(suttaTitle);
}
);
}
function reader_draw_para_menu() {
$(".page_number").each(function () {
let strPara = $(this).text();
$(this).addClass("case_dropdown");
let html = "";
html += "";
$(this).append(html);
});
}
function junp_to_para(book, para) {
let url = "../article/?view=para&book=" + book + "&par=" + para + "&display=sent";
location.assign(url);
}
function copy_para_ref(book, para) {
let output = "";
for (const iterator of _sent_data.sent_list) {
if (iterator.book == book && iterator.paragraph == para) {
output += "{{" + book + "-" + para + "-" + iterator.begin + "-" + iterator.end + "}}\n";
}
}
output += "\n";
copy_to_clipboard(output);
}
function edit_wbw(book, para) {
wbw_channal_list_open(book, [para]);
}
function to_article(){
article_add_dlg_show({
title:_sent_data.title,
content:_sent_data.content,
});
}
var prevChapter=0,nextChapter=0;
var strPrevChapter,strNextChapter;
function render_toc(){
$.getJSON(
"../api/pali_text.php",
{
_method:"index",
view:"toc",
book: _book,
par: _par,
}
).done(function (data) {
let arrToc = new Array();
for (const it of data.data) {
if(_par==it.paragraph){
nextChapter = it.next_chapter;
prevChapter = it.prev_chapter;
}
arrToc.push({article:it.paragraph,title:it.toc,level:it.level});
}
$("#toc_content").fancytree({
autoScroll: true,
source: tocGetTreeData(arrToc,_par),
activate: function(e, data) {
gotoChapter(data.node.key);
return false;
}
});
switch (_view) {
case "chapter":
fill_chapter_nav();
break;
case "para":
fill_para_nav();
break;
case "sent":
fill_sent_nav();
default:
fill_default_nav();
break;
}
});
}
function fill_sent_nav(){
$("#contents_nav_left").hide();
$("#contents_nav_right").hide();
}
function fill_sent_nav(){
$("#contents_nav_left_inner").html("");
$("#contents_nav_right_inner").html("");
}
function fill_para_nav(){
$("#contents_nav_left_inner").html(_par-1);
$("#contents_nav_right_inner").html(_par+1);
}
function fill_chapter_nav(){
if(prevChapter>0){
$.getJSON(
"../api/pali_text.php",
{
_method:"show",
view:"toc",
book: _book,
par: prevChapter,
}
).done(function (data) {
$("#contents_nav_left_inner").html(data.data.toc);
});
}else{
$("#contents_nav_left_inner").html("无");
}
if(nextChapter>0){
$.getJSON(
"../api/pali_text.php",
{
_method:"show",
view:"toc",
book: _book,
par: nextChapter,
}
).done(function (data) {
$("#contents_nav_right_inner").html(data.data.toc);
});
}else{
$("#contents_nav_right_inner").html("无");
}
}
//跳转到另外一个章节
function gotoChapter(paragraph) {
let url = "../article/index.php?view=chapter";
url += "&book=" + _book;
url += "&par=" + paragraph;
if (_channal != "") {
url += "&channal=" + _channal;
}
if (_display != "") {
url += "&display=" + _display;
}
if (_mode != "") {
url += "&mode=" + _mode;
}
if (_direction != "") {
url += "&direction=" + _direction;
}
location.assign(url);
}
//跳转到另外一个章节
function gotoPara(paragraph) {
let url = "../article/index.php?view=para";
url += "&book=" + _book;
url += "&par=" + paragraph;
if (_channal != "") {
url += "&channal=" + _channal;
}
if (_display != "") {
url += "&display=" + _display;
}
if (_mode != "") {
url += "&mode=" + _mode;
}
if (_direction != "") {
url += "&direction=" + _direction;
}
location.assign(url);
}