Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

moved diagnostics by default to settable variable instead of on by de…

…fault
  • Loading branch information...
commit f5cda66f6bd98e9ad36cc56dce3e2c16a4824dc3 1 parent 12654f2
@jcleblanc authored
Showing with 36 additions and 24 deletions.
  1. +19 −15 js-yql-display/yql_js_widget.html
  2. +17 −9 js-yql-display/yql_js_widget.js
View
34 js-yql-display/yql_js_widget.html 100644 → 100755
@@ -1,32 +1,36 @@
-<!--
-yql_js_widget.html
-YQL JavaScript Widget
-
-Created by Jonathan LeBlanc on 06/08/09.
-Copyright (c) 2009 Yahoo! Inc. All rights reserved.
-
-The copyrights embodied in the content of this file are licensed under the BSD (revised) open source license.
--->
-
-<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>YQL / YUI JavaScript Widget</title>
<!-- widget file include -->
<script type="text/javascript" src="yql_js_widget.js"></script>
+
+<style>
+div#widgetContainer, div#widgetContainer2{ margin:10px; }
+div.imgCnt{ border: 1px solid rgb(96, 96, 96); margin: 5px 5px 5px 0pt; float: left; background-color: rgb(241, 241, 241); width:100px; height:140px; }
+div.imgCnt img{ border:0; margin:5px; }
+div.imgCnt div.imgTitle{ padding: 5px; font-size: 11px; text-align:center; }
+</style>
</head>
<body>
+<b>The full documentation and examples for how to set up these samples is available on github at: <a href="http://github.com/jonleblanc/yql-utilities/tree/master" target="_blank">http://github.com/jonleblanc/yql-utilities/tree/master</a></b>
+
<div id="widgetContainer"></div><br style="clear:both" />
+<div id="widgetContainer2"></div>
<script type="text/javascript">
-var config = {'debug':true};
-var format = '<br style="clear:both" /><img src="{content}" width="620" height="500" alt="map" />';
-var yqlQuery = 'SELECT * FROM maps.map WHERE (latitude, longitude) IN (SELECT match.place.centroid.latitude, match.place.centroid.longitude FROM geo.placemaker WHERE documentURL = "http://www.cnn.com/" AND documentType="text/html" AND appid="")';
+var config = {'debug' : true, 'diagnostics' : true};
+var format = '<div class="imgCnt" align="center"><a href="http://www.flickr.com/photos/{owner}/{id}/" target="_blank"><img src="http://farm3.static.flickr.com/{server}/{id}_{secret}.jpg?v=0" width="80" height="80" /></a><div class="imgTitle"><a href="http://www.flickr.com/photos/{owner}/{id}/">{title}</a></div></div>';
+var yqlQuery = 'select * from flickr.photos.search where text="YDN"';
var insertEl = 'widgetContainer';
yqlWidget.push(yqlQuery, config, format, insertEl);
+
+var format2 = '<br style="clear:both" />{item.description}';
+var yqlQuery2 = 'select * from weather.forecast where location = 90210';
+var insertEl2 = 'widgetContainer2';
+yqlWidget.push(yqlQuery2, config, format2, insertEl2);
yqlWidget.render();
</script>
</body>
-</html>
+</html>
View
26 js-yql-display/yql_js_widget.js 100644 → 100755
@@ -10,8 +10,8 @@
//YUI includes for GET utility
if (! window.YAHOO){
- document.write('<script type="text/javascript" src="http://yui.yahooapis.com/2.7.0/build/yahoo/yahoo-min.js" ></script>' +
- '<script type="text/javascript" src="http://yui.yahooapis.com/2.7.0/build/get/get-min.js" ></script>');
+ document.write('<script type="text/javascript" src="http://yui.yahooapis.com/2.7.0/build/yahoo/yahoo-min.js" ></script>' +
+ '<script type="text/javascript" src="http://yui.yahooapis.com/2.7.0/build/get/get-min.js" ></script>');
}
yqlWidget = function() {
@@ -35,22 +35,27 @@ yqlWidget = function() {
************************************************************/
var getYQLData = function(query){
//prepare the URL for YQL query:
- var sURL = yqlPublicQueryURL + "q=" + encodeURI(query) + "&format=json&callback=yqlWidget.getYQLDataCallback";
+ var sURL = yqlPublicQueryURL + "q=" + encodeURI(query) + "&format=json&callback=yqlWidget.getYQLDataCallback";
//add any environment files specified in the config
if (setupConfig['env']) {
sURL += "&env=" + escape(setupConfig['env']);
}
+ //disable diagnostics if not set to true
+ if (setupConfig['diagnostics'] !== true){
+ sURL += "&diagnostics=false";
+ }
+
//make GET request to YQL with provided query
- var transactionObj = YAHOO.util.Get.script(sURL, {
+ var transactionObj = YAHOO.util.Get.script(sURL, {
onSuccess : onYQLReqSuccess,
- onFailure : onYQLReqFailure,
- scope : this
- });
+ onFailure : onYQLReqFailure,
+ scope : this
+ });
return transactionObj;
- }
+ }
/************************************************************
* Method: Parse YQL Results
@@ -93,6 +98,8 @@ yqlWidget = function() {
var parseFormat = function(node){
currString = node;
+ console.log(currString);
+
//replace YQL result placeholders with return content
if (resultFormat){ currString = resultFormat.replace(regex, function(matchedSubstring, index, originalString){
return eval("currString." + index);
@@ -131,6 +138,7 @@ yqlWidget = function() {
//yql data caption success callback
getYQLDataCallback: function(o){
+ console.log(o.query);
if (! o.query){
if (setupConfig['debug'] && window.console){ console.log('YQL query returned no results'); }
return null;
@@ -138,4 +146,4 @@ yqlWidget = function() {
parseYQLResults(o.query.results);
}
}
-}();
+}();
Please sign in to comment.
Something went wrong with that request. Please try again.