var minpage = 6; // Minimum number to display the page
var maxpage = 10; // The maximum number of pages to display
var firstpage = 0; // Detect the first time it is executed
var pagernum = 0; // Contain the page number where we
var postsnum = 0; // Start the first page
var actualpage = 1; // Starting value of the current page (it will change if you click the pagination).
// This is the container template that will be used to insert post template, pagination and the posts count
document.write('');
var _results = document.getElementById('results');
var _pagination = document.getElementById('pagination');
var _totalposts = document.getElementById('totalposts');
// Build the table of contents framework
function showPagePosts(json) {
var entry, posttitle, posturl, postimg, postsumm, replies, monthnames, timepub, output = "";
if (pagernum === 0) {
postsnum = parseInt(json.feed.openSearch$totalResults.$t);
pagernum = parseInt(postsnum / postsperpage) + 1;
}
for (var i = 0; i < postsperpage; i++) {
if ("entry" in json.feed) {
if (i == json.feed.entry.length) break;
entry = json.feed.entry[i];
posttitle = entry.title.$t; // Get the post title
// Get rel="alternate" for truly post url
for (var k = 0, elen = entry.link.length; k < elen; k++) {
if (entry.link[k].rel == 'alternate') {
posturl = entry.link[k].href; // This is your real post URL!
break;
}
}
// If the Blogger-feed is set to SHORT, then the content is in the summary-field
postsumm = ("summary" in entry) ? entry.summary.$t.replace(/
/ig, " ").replace(/<(.*?)>/g, "") : ""; // Get the post summary // Reduce post summaries to "numchars" characters. // "numchars" is a variable. You determine the value if (postsumm.length > numchars) { postsumm = (numchars > 0 && numchars !== false) ? postsumm.substring(0, numchars) + '...' : ""; } // Month array template monthnames = (idMode) ? ["Jan", "Feb", "Mar", "Apr", "Mei", "Jun", "Jul", "Agt", "Sep", "Okt", "Nov", "Des"] : ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]; // Get the post thumbnails postimg = ("media$thumbnail" in entry) ? entry.media$thumbnail.url : imgBlank; // Build the post template output += '
';
}
}
// Put the whole template above into
_results.innerHTML = output;
_create_pagination();
}
// Build the pagination
function _create_pagination() {
output = "";
var starter = 0;
output += ((actualpage > 1) ? '' + prevText + '' : '' + prevText + '') + '';
if (pagernum < (maxpage + 1)) {
for (starter = 1; starter <= pagernum; starter++) {
output += (starter == actualpage) ? '' + starter + '' : '' + starter + '';
}
} else if (pagernum > (maxpage - 1)) {
if (actualpage < minpage) {
for (starter = 1; starter < (maxpage - 2); starter++) {
output += (starter == actualpage) ? '' + starter + '' : '' + starter + '';
}
output += ' ... ';
output += '' + parseInt(pagernum - 1) + '';
output += '' + pagernum + '';
} else if (pagernum - (minpage - 1) > actualpage && actualpage > (minpage - 1)) {
output += '1';
output += '2';
output += ' ... ';
for (starter = actualpage - 2; starter <= actualpage + 2; starter++) {
output += (starter == actualpage) ? '' + starter + '' : '' + starter + '';
}
output += ' ... ';
output += '' + parseInt(pagernum - 1) + '';
output += '' + pagernum + '';
} else {
output += '1';
output += '2';
output += ' ... ';
for (starter = pagernum - (minpage + 1); starter <= pagernum; starter++) {
output += (starter == actualpage) ? '' + starter + '' : '' + starter + '';
}
}
}
output += '' + ((actualpage < starter - 1) ? '' + nextText + '' : '' + nextText + '');
_pagination.innerHTML = output;
var parameter = (actualpage * postsperpage) - (postsperpage - 1),
_final = actualpage * postsperpage;
_totalposts.innerHTML = totalPostLabel + ' ' + postsnum + ' - ' + jumpPageLabel + ' ' + parameter + ((actualpage < starter - 1) ? ' - ' + _final : "");
}
// Functions to remove and append the callback script that has been manipulated in the `start-index` parameter
function _init_script(n) {
var parameter = (n * postsperpage) - (postsperpage - 1);
var url = (sortByLabel) ? siteUrl + '/feeds/posts/summary/-/' + labelSorter + '?start-index=' + parameter : siteUrl + '/feeds/posts/summary/?start-index=' + parameter; // Optional: Sort posts by a specific label
if (firstpage == 1) {
var old = document.getElementById("TEMPORAL");
old.parentNode.removeChild(old);
}
_results.innerHTML = '/ig, " ").replace(/<(.*?)>/g, "") : ""; // Get the post summary // Reduce post summaries to "numchars" characters. // "numchars" is a variable. You determine the value if (postsumm.length > numchars) { postsumm = (numchars > 0 && numchars !== false) ? postsumm.substring(0, numchars) + '...' : ""; } // Month array template monthnames = (idMode) ? ["Jan", "Feb", "Mar", "Apr", "Mei", "Jun", "Jul", "Agt", "Sep", "Okt", "Nov", "Des"] : ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]; // Get the post thumbnails postimg = ("media$thumbnail" in entry) ? entry.media$thumbnail.url : imgBlank; // Build the post template output += '
';
output += '
';
output += '' + posttitle + '
'; output += ''; output += '' + loadingText + '
';
_pagination.innerHTML = '';
_totalposts.innerHTML = '';
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = url + '&max-results=' + postsperpage + '&orderby=published&alt=json-in-script&callback=showPagePosts';
script.id = 'TEMPORAL';
document.getElementsByTagName('head')[0].appendChild(script);
firstpage = 1;
actualpage = n;
}
// Execute the _init_script() function with parameter as `1` on page load
// So it will show the first page.
window.onload = function () {
_init_script(1);
};
0 komentar :
Posting Komentar