10.3.8 • Published 3 months ago

@financial-times/o-comments v10.3.8

Weekly downloads
635
License
MIT
Repository
-
Last release
3 months ago

o-comments MIT licensed

A component, integrated with FT authentication and Coral Talk, to add a comment stream or comment count to content.

Usage

Check out how to include Origami components in your project to get started with o-comments.

Unlike other Origami components o-comments requires additional peer dependencies.

Additional dependencies

o-comments is dependant on sass from o-overlay and o-forms and requires them to be included by the parent application.

Markup

These elements will be initialized automatically on the o.DOMContentReady event meaning you're unable to defer component initialisation.

Stream

Use the following markup to enable a comment stream:

<div class="o-comments"
	id="{element-id}"
	data-o-component="o-comments"
	data-o-comments-article-id="{article-id}"
	data-o-comments-article-url="{optional-article-url}">
</div>

Coral needs a parent element id when initialising the comment stream embed script.

Count

Add the following attribute to the markup to enable a comment count:

<div class="o-comments"
-	id="{element-id}"
	data-o-component="o-comments"
	data-o-comments-article-id="{article-id}"
+	data-o-comments-count="true">
</div>

The comment count is rendered when the data-o-comments-count attribute value is true.

getCount

If you need the count as a value, use the getCount method which returns an integer.

Comments.getCount('article-id')
	.then(count => console.log(count));

Use staging environment

Add the following attribute to the markup to use Coral staging environment:

For stream:

<div class="o-comments"
	id="o-comments-stream"
	data-o-component="o-comments"
	data-o-comments-article-id="{article-id}"
	data-o-comments-article-url="{optional-article-url}"
+	data-o-comments-use-staging-environment="true">
</div>

For count:

<div class="o-comments"
	data-o-component="o-comments"
	data-o-comments-article-id="{article-id}"
	data-o-comments-count="true"
+	data-o-comments-use-staging-environment="true">
</div>

Pass a display name into Coral Talk

In rare cases, a user may have already set their display name in a different part of the website. In this instance, add the following attribute to pass the display name into Coral Talk when creating a user account:

<div class="o-comments"
	id="o-comments-stream"
	data-o-component="o-comments"
	data-o-comments-article-id="{article-id}"
	data-o-comments-article-url="{optional-article-url}"
+	data-o-comments-display-name="{display-name}">
</div>

JavaScript

No code will run automatically unless you are using the Build Service. You must either construct an o-comments object or fire the o.DOMContentLoaded event, which o-comments listens for.

Constructing an o-comments

Assuming you have an HTML element on the page to represent your comment stream or count:

import oComments from '@financial-times/o-comments';
const commentsElement = document.querySelector('#element');
const Comments = new oComments(commentsElement, {
	articleId: 'article-id',
	articleUrl: 'optional-article-url'
})

Add useStagingEnvironment: true to the options if you want to use Coral staging environment.

If you want to initialise every comment stream or count element on the page (based on the presence of the attribute: data-o-component="o-comments"):

import oComments from '@financial-times/o-comments';
oComments.init();

Firing an oDomContentLoaded event

import '@financial-times/o-comments';

document.addEventListener('DOMContentLoaded', function() {
	document.dispatchEvent(new CustomEvent('o.DOMContentLoaded'));
});

Events

Events are emitted during key events or interactions and can be listened to by listening for events on the document.

document.addEventListener('oComments.ready', (event) => {
	console.log('This comments have rendered');
});

Global / Component

These events are anything to do with the component itself.

  • oComments.ready - Emitted when the component has finished rendering and is ready for the user to interact with comments

Comment

These events are anything to do with comment interactions.

  • oComments.postComment - Emitted when a users has successfully left a comment
  • oComments.replyComment - Emitted when a user has successfully left a comment which is a reply to an existing comment
  • oComments.editComment - Emitted when a user has successfully edited their existing comment
  • oComments.likeComment - Emitted when a users has liked a comment
  • oComments.reportComment - Emitted when a user reports a comment to the moderators
  • oComments.ignoreUser - Emmitted when a user ignores another user
  • oComments.toxicComment - Emitted when a user attempted to leave a comment that was flagged as toxic by the auto moderation

Tracking

To keep tracking consistent across applications o-comments will emit o-tracking events for all of the events. If your application is already using o-tracking then then there is no need to do anything to track common events.

Disable tracking

If you want to disable the o-tracking events and manage tracking / analytics yourself this can be done by passing the disableOTracking option to the o-comments instance.

Imperatively

import oComments from '@financial-times/o-comments';
const commentsElement = document.querySelector('#element');
const comments = new Comments(commentsElement, {
	disableOTracking: true
});

Declaratively

<div class="o-comments"
	id="o-comments-stream"
	data-o-component="o-comments"
	data-o-comments-article-id="{article-id}"
	data-o-comments-article-url="{optional-article-url}"
+	data-o-comments-disable-o-tracking="true">
</div>

Sass

Include all styles for o-comments with the mixin oComments. Set the coral-talk-iframe option to false:

@include oComments($opts: ('coral-talk-iframe': false));

The coral-talk-iframe option is set to false as these styles are included in the Coral Talk iframe, via the Origami Build Service, and do not need to be included directly within projects themselves.

Styling of Coral Talk iframe

This component contains a sass file (/src/scss/coral-talk-iframe/main.scss) that provides custom styling for Coral Talk components inside their own iframe. That file is included in the Coral Talk admin panel by including o-comments using an Origami Build Service request.

Migration

StateMajor VersionLast Minor ReleaseMigration guide
✨ active9N/Amigrate to v9
⚠ maintained8N/Amigrate to v8
╳ deprecated77.7migrate to v7
╳ deprecated6N/Amigrate to v6
╳ deprecated55.0.1migrate to v5
╳ deprecated44.2.0-
╳ deprecated33.5.0-
╳ deprecated22.5.0-
╳ deprecated11.0.10-

Contact

If you have any questions or comments about this component, or need help using it, please either raise an issue, visit #origami-support or email Origami Support.

Licence

This software is published by the Financial Times under the MIT licence.

10.3.6

3 months ago

10.3.7

3 months ago

10.3.8

3 months ago

10.3.5

3 months ago

10.3.2

9 months ago

10.3.3

9 months ago

10.3.4

7 months ago

10.3.1

11 months ago

10.3.0

11 months ago

10.2.3

1 year ago

10.2.1

1 year ago

10.2.2

1 year ago

10.2.0

1 year ago

10.1.0

1 year ago

10.0.0

1 year ago

10.0.1

1 year ago

10.0.2

1 year ago

9.0.2

1 year ago

9.0.1

2 years ago

9.0.0

2 years ago

8.3.3

2 years ago

8.3.2

2 years ago

8.3.1

2 years ago

8.2.0

3 years ago

8.3.0

2 years ago

8.1.2

3 years ago

8.1.1

3 years ago

8.1.0

3 years ago

7.7.6

3 years ago

7.7.5

3 years ago

8.0.1

3 years ago

8.0.0

3 years ago

8.0.0-beta.0

3 years ago

7.7.4

3 years ago

7.7.3

4 years ago

7.7.2

4 years ago

7.7.1

4 years ago

7.7.0

4 years ago

7.6.7

4 years ago

7.6.6

4 years ago

7.6.5

4 years ago

7.6.4

4 years ago

7.6.3

4 years ago

7.6.2

4 years ago

7.6.1

4 years ago

7.6.0

4 years ago

7.5.4

4 years ago

7.5.3

4 years ago

7.5.2

4 years ago

7.5.0

4 years ago

7.4.2

4 years ago

7.4.1

4 years ago

7.4.0

4 years ago

7.3.0

4 years ago

7.2.1

4 years ago

7.2.0

4 years ago

6.2.5

4 years ago

6.2.4

4 years ago

7.1.3

4 years ago

7.1.4

4 years ago

7.1.2

4 years ago

7.1.1

4 years ago

6.2.3

4 years ago

7.1.0

4 years ago

6.2.2

4 years ago

6.2.1

4 years ago

6.2.0

4 years ago

7.0.0

4 years ago

5.1.3

5 years ago

6.1.1

5 years ago

5.1.2

5 years ago

6.0.1

5 years ago

6.0.0

5 years ago

6.0.0-beta.54

5 years ago

6.0.0-beta.53

5 years ago

6.0.0-beta.52

5 years ago

6.0.0-beta.51

5 years ago

6.0.0-beta.50

5 years ago

6.0.0-beta.49

5 years ago

6.0.0-beta.48

5 years ago

6.0.0-beta.47

5 years ago

6.0.0-beta.46

5 years ago

6.0.0-beta.45

5 years ago

6.0.0-beta.44

5 years ago

6.0.0-beta.43

5 years ago

6.0.0-beta.42

5 years ago

6.0.0-beta.41

5 years ago

6.0.0-beta.40

5 years ago

6.0.0-beta.39

5 years ago

6.0.0-beta.38

5 years ago

6.0.0-beta.37

5 years ago

6.0.0-beta.36

5 years ago

6.0.0-beta.35

5 years ago

6.0.0-beta.34

5 years ago

6.0.0-beta.33

5 years ago

6.0.0-beta.32

5 years ago

6.0.0-beta.31

5 years ago

6.0.0-beta.30

5 years ago

6.0.0-beta.28

5 years ago

6.0.0-beta.26

5 years ago

6.0.0-beta.25

5 years ago

6.0.0-beta.24

5 years ago

6.0.0-beta.23

5 years ago

6.0.0-beta.22

5 years ago

6.0.0-beta.21

5 years ago

6.0.0-beta.20

5 years ago

6.0.0-beta.19

5 years ago

6.0.0-beta.18

5 years ago

6.0.0-beta.17

5 years ago

6.0.0-beta.16

5 years ago

6.0.0-beta.15

5 years ago

5.1.1

5 years ago

6.0.0-beta.14

5 years ago

6.0.0-beta.12

5 years ago

6.0.0-beta.11

5 years ago

6.0.0-beta.9

5 years ago

6.0.0-beta.3

5 years ago

5.0.1

5 years ago

5.0.0

5 years ago

4.2.0

5 years ago