// This file is part of the Neo template. As I spent quite some time developing // this code, please give proper credits to Hackosphere if you are going to // re-use the code. // - Ramani@hackosphere 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] = "January"; monthnames[2] = "February"; monthnames[3] = "March"; monthnames[4] = "April"; monthnames[5] = "May"; monthnames[6] = "June"; monthnames[7] = "July"; monthnames[8] = "August"; monthnames[9] = "September"; monthnames[10] = "October"; monthnames[11] = "November"; monthnames[12] = "December"; 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] + '

    ' + '
    '+'本文固定網址' + '
    ' + '' + postPermalink[index] + ''+ '
    '; if (editdiv) editdiv.innerHTML = ' '; commentdiv.innerHTML = '按我就可以回應'; var backlinksdiv = document.getElementById("backlinks-container"); backlinksdiv.innerHTML = ''; var postdiv = document.getElementById("post"); postdiv.scrollIntoView(true); new Effect.Highlight('post',{startcolor:'#C3D9FF', duration: 2.0, endcolor:'#fafafa'}); 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'); document.getElementById('LabelDisplay').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 + ", Pages: " 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 + "
    " + "On " + dateString(commentDate[i], 0) + ", " + commentAuthor[i] + " said...
    "; 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 + "
    " + " " + dateString(commentDate[i], 0) + ", " + commentAuthor[i] + " 同學說...
    "; 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); new Effect.ScrollTo("LabelDisplay",{offset: 0}); } function fetchNewerPosts(label) { startIndex = startIndex - numPosts; fetchPosts(label); //document.getElementById('LabelDisplay').scrollIntoView(true); new Effect.ScrollTo("LabelDisplay",{offset: 0}); } function fetchLatestPosts(url, label) { blogurl = url; startIndex = 1; fetchPosts(label); } function fetchLatestPosts2(url, label) { blogurl = url; startIndex = 1; fetchPosts2(label); } function fetchPosts(label) { var labelposts = document.getElementById("LabelPosts"); var labeltitle = document.getElementById("LabelTitle"); labeltitle.innerHTML = "

    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); //document.getElementById('LabelDisplay').scrollIntoView(true); new Effect.ScrollTo("LabelDisplay",{offset: 0}); new Effect.Highlight('LabelDisplay',{startcolor:'#C3D9FF', duration: 2.0, endcolor:'#fafafa'}); } function fetchPosts2(label) { var labelposts = document.getElementById("LabelPosts"); var labeltitle = document.getElementById("LabelTitle"); labeltitle.innerHTML = "

    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'; } }