Created
July 1, 2012 06:13
-
-
Save hemanth/3027086 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(function () { | |
var article_root = $("article"); | |
var search_api = "https://www.googleapis.com/customsearch/v1element"; | |
var apikey = "AIzaSyCVAXiUzRYsML1Pv6RwSG1gunmMikTzQqY"; | |
var cseid = "004387629570218579707:w1sg4iph0mc"; | |
var query = location.hash.match(/^\#q=([^&]+)/)[1]; | |
document.title = "'" + query + "' の検索結果 - 開発な日々"; | |
var result_url = [search_api, "?key=", apikey, "&rsz=large&num=8&cx=", cseid, "&q=", encodeURI(query), "&callback=?"].join(""); | |
$("input[name='q']").val(query); | |
$.getJSON(result_url, function (data) { | |
data.results.forEach(function (result) { | |
var article = article_root.clone(); | |
article.find("h1 a").text(result.titleNoFormatting).attr("href", result.url); | |
article.find("p").html(result.content).append($("<a />").text("続きを読む").attr("href", result.url)); | |
article_root.before(article); | |
}); | |
article_root.remove(); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment