Last active
August 29, 2015 13:57
-
-
Save paulusm/9505975 to your computer and use it in GitHub Desktop.
Twitter widget + external feed
This file contains 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
<!doctype html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Widget Demos</title> | |
<style> | |
.twitter-timeline{float:left;} | |
#feed{float:left;margin-left:20px;width:45%;} | |
li, h2{font-family:helvetica;} | |
</style> | |
</head> | |
<body> | |
<a class="twitter-timeline" href="https://twitter.com/search?q=webwewant" data-widget-id="443669187341193217">Tweets about "webwewant"</a> | |
<script>!function(d,s,id) | |
{var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https'; | |
if(!d.getElementById(id)){ | |
js=d.createElement(s); | |
js.id=id; | |
js.src=p+"://platform.twitter.com/widgets.js"; | |
fjs.parentNode.insertBefore(js,fjs);} | |
}(document,"script","twitter-wjs"); | |
</script> | |
<script> | |
var feed = "http://info.uwe.ac.uk/news/xml/uwenewsrss.xml"; | |
var api = "http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&callback=displayFeed&output=json&q=" + encodeURIComponent(feed); | |
//This creates a script element to make a "jsonp" request each time the page is requested | |
var script = document.createElement('script'); | |
script.src = api; | |
document.getElementsByTagName('head')[0].appendChild(script); | |
//use the data that comes back to put into the HTML div | |
var displayFeed = function(data){ | |
// loop through the feed items | |
if(data.responseData.feed.entries){ | |
for(var i=0; i< data.responseData.feed.entries.length; i++){ | |
//create new HTML elements to hold the items | |
var hl = document.createElement("li"); | |
var lnk = document.createElement("a"); | |
var blurb = document.createElement("p"); | |
// make a link and add it to the list item | |
lnk.href = data.responseData.feed.entries[i].link; | |
lnk.innerText = data.responseData.feed.entries[i].title; | |
lnk.text = data.responseData.feed.entries[i].title; | |
hl.appendChild(lnk); | |
// Also add the content snippet | |
blurb.textContent= data.responseData.feed.entries[i].contentSnippet; | |
blurb.innerText= data.responseData.feed.entries[i].contentSnippet; | |
console.log(blurb); | |
hl.appendChild(blurb); | |
//Add the whole item to the list | |
document.getElementById("hls").appendChild(hl); | |
} | |
} | |
} | |
</script> | |
<div id="feed"> | |
<h2>Headlines</h2> | |
<ul id="hls"></ul> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment