Skip to content

Instantly share code, notes, and snippets.

@Jamedjo
Last active December 18, 2015 13:09
Show Gist options
  • Save Jamedjo/5787449 to your computer and use it in GitHub Desktop.
Save Jamedjo/5787449 to your computer and use it in GitHub Desktop.
LiveFyre comments system implemented as an angularjs service. Navigating to to a new page generates a new comment config from the url. Buggy WIP, livefyre appears to be polling a url which is 404 Not Found until it eventually gets created.
myapp.factory('Comments', function ($location) {
var isInitialized = false;
var comments = {};
var getConfig = function(){
var articleId = $location.path();
var defaults = {
articleId: articleId,
collectionMeta: {
articleId: articleId,
url: fyre.conv.load.makeCollectionUrl(null, [], true)
}
};
return defaults;
};
var swapConfig = function(settings_object){};
var init = function () {
isInitialized=true;
fyre.conv.load({
el: 'livefyre-comments',
network: "livefyre.com",
siteId: "123456",
signed: false
}, [getConfig()], function callback(widget) {
swapConfig = widget.changeCollection;
});
};
var swap = function(){
swapConfig(getConfig());
};
comments.run = function(){
if(isInitialized){
swap();
} else {
init();
}
}
return comments;
});
function AppController($scope, Comments) {
Comments.run();
}
@charlesbdudley
Copy link

Thanks for this!

Just in case anyone else is running into a problem like I did, I got it to work by changing getConfig to the following:

    var getConfig = function(){
        var articleId = fyre.conv.load.makeArticleId($location.absUrl());
        var defaults = {
            articleId: articleId,
            siteId: "123456",
            el: 'livefyre-comments',
            collectionMeta: {
                articleId: articleId,
                url: fyre.conv.load.makeCollectionUrl($location.absUrl(), [], true)
            }
        };
        return defaults;
    };

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment