Skip to content

Instantly share code, notes, and snippets.

@HendrikRoth
Last active August 29, 2015 14:22
Show Gist options
  • Save HendrikRoth/1b3815f156cfb64cde7e to your computer and use it in GitHub Desktop.
Save HendrikRoth/1b3815f156cfb64cde7e to your computer and use it in GitHub Desktop.
var test = {};
test.getnews = function(exa) {
return m.request({
method: 'GET',
dataType: "jsonp",
url: "http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&num=50&q=" + exa,
unwrapSuccess: function(response) {
return response.responseData.feed.entries;
},
unwrapError: function(response) {
return response.error;
}
})
};
var nSource = [{
title: "CNN ",
url: 'http://rss.cnn.com/rss/cnn_topstories.rss'
}, {
title: "Reuters World News ",
url: 'http://feeds.reuters.com/Reuters/worldNews'
}]
test.controller = function() {
var ctrl = this;
ctrl.selectedId = m.prop('http://www.bloombergview.com/rss')
ctrl.source = nSource;
ctrl.feeds = test.getnews(ctrl.selectedId())
};
test.view = function(ctrl) {
return [m('select', {
onchange: m.withAttr('value', ctrl.selectedId)
}, [
ctrl.source.map(function(data) {
return m('option', {
value: data.url
}, data.title)
})
]),
m('.list-group', [
ctrl.feeds().map(function(feed) {
return m('a.list-group-item', {
href: feed.link,
target: '_newtab'
}, [
m('h4.list-group-item-heading', feed.title),
m('p.list-group-item-text.text-left', feed.contentSnippet),
m('span.small', feed.publishedDate)
]);
})
])
]
}
m.mount(document.body, test)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment