Javascript API (ReST) - pwanglive/mustached-octo-adventure GitHub Wiki

Index

A Livefyre Collection can be displayed using LiveComments by calling the fyre.conv.load(...) method.

fyre.conv.load(globalInfo, [appInfo], function(widget) {
    // Fired on load
});

You can register your own delegate objects to perform actions other than the Livefyre default. These delegate objects should be passed to fyre.conv.load when instantiating Livefyre.

This delegate will be used to share pieces of content (e.g. when a user clicks 'share' on an item). When a user shares, this function will be called and passed a data Object with the following properties:

  • url: A URL for the Content that was shared

Example:

var appInfo = {...}; // Should have siteId, articleId, etc.
appInfo.shareDelegate = function (data) {
    // Do something with data.url
};

fyre.conv.load(globalInfo, [appInfo], function(app) {});

Add more action buttons next to the existing actions buttons on a piece of content (such as "Share", "Flag", etc). Simply define a key for the text that is desired to be displayed and a callback that will be invoked on a click event. The callback will be invoked with an object with two keys: "authorId" and "contentId".

Example:

var appInfo = {...}; // Should have siteId, articleId, etc.
appInfo.actionButtons = [
    {
        key: 'Do Something',
        callback: function(commentInfo) {
            console.log('Author of content is ' + commentInfo.authorId);
            console.log('id of content is ' + commentInfo.contentId);
        }
    },
    ...
];

fyre.conv.load(globalInfo, [appInfo], function(app) {});

After calling fyre.conv.load, a variable is passed to your onLoad callback that represents the widget (widget in the above example). This can be used to add callbacks to widget events or change the collection rendered in the widget.

Change the Collection being displayed in an already-loaded LiveComments Stream. This is useful for photo galleries or other applications where the displayed collection should change after page load.

<script type="text/javascript">
window.lf_config1 = {"collectionMeta": <COLLECTION META 1>,
		     "checksum": <CHECKSUM 1>,
		     "siteId": <SITE ID>,
		     "articleId":"1",
		     "el":"livefyre"};
window.lf_config2 = {"collectionMeta": <COLLECTION META 2>,
		     "checksum": <CHECKSUM 2>,
		     "siteId": <SITE ID>,
		     "articleId":"2",
		     "el":"livefyre"};
window.lf_config3 = {"collectionMeta": <COLLECTION META 3>,
		     "checksum": <CHECKSUM 3>,
		     "siteId": <SITE ID>,
		     "articleId":"3",
		     "el":"livefyre"};

function onLoadFunc (widget) {
    window.changeConv = widget.changeCollection;
};
</script>

<button onclick="window.changeConv(window.lf_config1);">Conv 1</button>
<button onclick="window.changeConv(window.lf_config2);">Conv 2</button>
<button onclick="window.changeConv(window.lf_config3);">Conv 3</button>

<div id="livefyre"></div>
<script type="text/javascript">
var conv = fyre.conv.load({"network": <NETWORK>, "authDelegate": <AUTH DELEGATES>}, [window.lf_config1], onLoadFunc);
</script>

Stop making streaming and live listener count requests to Livefyre.

widget.stop();

Remove the stream from the page entirely, and stop any active streams. After calling .remove(), all method calls on the widget object will have no effect.

widget.remove();

Lots of things happen once a Livefyre Stream is embedded on your web page. Users can like Content, post new Content, and share Content to Twitter and Facebook. Sometimes it is useful to be notified when these events occur, either to update the rest of your webpage or to count the events in an analytics product. Livefyre's JavaScript Events make this possible.

Event handlers can be bound to Livefyre Streams in the code that instantiates the Stream on your webpage. The code looks like this, with an actual event name substituted for {eventName}:

fyre.conv.load({}, [conversationInfo], function(widget) {
    widget.on('{eventName}', function (data) {
        // Do something, perhaps using data
    });
});

Note: data objects are provided for all event handlers. Example data objects follow each Event.

initialRenderComplete

The comment stream has loaded, and the initial set of content has been fetched from the server and displayed to the user.

data is undefined.

commentPosted

A user posted a comment.

data = {
  authorId: "[email protected]" // The ID of the Author of the comment 
  parent: "893549" // The ID of the comment that this new comment is in reply to, else null
  bodyHtml: "<p>42</>" //The HTML of the submitted Content
  sharedToFacebook: true // Whether the comment was also posted to Facebook
  sharedToTwitter: false // Whether the comment was also posted to Twitter
}
  • A parent of null is a new comment.
  • A parent of None is a comment that has been edited.
  • A number for parent is the parent id of reply.

commentFlagged

A user flagged a comment.

data = {
  targetId: "789347" // The ID of the comment that was flagged
  type: ["disagree"] // The type of flag
  notes: ["I don't entirely agree with this post"] // A note/reason for the flag
}

commentLiked

A user liked a comment.

data = {
  targetId: "245625" // The ID of the comment that was liked
  targetAuthorId: "[email protected]" // The ID of the author of the comment that was liked
}

commentShared

A user shared a comment.

data = {
  targetId: "256255" // The ID of the comment that was shared
  sharedToFacebook: false // Whether the comment was shared to Facebook
  sharedToTwitter: true // Whether the comment was shared to Twitter
}

commentCountUpdated

The total number of visible comments in this conversation has changed (either incremented or decremented).

data: 34 // The total number of visible comments in the conversation (integer).

userLoggedIn

A user has logged in.

data = {
  avatar: "http://gravatar.com/avatar/50.jpg" // link to logged in user's avatar image
  displayName: "NewUser" // display name of the logged in user
  id: "[email protected]" // ID of the logged in user
  isModerator: false // boolean indicating whether logged in user is a moderator
}

userLoggedOut

A user has logged out.

socialMention

A user sent a social mention through a comment; returns an array of the following:

data = {
  id: '[email protected]' // ID of the mentioned user
  displayName: 'testUser' // Display name of mentioned user
  message: "@testUser Wow, I can't believe it either!" // Message that was sent to the particular user
  provider``: 'twitter' // Provider to which the mention was shared
}

commentFeatured

A moderator user featured a comment; returns an array of the following:

data = {
  targetId: "134234" // The ID of the comment that was featured
  targetAuthorId: "[email protected]" // The ID of the author of the comment that was featured
}
⚠️ **GitHub.com Fallback** ⚠️