Permalink
Browse files

adding loadMedia, google search support, better weather support

  • Loading branch information...
1 parent 543271d commit 17cf65d20df90ccc8e7c74d936bc4ddad5afa913 @addyosmani committed Jun 9, 2011
Showing with 82 additions and 10 deletions.
  1. +45 −2 css/style.css
  2. +10 −0 index.html
  3. +1 −0 js/mylibs/gsearch.js
  4. +26 −8 js/mylibs/speechBrowser.js
View
@@ -85,8 +85,51 @@ body { font-family:Helvetica, Arial, sans-serif; margin:0 auto; padding:0;}
h1 { font-size:3em; letter-spacing:-1px;}
h3 { color: #ccc}
input[type="text"] { font-size:2em; margin:5px}
-
-
+#search-results { padding-top:20px; text-align:left;}
+#search-results li.numbers { float:left; list-stype-type:none; }
+.google-search-results {
+ font-size: 13px;
+ font-family: Tahoma, Geneva, sans-serif;
+ line-height: 1.5;
+}
+.google-search-results .result {
+ margin: 0 0 20px 0;
+}
+.google-search-results a {
+ color: #666;
+ text-decoration: underline;
+}
+.google-search-results .result .title {
+ font-size: 1.1em;
+}
+.google-search-results .result .url-cache span {
+ color:#282;
+}
+.google-search-results .result .url-cache a {
+ color: #4272db;
+ text-decoration: none;
+}
+.google-search-results .pagination ul {
+ list-style: none;
+ background: none;
+}
+.google-search-results .pagination ul li {
+ list-style: none;
+ background: none;
+ padding: 0;
+ display: inline;
+ margin: 0 5px;
+}
+.google-search-results .pagination ul li a {
+ text-decoration: none;
+}
+.google-search-results .pagination ul li.selected a {
+ color: #000;
+ font-weight: bold;
+}
+.google-search-results .pagination ul li.prev-next a {
+ font-weight: bold;
+}
View
@@ -33,6 +33,9 @@
<input type="submit" name="submitQuery" id="submitQuery" value="Submit" />
<h3>Supports: hello, how is the weather, what is your name, search [something something]</h3>
</form>
+ <div class="search-case">
+ <div id="search-results"></div>
+ </div>
</div>
<footer>
@@ -60,8 +63,15 @@
s.parentNode.insertBefore(g,s)}(document,"script"));
</script>
+<!--tts-->
<script type="text/javascript" src="http://chachakawooka.com/js/cckw_tts.js"></script>
+<!--weather-->
<script type="text/javascript" src="js/mylibs/jquery.simpleWeather-1.8.min.js"></script>
+<!--search-->
+<script type="text/javascript" src="http://google.com/jsapi?key=ABQIAAAA5g3oldWeWxuPrTXKva9onBThuutJKBzNgiFSXrfV8d7em1iSJxTy2j4jgYplI_ynFqz-oxLfNc61Ag"></script>
+<script type="text/javascript">google.load("search", "1");</script>
+<script type="text/javascript" src="js/mylibs/gsearch.js"></script>
+
</body>
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -74,8 +74,23 @@ var speechBrowser = function(){
return z;
},
+ prepareStage:function(){
+ $('#search-results').html('');
+ },
+
+ loadMedia:function(type,url){
+ switch(type){
+ case 'image':
+ $('#search-results').html("<img src='" + url + "'/>");
+ break;
+ }
+ },
+
query: function(val){
var qStr = speech.val();
+
+ this.prepareStage();
+
console.log(qStr);
if(qStr !== null){
@@ -88,7 +103,8 @@ var speechBrowser = function(){
/*now let's get everything after search*/
var searchQuery = qStr.slice(searchTest+searchPhrase.length, qStr.length);
console.log('you searched for:' + searchQuery);
- this.textToSpeech('you searched for:' + searchQuery);
+ this.textToSpeech('i hope these results for' + searchQuery + ' help ');
+ $("#search-results").gSearch({search_text : searchQuery ,count:4,pagination:true});
}else{
@@ -99,9 +115,7 @@ var speechBrowser = function(){
console.log('hello right back at you!');
this.textToSpeech('hello right back at you!');
}
- else if(this.similar(qStr, 'how is the weather today') || this.similar(qStr, 'how is the weather') || this.similar(qStr, 'whats the weather like')){
- //console.log('taking you to weather..');
- //this.textToSpeech('the weather is cold today');
+ else if(this.similar(qStr, 'how is the weather today') || this.similar(qStr, 'how is the weather') || this.similar(qStr, 'whats the weather like')|| this.similar(qStr, 'whats the weather like in london')){
$.when(this.getWeather())
.then(function(){
console.log('weather done');
@@ -113,7 +127,8 @@ var speechBrowser = function(){
}
else if(this.similar(qStr, 'what is your favorite movie')){
console.log('terminator of course');
- this.textToSpeech('terminator of course. we will be back');
+ this.textToSpeech('terminator of course.');
+ this.loadMedia('image','http://www.eurocriticsmagazine.com/wp-content/uploads/2008/06/terminator.jpg');
}
@@ -140,8 +155,10 @@ var speechBrowser = function(){
unit: 'f',
success: function(weather) {
- var result = 'The temperature for ' + weather.city + ' in ' + weather.country + ' is currently ' + weather.temp+ ' degrees ';// + weather.units.temp + '. Todays high will be ' + weather.high+' degrees '+weather.units.temp+ ' and todays low will be ' + weather.low+' degrees '+ weather.units.temp;
+ var result1 = 'The temperature for ' + weather.city + ' in ' + weather.country + ' is currently ' + weather.temp+ ' degrees ' + ' and i think the high will be ' + weather.high;
+ var result2 = ' Todays high will be ' + weather.high+' degrees '+weather.units.temp+ " and todays low will be " + weather.low+' degrees '+ weather.units.temp;
/*
+ baaad string concat, but it's from the API docs. just leaving here for reference.
html = '<h2>'+weather.city+', '+weather.region+' '+weather.country+'</h2>';
html += '<p><strong>Today\'s High</strong>: '+weather.high+'&deg; '+weather.units.temp+' - <strong>Today\'s Low</strong>: '+weather.low+'&deg; '+weather.units.temp+'</p>';
html += '<p><strong>Current Temp</strong>: '+weather.temp+'&deg; '+weather.units.temp+'</p>';
@@ -157,8 +174,9 @@ var speechBrowser = function(){
html += '<p><strong>Last updated</strong>: '+weather.updated+'</p>';
html += '<p><a href="'+weather.link+'">View forecast at Yahoo! Weather</a></p>';*/
- console.log('inner result:' + result);
- speechBrowser.textToSpeech(result);
+ console.log('inner result:' + result1);
+ speechBrowser.textToSpeech(result1);
+ //speechBrowser.textToSpeech(result2);
dfd.resolve();
},

0 comments on commit 17cf65d

Please sign in to comment.