/**
* Blogger Quick Search Result JSON
* Author: Taufik Nurrohman
* URL: https://plus.google.com/108949996304093815163/about
* See: http://www.dte.web.id/2012/09/membangun-aplikasi-quick-search-dengan.html
*/
// Just a shortcut for document.getElementById();
function getId(id) {
return document.getElementById(id);
}
var config = searchFormConfig,
input = getId('feed-q-input'),
resultContainer = getId('search-result-container'),
resultLoader = getId('search-result-loader'),
skeleton = '';
// The Most Basic :: JSON caller function to display the list of posts in the container
function showResult(json) {
var entry = json.feed.entry ? json.feed.entry : "", url, summary, img;
skeleton = '
' + config.resultTitle + ' "' + input.value + '"
';
skeleton += '×';
if (entry === "") {
skeleton += '- ' + config.noResult + '
';
}
for (var i = 0; i < config.numPost; i++) {
if (i == entry.length) break;
var mark = new RegExp(input.value, "ig"), entries = entry[i], title = entries.title.$t.replace(mark, ""+input.value+"");
for (var j = 0; j < entries.link.length; j++) {
if (entries.link[j].rel == 'alternate') {
url = entries.link[j].href;
break;
}
}
summary = ("summary" in entries && config.summaryPost === true) ? entries.summary.$t : "";
if (config.resultThumbnail === true) {
img = ("media$thumbnail" in entries) ? entries.media$thumbnail.url.replace(/\/s[0-9]+\-c/g, "/s"+config.thumbSize+"-c") : config.fallbackThumb;
}
summary = summary.replace(/
/ig, " ").replace(/<.*?>/g, "").replace(/[<>]/g, "");
if (summary.length > config.summaryLength) {
summary = summary.substring(0, config.summaryLength) + '...';
}
summary = summary.replace(mark, ""+input.value+"");
skeleton += '- '+title+''+summary+'
';
}
skeleton += '
';
resultContainer.innerHTML = skeleton;
resultLoader.style.display = "none";
resultContainer.style.display = "block";
}
// Insert an empty