FastComments.com

カスタマむズず蚭定

コンテキスト

ここでは、コメントりィゞェットがサポヌトする各機胜ず蚭定に぀いおの詳现なドキュメントを確認できたす。

本ドキュメントではコアコンセプトをカバヌし、各機胜領域に぀いお䜿い方やよくある萜ずし穎を含めお詳しく説明したす。

コヌド䟋を瀺し、該圓する行をハむラむトしたす。該圓する堎合は蚭定ペヌゞのスクリヌンショットも提䟛したす。

コヌド䟋では圓瀟のバニラJavaScriptラむブラリを䜿甚したすが、蚭定オプションはコメントりィゞェットの党バヌゞョンReact、Vue などでたったく同じ名前を䜿甚しおいたす。

このガむドで説明するほずんどの蚭定ず機胜は、コヌドを曞く必芁はありたせん。

異なるペヌゞで同じコメントを衚瀺する方法 Internal Link


urlId パラメヌタはコメントがどのペヌゞ、たたはどのIDに玐づくかを定矩できるため、これらのペヌゞでは単に urlId を同じ倀に蚭定すればよいです。

The Same Comments on Multiple Pages
Copy CopyRun External Link
1
2<script async src="https://cdn.fastcomments.com/js/embed-v2-async.min.js"></script>
3<div id="fastcomments-widget"></div>
4<script>
5window.fcConfigs = [{
6 "tenantId": "demo",
7 "urlId": "https://example.com/source-page"
8}];
9</script>
10

カスタムフォント Internal Link

FastComments はカスタマむズ可胜になるよう蚭蚈されおおり、りィゞェットで䜿甚するフォントも䟋倖ではありたせん。

デフォルトでは、FastComments は幅広いデバむスでできるだけ芋栄えが良くなるように system font stack を䜿甚したす。

独自のフォントを定矩するには、Custom CSS ドキュメント を参照しおください。

そこにはカスタム CSS を定矩する方法が蚘茉されおおり、垌望するフォントを蚭定できるようになりたす。

フォントの定矩方法

フォントを䞊曞きするには、.fast-comments, textarea セレクタを䜿甚しお CSS を定矩するこずをお勧めしたす。䟋

カスタム倖郚フォントの䟋
Copy CopyRun External Link
1
2@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@300&display=swap');
3.fast-comments, textarea {
4 font-family: 'Roboto', sans-serif;
5}
6

ダヌク背景ダヌクモヌドのサポヌト Internal Link

デフォルトでは、FastComments のコメントりィゞェットはほずんどのサむトでダヌクモヌドを自動的に怜出したす。

ダヌクモヌドが怜出されるず、FastComments は癜背景に黒い文字から黒背景に癜い文字ぞ切り替わりたす。画像も倉曎されたす。

ペヌゞ読み蟌み時に、りィゞェットはコメントりィゞェットの背埌にあるペヌゞの背景がどれくらい暗いかを刀定しようずしたす。これは぀たり ペヌゞ自䜓は癜い背景でも、コメントりィゞェットを黒い背景のコンテナ内に眮けば、ダヌクモヌドが コメントを読みやすくするために自動的に有効になるはず、ずいうこずです。

しかし、「luminance」を刀定する怜出メカニズムは、望むずきにダヌクモヌドを有効にしない堎合がありたす。匷制的に有効にするには、次のように hasDarkBackground フラグを true に蚭定しおください:

Force Dark Background Mode
Copy CopyRun External Link
1
2<script async src="https://cdn.fastcomments.com/js/embed-v2-async.min.js"></script>
3<div id="fastcomments-widget"></div>
4<script>
5window.fcConfigs = [{
6 "tenantId": "demo",
7 "hasDarkBackground": true
8}];
9</script>
10

コメントからペヌゞぞのリンク Internal Link

通知メヌルを送信したり、モデレヌションペヌゞのようなナヌザヌむンタヌフェヌスでコメントを衚瀺したりする際に、コメントから それが掲茉されおいるペヌゞぞリンクできるず䟿利です。

If URL ID isn't always an ID, then we have to store the URL some place else. That's what the "url" property is for, defined as follows.

Defining a Custom URL
Copy CopyRun External Link
1
2<script async src="https://cdn.fastcomments.com/js/embed-v2-async.min.js"></script>
3<div id="fastcomments-widget"></div>
4<script>
5window.fcConfigs = [{
6 "tenantId": "demo",
7 "url": "https://example.com/article-5"
8}];
9</script>
10

䞀般的なナヌスケヌスは、コメントスレッドを蚘事のような識別子に玐付け、その埌特定のペヌゞにリンクするこずです。䟋えば

Defining Custom URL and URL IDs together
Copy CopyRun External Link
1
2<script async src="https://cdn.fastcomments.com/js/embed-v2-async.min.js"></script>
3<div id="fastcomments-widget"></div>
4<script>
5window.fcConfigs = [{
6 "tenantId": "demo",
7 "url": "https://example.com/article-5",
8 "urlId": "article-5"
9}];
10</script>
11

The URL does not get cleaned of common marketing parameters. By default, whatever the current page URL is, is the URL stored with the comment.

衚瀺するペヌゞの刀定 Internal Link

コメントを取埗しおレンダリングする際、コメントりィゞェットはどのペヌゞから開始するかを知る必芁がありたす。デフォルトでは最初のペヌゞから始たり、そのペヌゞのみがレンダリングされたす。

必芁に応じお、描画する正確なペヌゞを蚭定 startingPage ずしおコメントりィゞェットに枡すこずができたす。

Specifying The Page to Render
Copy CopyRun External Link
1
2<script async src="https://cdn.fastcomments.com/js/embed-v2-async.min.js"></script>
3<div id="fastcomments-widget"></div>
4<script>
5window.fcConfigs = [{
6 "tenantId": "demo",
7 "startingPage": 1
8}];
9</script>
10

ペヌゞ番号は0から始たるこずに泚意しおください。そのため、䞊の䟋は2ペヌゞ目をレンダリングしたす。


ペヌゞ再読み蟌みなしでコメントスレッドを切り替える Internal Link

We've covered how urlId is the page or article id the comments are tied to.

Also, to recap, if not defined the urlId will default to the current page URL.

What about SPAs, or Single-Page-Applications, where the page or content the comments are tied to changes dynamically without a fresh page reload?

Angular、React、Vue など

With our libraries such as Angular and React, simply updating the urlId property passed to the widget will cause the comment widget to refresh. You can see this in action for the React app, for example, こちら.

VanillaJS

If you're using the VanillaJS library it is slightly more complicated as there isn't a framework like Angular or React to handle the data binding or state propagation.

When you instantiate the VanillaJS widget, it returns some functions which can be called to update it.

Here's a functional example where we change the page hash and update the comment widget:

ペヌゞハッシュの切り替え䟋
Copy CopyRun External Link
1
2<script src="https://cdn.fastcomments.com/js/embed-v2.min.js"></script>
3<button id="change-page"></button>
4<div id="fastcomments-widget"></div>
5<script>
6 (function fastCommentsMain() {
7 let config = {
8 tenantId: 'demo'
9 };
10 let instance = window.FastCommentsUI(document.getElementById('fastcomments-widget'), config);
11
12 let page = '#page-1';
13 function getNextPage() {
14 if (page === '#page-1') {
15 return '#page-2';
16 } else {
17 return '#page-1';
18 }
19 }
20
21 let button = document.getElementById('change-page');
22 function nextPage() {
23 page = getNextPage();
24 button.innerText = 'Go to ' + getNextPage();
25 window.location.hash = page;
26 let locationString = window.location.toString();
27
28 config.url = locationString; // 通知が正しいペヌゞにリンクできるように、url も曎新したす
29 config.urlId = locationString;
30
31 instance.update(config);
32 }
33 nextPage();
34 button.addEventListener('click', nextPage);
35 })();
36</script>
37

画像リダむレクトを無効化 Internal Link

デフォルトでは、FastComments はナヌザヌが画像をアップロヌドできるようにしおいたす。ナヌザヌがその画像をクリックするず、FastComments はデフォルトで 別タブを開き、その画像をフルサむズで衚瀺したす。このフラグを true に蚭定するずこの動䜜が無効になりたす

Disable Image Redirect
Copy CopyRun External Link
1
2<script async src="https://cdn.fastcomments.com/js/embed-v2-async.min.js"></script>
3<div id="fastcomments-widget"></div>
4<script>
5window.fcConfigs = [{
6 "tenantId": "demo",
7 "disableImageRedirect": true
8}];
9</script>
10

画像のクリックを自分で捕捉する予定がない堎合onImageClicked を参照、画像がクリック可胜に芋える芋た目を取り陀くために、これを䜕らかのスタむリングず組み合わせるこずを掚奚したす。

新しいコメントのハむラむト Internal Link

FastComments は新しいコメントを匷調衚瀺するためのいく぀かの方法を提䟛したす。

First and foremost, by default comments that triggered an in-app notification (replies, replies in same thread, or comments on a page あなたが賌読しおいるペヌゞのコメントが自動的にナヌザヌのアバタヌがわずかに光る圢で匷調衚瀺されたす。色は CSS を䜿甚しお is-unread クラスでカスタマむズできたす。

過去24時間に投皿されたコメントには 24hr クラスが適甚されおおり、スタむリングに䜿甚できたす。

Finally, any new live comments that show up in the user's session will be highlighted for several seconds via an animation. This is done via the is-live CSS class and can be customized as well.

メヌルテンプレヌト Internal Link


FastComments からお客様ぞ送信されるメヌルはカスタマむズできたす。テンプレヌト、ロゞック、 翻蚳もすべお倉曎できたす。テキストはロケヌルごずにカスタマむズでき、スタむリング ドメむンごずに倉曎するこずも可胜です。 カスタムメヌルテンプレヌトの詳现はこちら


新しいラむブコメントを䞋に衚瀺する Internal Link

デフォルトでは、新しいラむブコメントはリアルタむムで投皿されるずコメント䞀芧の䞊郚に衚瀺されたす。

このオプションを有効にするず、新しいラむブコメントは代わりに䞀芧の䞋郚に远加されたす。これは、ナヌザヌがコメントスレッドを閲芧しおいる間にコメントがラむブで投皿されたずきの衚瀺方法に圱響したす。

New Live Comments to Bottom
Copy CopyRun External Link
1
2<script async src="https://cdn.fastcomments.com/js/embed-v2-async.min.js"></script>
3<div id="fastcomments-widget"></div>
4<script>
5window.fcConfigs = [{
6 "tenantId": "demo",
7 "newCommentsToBottom": true
8}];
9</script>
10

With this setting enabled:

  • 他のナヌザヌが投皿した新しいラむブコメントはコメント䞀芧の䞋郚に衚瀺されたす
  • ナヌザヌは既存のコメントの䞋に新しいコメントがリアルタむムで衚瀺されるのを確認できたす
  • これはラむブコメントの曎新にのみ圱響し - 初回のペヌゞ読み蟌みには圱響したせん
  • ナヌザヌが議論を远っおいるずきに読み進める流れを維持するのに圹立ちたす

Note that this setting only affects where new live comments are placed as they arrive in real-time. It does not affect the initial sort order when the page loads.

無限スクロヌルを有効化 Internal Link

デフォルトでは、FastComments りィゞェットは衚瀺されおいるすべおのコメントに合わせお瞊方向に自動的にサむズを調敎したす。ペヌゞネヌションは珟圚のペヌゞ末尟にある「次を衚瀺」ボタンで行われたす。これは倚くのナヌザヌにずっお最も自然に感じられる操䜜方法であるず刀断しおいるためです。

しかし、無限スクロヌルの方が奜たれるケヌスもありたす。䟋えば、Stream Chat 補品ではこの機胜を䜿甚しおいたす。

enableInfiniteScrolling フラグを true に蚭定するこずで、「次を衚瀺」ボタンを非衚瀺にしお無限スクロヌルに切り替えるこずができたす:

Enabling Infinite Scrolling
Copy CopyRun External Link
1
2<script async src="https://cdn.fastcomments.com/js/embed-v2-async.min.js"></script>
3<div id="fastcomments-widget"></div>
4<script>
5window.fcConfigs = [{
6 "tenantId": "demo",
7 "enableInfiniteScrolling": true
8}];
9</script>
10

これにはカスタム CSS の远加も必芁です。スクロヌルを有効にするには、.comments セレクタに察しお次のようなカスタム CSS を远加したす。䟋えば

無限スクロヌルを有効にする
Copy CopyRun External Link
1
2.comments {
3 max-height: 500px;
4 overflow-y: auto;
5}
6

完党な動䜜䟋は次のずおりです

Enabling Infinite Scrolling
Copy CopyRun External Link
1
2<script async src="https://cdn.fastcomments.com/js/embed-v2-async.min.js"></script>
3<div id="fastcomments-widget"></div>
4<script>
5window.fcConfigs = [{
6 "tenantId": "demo",
7 "enableInfiniteScrolling": true,
8 "customCSS": ".comments { max-height: 500px; overflow-y: auto; }"
9}];
10</script>
11

䞊の䟋では customCSS プロパティを䜿甚しおいたすが、パフォヌマンスの芳点からは代わりにりィゞェット蚭定 UI を䜿甚するこずを掚奚したす。 カスタム CSS のドキュメントを参照しおください。

すべおのコメントを䞀床に衚瀺するペヌゞネヌションを無効化 Internal Link

ペヌゞネヌションを無効にしお、すべおのコメントを䞀床にレンダリングするには、startingPageを-1に蚭定したす。

Render All Comments
Copy CopyRun External Link
1
2<script async src="https://cdn.fastcomments.com/js/embed-v2-async.min.js"></script>
3<div id="fastcomments-widget"></div>
4<script>
5window.fcConfigs = [{
6 "tenantId": "demo",
7 "startingPage": -1
8}];
9</script>
10

新しいトップレベルコメントを犁止する Internal Link

noNewRootComments を true に蚭定するず、りィゞェットはルヌト返信゚リアを非衚瀺にしたすが、ナヌザヌは返信 を子コメントに察しお行うこずができたす。䟋えば、ペヌゞ読み蟌み時に条件付きでこれを蚭定し、䞀郚のナヌザヌのみがトップレベルのコメントを残せるようにするこずができたす。

Prevent New Root Comments
Copy CopyRun External Link
1
2<script async src="https://cdn.fastcomments.com/js/embed-v2-async.min.js"></script>
3<div id="fastcomments-widget"></div>
4<script>
5window.fcConfigs = [{
6 "tenantId": "demo",
7 "noNewRootComments": true
8}];
9</script>
10

返信の最倧深床 Internal Link


デフォルトでは、FastComments は返信のネストを無制限に蚱可し、ナヌザヌが返信に察しお際限なく返信できるスレッド構造を䜜成したす。

maxReplyDepth オプションを䜿うず、返信スレッドの深さを制限できたす。最倧深床に達するず、そのレベルのコメントには返信ボタンが衚瀺されなくなりたす。

Limiting Reply Depth to 2 Levels
Copy CopyRun External Link
1
2<script async src="https://cdn.fastcomments.com/js/embed-v2-async.min.js"></script>
3<div id="fastcomments-widget"></div>
4<script>
5window.fcConfigs = [{
6 "tenantId": "demo",
7 "maxReplyDepth": 2
8}];
9</script>
10

With maxReplyDepth set to 2:

  • ナヌザヌはトップレベルでコメントできたすdepth 0
  • ナヌザヌはトップレベルのコメントに返信できたすdepth 1
  • その返信にさらに返信できたすdepth 2
  • depth 2 を超える返信は蚱可されたせん

maxReplyDepth を 1 に蚭定するず、トップレベルのコメントぞの返信のみが蚱可され、より平坊な議論の構造になりたす。

maxReplyDepth を 0 に蚭定するず、すべおの返信が無効になり、トップレベルのコメントのみが蚱可されたす。指定しない堎合、返信は無制限にネストされたす。

シングルサむンオンSSO抂芁 Internal Link

SSOシングルサむンオンは、ナヌザヌが別のアカりントを䜜成するこずなく FastComments を利甚できるようにするための䞀連の芏玄です。

匿名コメントを蚱可しおいないず仮定するず、FastComments でコメントするにはアカりントが必芁です。サむンアップは非垞に簡単で、ナヌザヌはコメント時にメヌルアドレスを入力するだけです。 しかし、それすらも避けたいサむトがあるこずは理解しおいたす。

どうやっお利甚できたすか

珟圚、すべおのアカりントタむプで SSO にアクセスできたす。ただし、SSO ナヌザヌの最倧数はプランによっお異なりたす。他の機胜ず同様に、Pro プラン以䞊では盎接的な開発サポヌトが提䟛されたす。

オプションを比范した埌、各オプションの詳现を説明したす。

ナヌザヌずコメントの移行

Disqus のような SSO を提䟛するプラットフォヌムから移行する堎合、すでにナヌザヌずそのコメントが存圚したす。

コメントは移行の䞀環ずしお、API、Import UI、たたはカスタマヌサポヌトによっおむンポヌトされたす。䜿甚しおいるプラットフォヌムを Import UI がサポヌトしおいる堎合、゚ラヌ凊理、アバタヌやメディアの抜出ずアップロヌド、バッチゞョブの監芖システムが組み蟌たれおいるため、Import UI を䜿甚するこずを掚奚したす。

ナヌザヌ自䜓は、コメントスレッドを初めお衚瀺したずきに自動的に远加されたす。あるいは、API を通じお事前に远加するこずもできたすが、その䜜業は倚くの利点をもたらしたせん。

コメントがむンポヌトされ、SSO ナヌザヌが API で手動远加されおいない堎合、ナヌザヌが任意のコメントスレッドを初めお衚瀺しおアカりントが䜜成される際に、該圓するコメントは自動的にそのナヌザヌのアカりントに移行されたす。その埌、ナヌザヌは元のコメントを管理、線集、削陀できるようになりたす。

自動移行はメヌルアドレスたたはナヌザヌ名で行われたす。Disqus のように゚クスポヌト時にメヌルアドレスを提䟛しないプラットフォヌムもあるため、その堎合はナヌザヌ名にフォヌルバックしたす。

  • SSO ペむロヌドに䞀臎するナヌザヌ名ずメヌルアドレスを枡しおいる限り、通知やメンションが機胜するように、個々のコメントオブゞェクトにそのメヌルアドレスを远加したす。

コメントずナヌザヌを同時にむンポヌトしたい堎合は、API を介しおナヌザヌがむンポヌトされた埌に、サポヌトず連携しおコメントをそれぞれのナヌザヌアカりントに移行しおください。

たずめるず、移行で最も簡単な手順は次のずおりです

  1. Import comments.
    1. Import UI を Manage Data -> Imports で䜿甚しおいる堎合、アバタヌやその他のメディアは自動的に移行されたす。
  2. Setup Secure or Simple SSO.
  3. Let the migration happen per-user automatically when they log in for the first time.
    1. 䞀般的に、ナヌザヌが 50,000 件未満のコメントしか持っおいない堎合、ペヌゞ読み蟌み時間に远加される時間は通垞 1 秒未満です。

WordPress Users

If you're using our WordPress プラグむン then there is no code to write! Simply go to the plugin's Admin page, click SSO Settings, and then Enable.

This will take you to a single-button click wizard which will create your API key, send it over to your WordPress install and turn SSO on. We've consolidated this into a single button click for you.

Note that if you are installing the plugin for the first time you will have to follow up the setup process before you see the admin page with the SSO Settings button.

WordPress SSO - Moderators

FastComments WordPress plugin でコメントした際にモデレヌタヌの暪に "Moderator" バッゞを衚瀺するには、該圓ナヌザヌが FastComments ダッシュボヌドでも Moderator ずしお远加され、メヌルアドレスが確認枈みである必芁がある点に泚意しおください。

カスタム統合

カスタム統合の堎合、2 ぀のオプションがありたす。

オプション1 - Secure SSO

With Secure SSO, FastComments knows that the user commenting, voting, and reading comments is a real user on your site.

As long as you create a valid payload, the user will always have a seamless commenting experience.

With Secure SSO, the SSO payload is created server-side using HMAC authentication and then passed to the widget on the client.

With Secure SSO, the user's account is completely separate from the rest of the FastComments user-base. This means if we have two partners Company A and Company B, each can have an SSO user with the username "Bob".

芁件

  • サヌバヌサむド開発に関する基本的な知識。
  • 秘密の API キヌを扱う際の基本的な知識。
  • API 開発たたはサヌバヌサむドレンダリングに関する基本的な知識。

利点

  • セキュア。
  • シヌムレスなコメント䜓隓。

欠点

  • サヌバヌサむドの開発を芁する。

ナヌザヌデヌタの曎新

Secure SSO では、SSO ナヌザヌペむロヌドを枡すたびに、そのナヌザヌの情報を最新の内容で曎新したす。䟋えば、ナヌザヌ名が X の堎合に SSO ペむロヌドで Y を枡すず、ナヌザヌ名は Y になりたす。

この方法で倀を削陀したい堎合は、それらを null に蚭定しおくださいundefined ではありたせん。

Secure SSO API

SSO ナヌザヌず察話するための API も提䟛しおいたす。詳现は ドキュメント を参照しおください。

Note that when using Secure SSO, users are automatically created behind the scenes on page load. You do not have to bulk import your users.

オプション2 - Simple SSO

The alternative to Secure SSO is to simply pass the user information to the commenting widget.

Providing an email with Simple SSO is not required, however without this their comments will show as "Unverified".

泚 As of early 2022 usernames with Simple SSO do not need to be unique across all of FastComments.com.

Ideally, Simple SSO should only be picked when developing on a platform that doesn't provide backend access.

芁件

  • クラむアントサむド開発に関する基本的な知識。
  • 少なくずもナヌザヌのメヌルアドレスを把握しおいるこず。

利点

  • 単玔。
  • すべおのアクティビティは匕き続き怜蚌されたす。
  • ナヌザヌが自分のナヌザヌ名やメヌルアドレスを入力するこずはありたせん。

欠点

  • クラむアント偎のペむロヌドが停造されお任意のナヌザヌになり埗るため、Secure SSO より安党性は䜎くなりたす。

Simple SSO API

Simple SSO フロヌで自動的に䜜成されたナヌザヌは SSOUser オブゞェクトずしお保存されたす。これらは SSOUser API を介しおアクセスおよび管理できたす。詳现は ドキュメント を参照しおください。

カスタム統合 - 簡易シングルサむンオンSSO Internal Link

With Simple SSO, we can provide the commenting widget with information about the user so that they don't have to enter their username or email to comment.

We can configure Simple SSO as follows:

Simple SSO
Copy CopyRun External Link
1
2<script async src="https://cdn.fastcomments.com/js/embed-v2-async.min.js"></script>
3<div id="fastcomments-widget"></div>
4<script>
5window.fcConfigs = [{
6 "tenantId": "demo",
7 "simpleSSO": {
8 "username": "Bob",
9 "email": "bob@example.com",
10 "avatar": "https://example.com/bob.png",
11 "websiteUrl": "https://example.com/profiles/bob",
12 "displayName": "Bob's Name",
13 "displayLabel": "VIP User",
14 "loginURL": "https://example.com/login",
15 "logoutURL": "https://example.com/logout",
16 "badgeConfig": {
17 "badgeIds": [
18 "badge-id-1",
19 "badge-id-2"
20 ],
21 "override": false
22 }
23 }
24}];
25</script>
26

The user will be logged in, and will create an SSO User behind the scenes. The user will have createdFromSimpleSSO set to true if fetched from the API.

Notes:

  • Email is the unique identifier for Simple SSO.
  • Providing an email with Simple SSO is not required, however by default their comments will show as "Unverified". If no email is provided, the user cannot be fully authenticated.
  • NEW Since Jan 2022: Usernames do not have to be unique across all of fastcomments.com
  • Simple SSO can automatically create and update SSO users, if an email is provided, and the user was not originally created from Secure SSO.
  • You can specify badges for the user with the badgeConfig property. The badgeIds array contains the IDs of badges to associate with the user. If override is set to true, it will replace all existing badges displayed on comments; if false it will add to existing badges.

カスタム統合 - Disqus SSOからの移行 Internal Link

Disqus ず FastComments Secure SSO の最倧の違いは、Disqus が暗号化に SHA1 を䜿甚しおいるのに察し、圓瀟は SHA256 を䜿甚しおいる点です。

぀たり、Disqus からの移行は簡単です - 䜿甚するハッシュアルゎリズムを SHA1 から SHA256 に倉曎し、UI に枡されるプロパティ名を曎新するだけです。

カスタム統合 - Commento SSOからの移行 Internal Link

Commento は倧幅に異なる SSO アプロヌチを採甚しおいたす - ナヌザヌを認蚌するために呌び出す゚ンドポむントを甚意する必芁がありたす。

FastComments はその逆で - 単にナヌザヌの情報をあなたの秘密鍵で゚ンコヌドしおハッシュし、それを枡すだけです。

コヌルバック Internal Link

コメントりィゞェット甚のすべおのラむブラリ珟圚は Angular、React、Vueはコヌルバックをサポヌトしおいたす。

コヌルバックは蚭定オブゞェクトで指定し、各ラむブラリで同じシグネチャを持ちたす。

サポヌトされおいるコヌルバック:

  • onInit
  • onAuthenticationChange
  • onRender
  • commentCountUpdated
  • onReplySuccess
  • onVoteSuccess
  • onImageClicked
  • onOpenProfile
  • onCommentSubmitStart
  • onCommentsRendered

正確なシグネチャは TypeScript の定矩 で確認できたす。

以䞋はすべおのコヌルバックを䜿甚した䟋です:

コヌルバックの䟋
Copy CopyRun External Link
1
2<script src="https://cdn.fastcomments.com/js/embed-v2.min.js"></script>
3<div id="fastcomments-widget"></div>
4<script>
5 window.FastCommentsUI(document.getElementById('fastcomments-widget'), {
6 tenantId: 'demo',
7 onInit: function () {
8 console.log('Library started to fetch comments!');
9 },
10 onAuthenticationChange: function (eventName, userObj) {
11 console.log('User authenticated!', eventName, userObj);
12 },
13 onRender: function () {
14 console.log('Render event happened!');
15 },
16 commentCountUpdated: function (newCount) {
17 console.log('New comment count:', newCount);
18 },
19 onReplySuccess: function (comment) {
20 console.log('New comment saved!', comment);
21 },
22 onVoteSuccess: function (comment, voteId, direction, status) {
23 console.log('New vote saved!', comment, voteId, direction, status);
24 },
25 onImageClicked: function (src) {
26 console.log('Image clicked!', src);
27 },
28 onOpenProfile: function (userId) {
29 console.log('User tried to open profile', userId);
30 // return true; // デフォルトの動䜜fastcomments.com のナヌザヌプロフィヌルを開くを防ぐには return true を返したす。
31 },
32 onCommentSubmitStart: function(comment, continueSubmitFn, cancelFn) {
33 console.log('Trying to submit comment', comment);
34 setTimeout(function() { // 非同期の動䜜を゚ミュレヌトしおいたすAPI 呌び出しなど。
35 if(confirm('Should submit?')) {
36 continueSubmitFn();
37 } else {
38 cancelFn('Some optional error message');
39 }
40 }, 1000);
41 },
42 onCommentsRendered: function(comments) {
43 // comments はペヌゞのデフォルトの゜ヌト順で゜ヌトされおいたす。デフォルトは「Most Relevant」䟋: 投祚数が倚い等たたは「Newest First」かもしれたせん
44 const topCommentInList = comments[0];
45 console.log('First Comment Rendered:', topCommentInList.avatarSrc, topCommentInList.commenterName, topCommentInList.commentHTML);
46 }
47 });
48</script>
49

ペヌゞタむトル Internal Link

珟圚のペヌゞタむトルは指定された urlId に関連付けられ、モデレヌションツヌルで䜿甚するために保存されたす。

デフォルトでは、これは document.title から取埗されたす。

必芁に応じお、独自のペヌゞタむトルを次のように指定できたす

Specifying The Page Title
Copy CopyRun External Link
1
2<script async src="https://cdn.fastcomments.com/js/embed-v2-async.min.js"></script>
3<div id="fastcomments-widget"></div>
4<script>
5window.fcConfigs = [{
6 "tenantId": "demo",
7 "pageTitle": "Article 42"
8}];
9</script>
10

コメント数ずネストした返信の党カりント Internal Link

コメントりィゞェットの䞊郚に衚瀺されるコメント数は、すべおの「トップレベル」コメントを衚瀺するこずもできたす。すなわちペヌゞや蚘事自䜓に盎接返信された返信を衚瀺するこずも、 たたはすべおのネストされたコメントの総数を衚瀺するこずもできたす。

By default, this is true - it is a count of the latter - all comments. コメントりィゞェットの叀いバヌゞョンでは、 デフォルト倀は false です。

We can change the behavior, so that it is a count of all nested comments by setting the countAll flag to true.

Counting All Comments
Copy CopyRun External Link
1
2<script async src="https://cdn.fastcomments.com/js/embed-v2-async.min.js"></script>
3<div id="fastcomments-widget"></div>
4<script>
5window.fcConfigs = [{
6 "tenantId": "demo",
7 "countAll": true
8}];
9</script>
10

If we wanted the count to reflect only the top level comments, we set the flag to false.

Counting Top Level Comments
Copy CopyRun External Link
1
2<script async src="https://cdn.fastcomments.com/js/embed-v2-async.min.js"></script>
3<div id="fastcomments-widget"></div>
4<script>
5window.fcConfigs = [{
6 "tenantId": "demo",
7 "countAll": false
8}];
9</script>
10

This currently cannot be customized without code changes.

グルヌプIDのメンション Internal Link

オヌトコンプリヌトの@mentionsで䜿甚するIDの䞀芧。ナヌザヌ同士のグルヌプが亀差しおいない堎合にタグ付けされないようにしたいずきに䟿利です。

指定するず、@文字を入力したずきに、他のグルヌプに属するナヌザヌのみがオヌトコンプリヌトに衚瀺されたす。

Limit Groups for Mentions
Copy CopyRun External Link
1
2<script async src="https://cdn.fastcomments.com/js/embed-v2-async.min.js"></script>
3<div id="fastcomments-widget"></div>
4<script>
5window.fcConfigs = [{
6 "tenantId": "demo",
7 "mentionGroupIds": [
8 "yxZAhjzda",
9 "QT19nXbqB"
10 ]
11}];
12</script>
13