/** * Advance Search Box For Blogger With JSON * URL: http://www.softglad.com/2013/08/json-search-box-for-blogger.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 += '
  1. ' + config.noResult + '
  2. '; } 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 += '
  3. '+title+''+summary+'

  4. '; } skeleton += '
'; resultContainer.innerHTML = skeleton; resultLoader.style.display = "none"; resultContainer.style.display = "block"; } // Insert an empty