var postTitle = new Array(); var postContent = new Array(); var postId = new Array(); var postDate = new Array(); var postPermalink = new Array(); var commentAuthor = new Array(); var commentContent = new Array(); var commentDate = new Array(); var blogid, blogurl, totalComments; var monthnames = new Array(); var startIndex = 1; var oldestFirstOrder = 0; function dateString(rawdate, needYear) { monthnames[1] = "一月"; monthnames[2] = "二月"; monthnames[3] = "三月"; monthnames[4] = "四月"; monthnames[5] = "五月"; monthnames[6] = "六月"; monthnames[7] = "七月"; monthnames[8] = "八月"; monthnames[9] = "九月"; monthnames[10] = "十月"; monthnames[11] = "十一月"; monthnames[12] = "十二月"; var year = rawdate.substring(0,4); var month = rawdate.substring(5,7); var day = rawdate.substring(8,10); str = monthnames[parseInt(month,10)] + ' ' + day; if (needYear) str = str + ', ' + year; return (str); } function updateLabelPosts(json) { feedid = json.feed.id.$t; start = feedid.indexOf('blog-'); blogid = feedid.substr(start+5); for (var k = 0; k < json.feed.link.length; k++) { if (json.feed.link[k].rel == 'alternate') { alturl = json.feed.link[k].href; break; } } index = alturl.lastIndexOf('/'); var label = alturl.substr(index+1); label = decodeURIComponent(label); var labelposts = document.getElementById("LabelPosts"); var labeltitle = document.getElementById("LabelTitle"); if (label == "") { labeltitle.innerHTML = '

最新文章


'; } else { labeltitle.innerHTML = '

标签为 "' + label + '"的文章

'; labeltitle.innerHTML = labeltitle.innerHTML + ' '; labeltitle.innerHTML = labeltitle.innerHTML + '订阅
'; } var disp = ''; for (var i = 0; i < json.feed.entry.length; i++) { var entry = json.feed.entry[i]; var selfurl; postTitle[i] = entry.title.$t; postContent[i] = entry.content.$t; postDate[i] = entry.published.$t.substring(0,10); entryid = entry.id.$t; start = entryid.indexOf('post-'); postId[i] = entryid.substr(start+5); for (var k = 0; k < entry.link.length; k++) { if (entry.link[k].rel == 'alternate') { postPermalink[i] = entry.link[k].href; break; } } disp = disp + '' + entry.title.$t + '

'; } if (label == "index.html") label = ""; disp = disp + ''; labelposts.innerHTML = disp; } function updatePost(index) { var datediv = document.getElementById("PostDate"); var titlediv = document.getElementById("PostTitle"); var contentdiv = document.getElementById("PostContent"); var editdiv = document.getElementById("PostEditLink"); var commentdiv = document.getElementById("PostCommentLink"); datediv.innerHTML = dateString(postDate[index], 1); titlediv.innerHTML = '' + postTitle[index] + ''; contentdiv.innerHTML = '

' + postContent[index] + '

'; if (editdiv) editdiv.innerHTML = ' '; commentdiv.innerHTML = '添加评论'; var backlinksdiv = document.getElementById("backlinks-container"); backlinksdiv.innerHTML = ''; //var postdiv = document.getElementById("post"); //postdiv.scrollIntoView(true); checkFullNeo(); fetchComments(postId[index]); } function updateComments(json) { if (json.feed.entry) { for (var i = 0; i < json.feed.entry.length; i++) { var entry = json.feed.entry[i]; commentAuthor[i] = entry.author[0].name.$t; commentContent[i] = entry.content.$t; commentDate[i] = entry.published.$t.substring(0,10); } totalComments = json.feed.entry.length; } else totalComments = 0; updateCommentsPage(0); } function showNextPage(page) { updateCommentsPage(page); var commentdiv = document.getElementById('comments'); commentdiv.scrollIntoView(true); } function updateCommentsPage(page) { var commentdiv = document.getElementById('comments'); if (totalComments == 0) { commentdiv.innerHTML = "

没有评论

"; return; } disp = "

" + totalComments + " 个评论"; var numpages = (totalComments / 10); if (numpages > 1) { disp = disp + ", 翻页: " for (i = 0; i < numpages; i++) { if (i == page) disp = disp + (i+1) + "  "; else disp = disp + '' + (i+1) + '  '; } } disp = disp + "

"; if (oldestFirstOrder == 1) { max = totalComments - 1 - (page * 10); min = totalComments - 1 - ((page+1) * 10); if (min < 0) min = 0; for (var i = max; i >= min; i--) { disp = disp + "
" + commentAuthor[i] + ",在 " + dateString(commentDate[i], 0) + "日, " + " 说...
"; if (commentAuthor[i] == blogAuthor) { disp = disp + "
" + commentContent[i] + "

"; } else { disp = disp + "
" + commentContent[i] + "

"; } } } else { max = (page + 1) * 10; if (max > totalComments) max = totalComments; for (var i = page * 10; i < max; i++) { disp = disp + "
" + commentAuthor[i] + ",在 " + dateString(commentDate[i], 0) + "日, " + " 说...
"; if (commentAuthor[i] == blogAuthor) { disp = disp + "
" + commentContent[i] + "

"; } else { disp = disp + "
" + commentContent[i] + "

"; } } } disp = disp + "
"; if (page < (numpages-1)) { disp = disp + '

查看下一页评论►


'; } commentdiv.innerHTML = disp; } function fetchOlderPosts(label) { startIndex = startIndex + numPosts; fetchPosts(label); document.getElementById('LabelDisplay').scrollIntoView(true); } function fetchNewerPosts(label) { startIndex = startIndex - numPosts; fetchPosts(label); document.getElementById('LabelDisplay').scrollIntoView(true); } function fetchLatestPosts(url, label) { blogurl = url; startIndex = 1; fetchPosts(label); } function fetchPosts(label) { var labelposts = document.getElementById("LabelPosts"); var labeltitle = document.getElementById("LabelTitle"); labeltitle.innerHTML = "

 读取中/Loading Indicator

"; if (label == '') { feedurl = blogurl + 'feeds/posts/default?orderby=published&start-index=' + startIndex + '&max-results=' + numPosts + '&alt=json-in-script&callback=updateLabelPosts'; } else { label = label.replace(" ", "%20"); feedurl = blogurl + 'feeds/posts/default/-/' + label + '?orderby=published&start-index=' + startIndex + '&max-results=' + numPosts + '&alt=json-in-script&callback=updateLabelPosts'; } var script = document.createElement('script'); script.setAttribute('src', feedurl); script.setAttribute('id', 'jsonScript'); script.setAttribute('type', 'text/javascript'); document.documentElement.firstChild.appendChild(script); } function fetchComments(postid) { var script = document.createElement('script'); script.setAttribute('src', blogurl + 'feeds/' + postid + '/comments/default?max-results=100&alt=json-in-script&callback=updateComments'); script.setAttribute('id', 'jsonScript'); script.setAttribute('type', 'text/javascript'); document.documentElement.firstChild.appendChild(script); } function showFullNeo() { var showspan = document.getElementById('showlink'); var hidespan = document.getElementById('hidelink'); var fullspan = document.getElementById('fullpost'); showspan.style.display = 'none'; hidespan.style.display = 'inline'; fullspan.style.display = 'inline'; } function hideFullNeo() { var showspan = document.getElementById('showlink'); var hidespan = document.getElementById('hidelink'); var fullspan = document.getElementById('fullpost'); showspan.style.display = 'inline'; hidespan.style.display = 'none'; fullspan.style.display = 'none'; var post = document.getElementById('post'); post.scrollIntoView(true); } function checkFullNeo() { var showspan = document.getElementById('showlink'); var hidespan = document.getElementById('hidelink'); var fullpost = document.getElementById('fullpost'); if (fullpost) { showspan.style.display = 'inline'; hidespan.style.display = 'none'; } else { showspan.style.display = 'none'; hidespan.style.display = 'none'; } }