1. Create empty HTML/JavaScript widget from Page Elements.
2. Find these tags in Template->Edit HTML code view:
<div class='widget-content'>3. Copy and Paste this JavaScript code between them:
</div>
<script type='text/javascript'>
/** Code taken from Sample at Code.Google.com **/
/**
* Lists blog entries from the specified JSON feed
* by creating a new 'ul' element in the DOM. Each
* bullet is the title of one blog entry, and contains
* a hyperlink to that entry's URL.
*/
function listEntries(json) {
var ul = document.createElement('ul');
for (var i = 0; i < json.feed.entry.length; i++) {
var entry = json.feed.entry[i];
var alturl;
for (var k = 0; k < entry.link.length; k++) {
if (entry.link[k].rel == 'alternate') {
alturl = entry.link[k].href;
break;
}
}
var li = document.createElement('li');
var a = document.createElement('a');
a.href = alturl;
var txt = document.createTextNode(entry.title.$t);
a.appendChild(txt);
li.appendChild(a);
ul.appendChild(li);
}
document.getElementById('data').appendChild(ul);
}
function search(query, type) {
removeOldQueryResults();
var script = document.createElement('script');
script.setAttribute('src', 'http://' + query + '/feeds/' + type +
'/default?alt=json-in-script&callback=listEntries');
script.setAttribute('type', 'text/javascript');
document.documentElement.firstChild.appendChild(script);
}
/**
* Removes results from the previous search, including
* the bullet list of blog entries and the script object
* used to obtain the feed.
*/
function removeOldQueryResults() {
// Remove the script element used to perform the query.
var script_nodes = document.getElementsByTagName('script');
for (var i = 0; i < script_nodes.length; i++) {
var cur_node = script_nodes[i];
if (cur_node.src && cur_node.src.indexOf('json') != -1) {
cur_node.parentNode.removeChild(cur_node);
}
}
// Remove the bullet list of blog entries.
var div = document.getElementById('data');
if (div.firstChild) {
div.removeChild(div.firstChild);
}
}
homeUrl = "<data:blog.homepageUrl/>";
var arr = new Array(4);
arr = homeUrl.split("/",4);
// To change from recent comments to recent posts, replace with:
// search(arr[2], "posts");
search(arr[2], "comments");
</script>
You are ready. Test it and enjoy!

0 коментара:
Post a Comment