Created
November 16, 2010 07:22
-
-
Save yyr446/701552 to your computer and use it in GitHub Desktop.
Google Blogger API Sample
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="ja"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Google Blogger API Sample</title> | |
<style type="text/css"></style> | |
<script type="text/javascript" src="http://www.google.com/jsapi"></script> | |
<script type="text/javascript">google.load("gdata","1.x");</script> | |
<script type="text/javascript"> | |
google.setOnLoadCallback(function(){ | |
var bloggerService = new google.gdata.blogger.BloggerService('GoogleInc-jsguide-1.0'); | |
var feedUri = 'http://xxxx.blogspot.com/feeds/posts/default'; | |
var handleBlogFeed = function(blogFeedRoot) { | |
var blogEntries = blogFeedRoot.feed.getEntries(); | |
if(!blogEntries.length){ | |
alert("記事が1件もありません"); | |
return; | |
}else | |
my_output = new feedout(blogEntries); | |
my_output.list(document.getElementById("my_blog_list"), | |
5, | |
{hizuke:true,jikan:true}, | |
"_blank" | |
); | |
my_output.scroll(document.getElementById("my_blog_info"), | |
5, | |
{hizuke:true,jikan:true}, | |
"_blank", | |
20000, | |
100 | |
); | |
}; | |
var handleError = function(error) { | |
alert(error); | |
}; | |
bloggerService.getBlogFeed(feedUri,handleBlogFeed,handleError); | |
}); | |
function feedout(blogEntries){ | |
this.entry = blogEntries; | |
} | |
feedout.prototype.list = function(cotainer,No,format,lnk_target){ | |
this.cotainer = cotainer; | |
this.idx = No?Math.min(this.entry.length,No):Math.min(this.entry.length,5); | |
this.format = format; | |
this.lnk_target = lnk_target; | |
var a,dataobj,hizuke,jikan,str,li; | |
for(var i=0;i<this.idx;i++){ | |
a = document.createElement("a"); | |
a.href = this.entry[0].getHtmlLink().getHref(); | |
a.target = this.lnk_target; | |
a.appendChild(document.createTextNode(this.entry[i].getTitle().getText())); | |
dateobj = this.entry[i].getUpdated().getValue().date; | |
hizuke = dateobj.getFullYear() + "年" | |
+ (dateobj.getMonth() + 1) + "月" | |
+ dateobj.getDate() + "日" + " "; | |
jikan = ((dateobj.getHours() < 10)?"0"+dateobj.getHours():dateobj.getHours()) | |
+ ":" | |
+ ((dateobj.getMinutes() < 10)?"0"+dateobj.getMinutes():dateobj.getMinutes()) | |
+ " "; | |
str = (this.format.hizuke?hizuke:"") + (this.format.jikan?jikan:""); | |
var li = document.createElement("li"); | |
li.appendChild(document.createTextNode(str)); | |
li.appendChild(a); | |
this.cotainer.appendChild(li); | |
} | |
} | |
feedout.prototype.scroll = function(cotainer,No,format,lnk_target,rot_int,scr_int){ | |
this.cotainer = cotainer; | |
this.idx = No?Math.min(this.entry.length,No):Math.min(this.entry.length,5); | |
this.format = format; | |
this.lnk_target = lnk_target; | |
this.rot_int = rot_int; | |
this.rot_count = 0; | |
this.rot_timer = null; | |
this.scr_int = scr_int; | |
this.scr_count = 0; | |
this.scroll_timer = null; | |
this.data = []; | |
this.width = this.cotainer.clientWidth; | |
var a,dataobj,hizuke,jikan,str,span; | |
for(var i=0;i<this.idx;i++){ | |
a = document.createElement("a"); | |
a.href = this.entry[0].getHtmlLink().getHref(); | |
a.target = this.lnk_target; | |
a.appendChild(document.createTextNode(this.entry[i].getTitle().getText())); | |
dateobj = this.entry[i].getUpdated().getValue().date; | |
hizuke = dateobj.getFullYear() + "年" | |
+ (dateobj.getMonth() + 1) + "月" | |
+ dateobj.getDate() + "日" + " "; | |
jikan = ((dateobj.getHours() < 10)?"0"+dateobj.getHours():dateobj.getHours()) | |
+ ":" | |
+ ((dateobj.getMinutes() < 10)?"0"+dateobj.getMinutes():dateobj.getMinutes()) | |
+ " "; | |
str = (this.format.hizuke?hizuke:"") + (this.format.jikan?jikan:""); | |
span = document.createElement("span"); | |
span.appendChild(document.createTextNode(str)); | |
span.appendChild(a); | |
span.style.position = 'absolute'; | |
span.style.left = this.width + 'px'; | |
this.data[i] = span; | |
} | |
this.cotainer.appendChild(this.data[this.rot_count]); | |
this.scrolling(); | |
this.rot_timer = setInterval((function(that){ | |
return function(){ | |
while(that.cotainer.hasChildNodes()) | |
that.cotainer.removeChild(that.cotainer.firstChild); | |
that.rot_count += 1; | |
if(that.rot_count > that.idx - 1) that.rot_count = 0; | |
that.cotainer.appendChild(that.data[that.rot_count]); | |
that.scr_count = 0; | |
that.scrolling(); | |
} | |
})(this),this.rot_int); | |
} | |
feedout.prototype.scrolling = function(){ | |
this.scroll_timer = setInterval((function(that){ | |
return function(){ | |
that.scr_count += 10; | |
var pos = that.width - that.scr_count; | |
if (pos < 0){ | |
pos = 0; | |
clearInterval(that.scroll_timer); | |
that.scroll_timer = null; | |
} | |
that.data[that.rot_count].style.left = pos + "px"; | |
} | |
})(this),this.scr_int); | |
} | |
</script> | |
</head> | |
<body> | |
<h1>Google Blogger API Sample</h1> | |
<ul id="my_blog_list" style="margin:0px;padding:0px;list-style:none;"></ul> | |
<div id="my_blog_info" style="position:relative;width:30em;height:1em;overflow:hidden;border:1px solid gray"> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment