📢 The commenting platform for ft.com, the app, interactive graphics & alphaville is currently being replaced. Please speak to the Comments team if you intend to start using this component or which to make any changes to it.
JavaScript module which incorporates common UI elements of the FT commenting system like dialogs, forms, common parts of a commenting widget with DOM manipulation and a unified way to load it.
Widget is responsible to coordinate getting initialization data, initializing the Ui. While this class implements some of the basic functionality (handling errors, loading timeout), it should be extended by providing an implementation for getting the initialization data.
new oCommentUi.Widget(config);
To create an instance, you need to provide a configuration object. This should have the following structure:
- articleId: ID of the article, any string
- url: canonical URL of the page
- title: Title of the page
- timeout: Period of time after a timeout is triggered. Default is 15000 ms (15 sec). Its value should be given in milliseconds (ms).
new oCommentUi.Widget(el, {
articleId: 'e113c91c-10d9-11e4-812b-00144feabdc0',
url: 'http://www.ft.com/cms/s/0/e113c91c-10d9-11e4-812b-00144feabdc0.html',
title: 'Rolls-Royce seeks to catch-up with rivals on margins - FT.com'
});
This method will initiate the process of loading the initialization data that are needed to render the widget and the rendering of the UI. This method uses hook methods which are not implemented in this module, but should be implemented in the module that extends it.
init
will handle errors of the process of loading the widget, also timeout if an error is not available.
This method can be called once on an instance (calling it multiple types will have no effect).
This method is responsible for gathering data that is needed to initialize the widget (e.g. metadata, site ID, comments, etc.).
This method is responsible for rendering the UI of the widget on the page. Render is called when the initialization process is done. This method is called using the data gathered during the init process:
this.render(initData);
This method is responsible to handle any error that appears during the initialization.
this.onError(errorObject);
The default implementation clears out the container of the widget and shows the unavailable message template (available using the template object).
This method is responsible to handle the case when within a given time the loading isn't finished and no error appeared.
The default implementation clears out the container of the widget and shows the unavailable message template (available using the template object).
Extending of the Widget
can be done in the following way:
var WidgetExtend = function () {
oCommentUi.Widget.apply(this, arguments);
}
oCommentUi.Widget.__extend(WidgetExtend, {eventNamespace}, {classNamespace});
Example from o-comments
:
var Widget = function () {
oCommentUi.Widget.apply(this, arguments);
}
oCommentUi.Widget.__extend(Widget, 'oComments', 'o-comments');
This class is responsible to handle the UI part of a commenting widget. An instance of this is created within an instance of the Widget
.
While this implementation has predefined methods, it can be extended with particular UI methods.
new oCommentUi.WidgetUi(widgetContainer);
Where widgetContainer
should be a DOM element in which the widget is loaded.
Scrolls the page to the widget. A callback function is called when the scroll finished (optional).
Inserts message when comments is not available, either because of the web services or Livefyre.
Clears the container's content.
Extending of Widget can be done in the following way:
var WidgetUiExtend = function () {
oCommentUi.WidgetUi.apply(this, arguments);
}
oCommentUi.WidgetUi.extend(WidgetUiExtend);
Generic Ui functionality which is common across all istances of the comments. These are mostly dialogs which show on the page and are unrelated to the Widget's container or widget instance.
The features are available on the following object:
oCommentUi.userDialogs
Shows a dialog for setting the initial pseudonym (shown when the user doesn't have a pseudonym set).
oCommentUi.userDialogs.showSetPseudonymDialog({
submit: function (formData, callback) {
// called when the form is submitted
},
close: function () {
// called when the dialog is closed by a user action
}
});
Settings dialog where the user can change its pseudonym or email preferences.
oCommentUi.userDialogs.showSettingsDialog({
displayName: 'currentPseudonym',
settings: {
emaillikes: 'never'
}
},
{
submit: function (formData, callback) {
// called when the form is submitted
},
close: function () {
// called when the dialog is closed by a user action
}
});
Shows a dialog which reminds the user to save its email preferences if he/she didn't do so.
commentUi.userDialogs.showEmailAlertDialog({
submit: function (formData, callback) {
// called when the form is submitted
},
close: function () {
// called when the dialog is closed by a user action
}
});
Shows a dialog with a sign in link to re-login after a session expire.
commentUi.userDialogs.showInactivityMessage({
submit: function (formData, callback) {
// called when the form is submitted
},
close: function () {
// called when the dialog is closed by a user action
}
});
All functions of userDialogs
has the same callback parameter structure, which should be an object with the following fields:
Required. Function that is called when the form is submitted. As parameters the form data is provided (serialized into an object of key-value pairs), and a callback which should be called with either an error message (if an error occurred) or without parameters if submission is successful. Example:
callbacks.submit({
formKey: 'formValue'
}, function (err) {
if (err) {
// show the error message, leave the dialog open
return;
}
// success, close the dialog
}
});
Optional. Function that is called when the dialog is closed.
This contains common Mustache templates which are compiled and can be rendered with custom data.
The templates are available on the following object:
oCommentUi.templates
Templates that are available:
Message that appears when an error occured or loading the widget takes longer than the timeout period. It has a default style added.
Parameters:
- message: message to show. By default i18n.unavailable is used to render within the WidgetUi.
Terms and guidelines message with default style. Requires no parameters to render.
Link that is used for changing user settings.
Parameters:
- label: Label of the link. i18n.commentingSettings can be used for it.
Clearfix. Separates rows horizontally that have float.
These templates can be overriden on a global level.
Internationalization is responsible to provide common messages/texts that are used within the commenting application.
The strings are available on the following object:
oCommentUi.i18n
It exposes the following:
Contains generic messages:
- unavailable: Message that is shown when the widget is unavailable
- changePseudonymError: Generic error when changing the pseudonym fails and no error message is coming from the server.
- genericError: Generic error message.
- commetingSettings: label of the commenting settings link "Commenting settings".
Some error messages that come from the web services are not very user friendly. These messages are mapped to more user friendly versions that can be shown to the user.
Logging can be enabled for debugging purposes. It logs using the global 'console' if available (if not, nothing happens and it degrades gracefully). By default logging is disabled.
This method enables logging of the module.
This method disables logging of the module.
This method sets the logging level. This could be a number from 0 to 4 (where 0 is debug, 4 is error), or a string from the available methods of 'console' (debug, log, info, warn, error). Default is 3 (warn).
There is a default font-family set for o-comment-ui: MetricWeb, serif
Please note that the font itself is not loaded by this module, this should be done by the product.
In order to override the default font, set a value for the following variable:
$o-comment-ui-font-family: font1, font2;
In order to suppress downloading the web fonts set the following variable
$o-comment-ui-include-fonts: false;
Works in accordance with our support policy
Only the enhanced experience offers any kind of commenting functionality. Core functionality will be added in due course.