Skip to content

Instantly share code, notes, and snippets.

@mpchadwick
Created February 18, 2014 18:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mpchadwick/9076670 to your computer and use it in GitHub Desktop.
Save mpchadwick/9076670 to your computer and use it in GitHub Desktop.
Feedmagnet API
<!-- simple CSS styling for sidebar and updates -->
<style>
.fm-update { margin-bottom: 20px; border-bottom: 1px #ddd; }
.avatar { float: left; margin-right: 10px; height: 48px; width: 48px; }
.author { font-size: 1.2em; padding-top: 5px; }
.timestamp { font-size: .8em; color: #777; }
.text { margin-top: 20px 0; }
.social-feed {
width: 33%;
float: left;
}
.clear-both {
clear: both;
}
</style>
<!-- this is the div we'll be replacing with social content -->
<div id="social-feed-1" class="social-feed"></div>
<div id="social-feed-2" class="social-feed"></div>
<div id="social-feed-3" class="social-feed"></div>
<div class="clear-both"></div>
<script>
// load FeedMagnet SDK
var fm_server = 'testdrive.feedmagnet.com'
;(function() {
window.fm_ready = function(fx) {
if (typeof $FM!=='undefined' && typeof $FM.ready==='function') {
$FM.ready(fx);
} else {
window.setTimeout(function() { fm_ready.call(null, fx); }, 50);
}
};
var fmjs = document.createElement('script');
var p = ('https:'===document.location.protocol?'https://':'http://');
fmjs.src = p + fm_server + '/embed.js';
fmjs.setAttribute('async', 'true');
document.documentElement.children[0].appendChild(fmjs);
})();
// do stuff once it is loaded
fm_ready(function($, _) {
// create the feed object and get content
var feed = $FM.Feed('demostuff').get()
var updateIndex = 1;
// process JSON data for each update into HTML
feed.connect('new_update', function(self, data) {
var udata = data.update.data
data.update.html =
'<img class="avatar" ' +
'src="' + udata.author.avatar + '" />' +
'<div class="author">' + udata.author.alias + '</div>' +
'<div class="timestamp">' +
_(udata.timestamp).pretty_time() +
'</div>' +
'<div class="text">' + udata.text + '</div>';
var el = '#social-feed-' + updateIndex;
console.log(el);
$FM.Element(el).add(data.update)
updateIndex = (updateIndex == 3) ? 1 : updateIndex + 1;
})
// display the feed on the page
// $FM.Element('#social-feed').display(feed)
})
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment