Last active
December 18, 2015 13:09
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} |
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
The init/load function takes the form
fyre.conv.load({permenentOptions},[{swapOptions}], callbackFunction);
url: fyre.conv.load.makeCollectionUrl(null, [], true)
tells livefyre to use window.location, without keeping any params, but taking the#hash
into account.getConfig
uses location to build config params which are then used in thewidget.changeCollection
swap function.