Skip to content

Instantly share code, notes, and snippets.

@skoon
Created September 8, 2009 19:25
Show Gist options
  • Save skoon/183160 to your computer and use it in GitHub Desktop.
Save skoon/183160 to your computer and use it in GitHub Desktop.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Let Me Bing That For You</title>
<style type="text/css">
body {
font-family:Arial,Helvetica,Sans-Serif;
font-size:small;
font-size-adjust:none;
font-style:normal;
font-variant:normal;
font-weight:normal;
line-height:normal;
margin-left:100px;
}
cite, .sb_cite {
color:#568E1A;
font-style:normal;
word-wrap:break-word;
}
h2 {
color:#568E1A;
padding:0 0 2em;
display:inline;
}
input.bingSearchBox {
font-family: Arial,Verdana,Helvetica,Sans-Serif;
font-size: 14pt;
color: #525051;
border: none;
}
div.bingSearchContainer {
margin-bottom:2em;
padding:4px;
border: 1px solid #acbabd;
width:235px;
}
div.bingSearchContainer img{
}
div.result {
padding:0 0 1.38em;
max-width:590px;
}
</style>
<script src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("prototype", "1.6.1.0");
</script>
<script type="text/javascript" id="jsonResults"></script>
<script type="text/javascript">
function loaded() {
Event.observe("bingSearchButton", "click", function(e) {
document.location.href="http://www.bing.com/search?q=" + $("bingSearchBox").value + "&go=&form=QBLH&qs=n";
});
var qs = window.location.search.substring(1);
var phrases = qs.split("&");
var searchPhrase = "";
for(var i =0, l = phrases.length; i<phrases.length; i++)
{
if(phrases[i].substring(0,1) == "q")
searchPhrase = phrases[i].split("=")[1];
}
$("bingSearchBox").value = searchPhrase;
MakeSearchRequest(searchPhrase);
};
function MakeSearchRequest(searchPhrase)
{
var req = "http://api.bing.net/json.aspx?"
+ "AppId=" + "8EF33F72374BCB09E0AD79E51DC921CA4EF70B4E"
+ "&Query=" + searchPhrase
+ "&Sources=Web"
+ "&JsonType=callback"
+ "&JsonCallback=BuildResults";
$("jsonResults").src = req;
};
function BuildResults(jsonResults)
{
var template = new Template("<div class='result'><a href='#{Url}'>#{Title}</a> - <div class='desc'>#{Description}</div><div><cite>#{DisplayUrl}</cite></div>");
jsonResults.SearchResponse.Web.Results.each(function(item) {
$("results").insert(template.evaluate(item));
});
};
Event.observe(window,"load", loaded);
</script>
</head>
<body>
<h2>Let Me <img src="http://www.bing.com/siteowner/s/siteowner/Logo_63x23_Dark.png" align="absmiddle"/> That For You</h2>
<div class="bingSearchContainer">
<input type="text" id="bingSearchBox" class="bingSearchBox"/>
<input type="image" id="bingSearchButton" src="http://www.bing.com/siteowner/s/siteowner/Spyglass_22x22.gif" align="absbottom"/>
</div>
<div id="results"></div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment