<html>
<head>
<script>
window.log = function(){
log.history = log.history || []; // store logs to an array for reference
log.history.push(arguments);
if(this.console){
console.log( Array.prototype.slice.call(arguments) );
}
};
$ = function(sel, ctx){return (ctx || document).querySelector(sel)}
$$ = function(sel, ctx){return (ctx || document).querySelectorAll(sel)}
</script>
<meta name="description" content="mithriljs: rss feed reader">
<meta charset="utf-8">
<title>Mithril Feed Reader</title>
<script src="//cdnjs.cloudflare.com/ajax/libs/mithril/0.2.0/mithril.min.js"></script>
</head>
<body>
</body>
</html>
rss = {}
rss.newsSources = [{
title: "CNN ",
url: 'http://rss.cnn.com/rss/cnn_topstories.rss'
}, {
title: "Reuters World News ",
url: 'http://feeds.reuters.com/Reuters/worldNews'
}, {
title: "Bloomberg ",
url: 'http://www.bloombergview.com/rss'
}]
rss.getFeed = function(exa) {
return m.request({
method: 'GET',
dataType: "jsonp",
url: "http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&num=3&q=" + exa,
unwrapSuccess: function(response) {
return response.responseData.feed.entries;
},
unwrapError: function(response) {
return response.error;
}
})
}
rss.vm = (function(){
vm = {}
vm.init = function(){
vm.sources = rss.newsSources
vm.selectedSource = m.prop("")
vm.feed = m.prop([])
vm.getNews = function(selection){
rss.getFeed(selection).then(function(response){
vm.feed(response)
})
}
}
return vm
})()
rss.controller = function() {
rss.vm.init()
rss.vm.getNews(rss.vm.sources[0].url)
};
rss.view = function(ctrl) {
//console.log('rss.vm', rss.vm);
return [m('select', {
onchange: m.withAttr('value', rss.vm.getNews)
}, [
rss.vm.sources.map(function(source) {
return m('option', {
value: source.url
}, source.title)
})
]),
m('.list-group', [
rss.vm.feed().map(function(article) {
return m('a.list-group-item', {
href: article.link,
target: '_newtab'
}, [
m('h4.list-group-item-heading', article.title),
m('p.list-group-item-text.text-left', article.contentSnippet),
m('span.small', article.publishedDate)
]);
})
])
]
}
m.mount(document.body, rss)
Output
300px
You can jump to the latest bin by adding /latest
to your URL
Keyboard Shortcuts
Shortcut | Action |
---|---|
ctrl + [num] | Toggle nth panel |
ctrl + 0 | Close focused panel |
ctrl + enter | Re-render output. If console visible: run JS in console |
Ctrl + l | Clear the console |
ctrl + / | Toggle comment on selected lines |
ctrl + ] | Indents selected lines |
ctrl + [ | Unindents selected lines |
tab | Code complete & Emmet expand |
ctrl + shift + L | Beautify code in active panel |
ctrl + s | Save & lock current Bin from further changes |
ctrl + shift + s | Open the share options |
ctrl + y | Archive Bin |
Complete list of JS Bin shortcuts |
JS Bin URLs
URL | Action |
---|---|
/ | Show the full rendered output. This content will update in real time as it's updated from the /edit url. |
/edit | Edit the current bin |
/watch | Follow a Code Casting session |
/embed | Create an embeddable version of the bin |
/latest | Load the very latest bin (/latest goes in place of the revision) |
/[username]/last | View the last edited bin for this user |
/[username]/last/edit | Edit the last edited bin for this user |
/[username]/last/watch | Follow the Code Casting session for the latest bin for this user |
/quiet | Remove analytics and edit button from rendered output |
.js | Load only the JavaScript for a bin |
.css | Load only the CSS for a bin |
Except for username prefixed urls, the url may start with http://jsbin.com/abc and the url fragments can be added to the url to view it differently. |