Skip to content

Instantly share code, notes, and snippets.

@tranch
Created June 10, 2014 01:46
Show Gist options
  • Save tranch/b8bfd9959ba7870e9d0e to your computer and use it in GitHub Desktop.
Save tranch/b8bfd9959ba7870e9d0e to your computer and use it in GitHub Desktop.
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, user-scalable=no">
<title>Feed Reader</title>
<style>
body { font-size: 14px; line-height: 1.3em; }
#main { max-width: 768px; margin: auto; }
#main-container { padding: 5px; background: #C3D9FF; }
#feed-list { margin: 0; padding: 0; }
#feed-list li { background: #E8EEF7; list-style: none; border-bottom: 1px solid #CCCCCC; }
#feed-list li .item-info { padding: 5px 10px; cursor: pointer; }
.item-info .title { display: block; width: 70%; text-decoration: none; }
.item-info .title:link { color: #000000; font-weight: bolder; }
.item-info .title:visited { color: #CCCCCC; font-weight: normal; }
.item-info .pubDate { display: block; width: 25%; font-size: 0.9em; text-align: justify; color: #555555; }
#feed-list li .item-content { padding: 15px; font-size: 0.9em; background: #FFFFFF; }
.item-content img { display: inline-block; max-width: 100%; height: auto; }
.alert { margin: 5px 0; padding: 5px 10px; font-size: 0.85em; }
.alert.info { background: #FAE5B0; border: 1px solid #FAD163; }
.clearfix:before, .clearfix:after { content: " "; display: table; }
.clearfix:after { clear: both }
.clearfix { *zoom: 1 }
.pull-left { float: left }
.pull-right { float: right }
</style>
</head>
<body>
<div id="main">
<h1 id="channel-title"></h1>
<div class="loading alert" style="display:none" data-load="data:image/gif;base64,R0lGODlhEAALAPQAAP///wAAANra2tDQ0Orq6gYGBgAAAC4uLoKCgmBgYLq6uiIiIkpKSoqKimRkZL6+viYmJgQEBE5OTubm5tjY2PT09Dg4ONzc3PLy8ra2tqCgoMrKyu7u7gAAAAAAAAAAACH/C05FVFNDQVBFMi4wAwEAAAAh/hpDcmVhdGVkIHdpdGggYWpheGxvYWQuaW5mbwAh+QQJCwAAACwAAAAAEAALAAAFLSAgjmRpnqSgCuLKAq5AEIM4zDVw03ve27ifDgfkEYe04kDIDC5zrtYKRa2WQgAh+QQJCwAAACwAAAAAEAALAAAFJGBhGAVgnqhpHIeRvsDawqns0qeN5+y967tYLyicBYE7EYkYAgAh+QQJCwAAACwAAAAAEAALAAAFNiAgjothLOOIJAkiGgxjpGKiKMkbz7SN6zIawJcDwIK9W/HISxGBzdHTuBNOmcJVCyoUlk7CEAAh+QQJCwAAACwAAAAAEAALAAAFNSAgjqQIRRFUAo3jNGIkSdHqPI8Tz3V55zuaDacDyIQ+YrBH+hWPzJFzOQQaeavWi7oqnVIhACH5BAkLAAAALAAAAAAQAAsAAAUyICCOZGme1rJY5kRRk7hI0mJSVUXJtF3iOl7tltsBZsNfUegjAY3I5sgFY55KqdX1GgIAIfkECQsAAAAsAAAAABAACwAABTcgII5kaZ4kcV2EqLJipmnZhWGXaOOitm2aXQ4g7P2Ct2ER4AMul00kj5g0Al8tADY2y6C+4FIIACH5BAkLAAAALAAAAAAQAAsAAAUvICCOZGme5ERRk6iy7qpyHCVStA3gNa/7txxwlwv2isSacYUc+l4tADQGQ1mvpBAAIfkECQsAAAAsAAAAABAACwAABS8gII5kaZ7kRFGTqLLuqnIcJVK0DeA1r/u3HHCXC/aKxJpxhRz6Xi0ANAZDWa+kEAA7AAAAAAAAAAAA"></div>
<div id="main-container">
<ul id="feed-list"></ul>
</div>
</div>
<script src="http://cdn.staticfile.org/jquery/2.1.1-rc2/jquery.min.js"></script>
<script>
(function($) {
load_feed_data('http://feeds.feedburner.com/cnbbc');
})(jQuery);
function load_feed_data(url) {
var loading = $('.loading').addClass('info');
$.ajax({
url: 'https://query.yahooapis.com/v1/public/yql',
data: {
q: 'SELECT * FROM feednormalizer WHERE url = "' + url + '"',
format: 'json'
},
beforeSend: function() {
loading
.html('数据加载中 <img src="'+loading.data('load')+'" alt="loading" />')
.show();
},
success: function(response) {
if (response.query.count) {
var results = response.query.results;
if (typeof(results.error) != 'undefined') {
loading.text('内容解析出错:' + results.error);
} else {
$('#channel-title').text(results.rss.channel.title);
$.each(results.rss.channel.item, function(index, node) {
var feed_item, item_info, item_content;
feed_item = $('<li>', {
'id': btoa(node.link)
});
item_content = $('<article>', {
'class': 'item-content',
'html': node.description
})
.hide();
item_info = $('<div>', {
'class': 'item-info clearfix'
})
.append($('<a>', {
'text': node.title,
'class': 'title pull-left',
'href': '#' + btoa(node.link)
}))
.append($('<span>', {
'class': 'pubDate pull-right',
'text': new Date(Date.parse(node.pubDate)).toLocaleString()
}))
.bind('click', function(e) {
$('article').not(item_content).hide();
item_content.toggle();
});
feed_item
.append(item_info)
.append(item_content)
.appendTo($('#feed-list'));
})
loading.remove();
}
} else {
loading.text('加载内容失败,请刷新页面重试。');
}
},
error: function() {
loading.text('加载内容失败,请刷新页面重试。');
}
});
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment