Created
March 11, 2011 07:28
-
-
Save sunng87/865574 to your computer and use it in GitHub Desktop.
Lifestream widget on my site
This file contains hidden or 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
var YAHOO_PIPE_URL = "http://pipes.yahoo.com/pipes/pipe.run?_id=7NxhUNSA3RG_BCC6BBNMsA&_render=json"; | |
function lifeStreamCallback(stream){ | |
var lifeStreamRootDom = document.getElementById("lifestream"); | |
try{ | |
lifeStreamRootDom.removeChild(lifeStreamRootDom.getElementsByTagName("ul")[0]); | |
}catch(e) {} | |
var lifeStreamListDom = document.createElement("ul"); | |
for(var i=0; i<stream.count; i++) { | |
var item = stream.value.items[i]; | |
var itemDomElement = document.createElement("li"); | |
var titleDomElement = document.createElement("p"); | |
titleDomElement.setAttribute("class", "streamTitle"); | |
titleDomElement.innerHTML = item.title; | |
itemDomElement.appendChild(titleDomElement); | |
var descDomElement = document.createElement("p"); | |
descDomElement.setAttribute("class", "streamDesc") | |
var content = item.description.length > 100 ? item.description.substring(0, 97)+"..." : item.description; | |
content += '<a href="' + item.link + '" title="Permalink" target="_blank"><strong>\u2197</strong></a>'; | |
descDomElement.innerHTML = content; | |
itemDomElement.appendChild(descDomElement); | |
lifeStreamListDom.appendChild(itemDomElement); | |
} | |
lifeStreamRootDom.appendChild(lifeStreamListDom); | |
// remove script tag | |
var t = document.getElementById("lifeStreamScriptTag"); | |
t.parentNode.removeChild(t); | |
} | |
function loadLifeStream() { | |
var url = YAHOO_PIPE_URL + "&_callback="+"lifeStreamCallback"; | |
var scriptTag = document.createElement("script"); | |
scriptTag.setAttribute("src", url); | |
scriptTag.setAttribute("type", "text/javascript"); | |
scriptTag.setAttribute("id", "lifeStreamScriptTag"); | |
document.getElementsByTagName("head")[0].appendChild(scriptTag); | |
window.setTimeout(loadLifeStream, 5*60*1000); | |
} | |
window.onload = loadLifeStream; |
This file contains hidden or 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
#lifestream { | |
position: absolute; | |
right: 30px; | |
top: 30px; | |
width:400px; | |
} | |
#lifestream h2 { | |
font-size: 16px; | |
margin:0; | |
padding:0; | |
margin-bottom:10px; | |
} | |
#lifestream p { | |
color:#999; | |
font-size:11px; | |
} | |
#lifestream ul { | |
list-style: none; | |
margin:0; | |
padding:0; | |
} | |
#lifestream ul li { | |
font-size: 12px; | |
-moz-border-radius:5px; | |
-webkit-border-radius:5px; | |
background-color: #EEE; | |
padding:5px; | |
margin:5px; | |
} | |
#lifestream ul li:hover { | |
background-color: #FEFEFE; | |
} | |
#lifestream ul li p.streamTitle { | |
text-shadow: 0 1px 0 #FFF; | |
color: #333; | |
font-weight: bold; | |
margin:0; | |
padding:0; | |
margin-bottom:5px; | |
} | |
#lifestream ul li p.streamDesc { | |
color:#66; | |
margin:0; | |
padding:0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment