An open API service indexing awesome lists of open source software.

https://github.com/anime-vsub/embed-fbcmt

a simple iframe embed facebook comment plugin for websites
https://github.com/anime-vsub/embed-fbcmt

api embed facebook-api facebook-comments facebook-comments-plugin message message-api spa vue

Last synced: 26 days ago
JSON representation

a simple iframe embed facebook comment plugin for websites

Awesome Lists containing this project

README

          

# embed-fbcmt (Embed Facebook Comment Plugin)

[![Release](https://github.com/anime-vsub/embed-fbcmt/actions/workflows/release.yml/badge.svg)](https://github.com/anime-vsub/embed-fbcmt/actions/workflows/release.yml)
[![pages-build-deployment](https://github.com/anime-vsub/embed-fbcmt/actions/workflows/pages/pages-build-deployment/badge.svg)](https://github.com/anime-vsub/embed-fbcmt/actions/workflows/pages/pages-build-deployment)
[![npm version](https://badge.fury.io/js/embed-fbcmt-client.svg)](https://badge.fury.io/js/embed-fbcmt-client)

[![GitHub license](https://img.shields.io/github/license/anime-vsub/embed-fbcmt)](https://github.com/anime-vsub/embed-fbcmt/blob/main/LICENSE) GitHub Issues Code Score Code Score

[![Test](https://github.com/anime-vsub/embed-fbcmt/actions/workflows/test.yml/badge.svg)](https://github.com/anime-vsub/embed-fbcmt/actions/workflows/test.yml)
[![CodeQL](https://github.com/anime-vsub/embed-fbcmt/actions/workflows/codeql.yml/badge.svg)](https://github.com/anime-vsub/embed-fbcmt/actions/workflows/codeql.yml) [![ESLint](https://github.com/anime-vsub/embed-fbcmt/actions/workflows/eslint.yml/badge.svg)](https://github.com/anime-vsub/embed-fbcmt/actions/workflows/eslint.yml) [![Prettier](https://github.com/anime-vsub/embed-fbcmt/actions/workflows/prettier.yml/badge.svg)](https://github.com/anime-vsub/embed-fbcmt/actions/workflows/prettier.yml)
[![TypeScript Checker Declaration](https://github.com/anime-vsub/embed-fbcmt/actions/workflows/typing.yml/badge.svg)](https://github.com/anime-vsub/embed-fbcmt/actions/workflows/typing.yml)
[![Try build](https://github.com/anime-vsub/embed-fbcmt/actions/workflows/try-build.yml/badge.svg)](https://github.com/anime-vsub/embed-fbcmt/actions/workflows/try-build.yml)

This is a plugin allow embed [Facebook Comment Plugin](https://developers.facebook.com/docs/plugins/comments/) to website SPA

Demo: https://anime-vsub.github.io/embed-fbcmt?href=https://google.com&no_socket=true&num_posts=20

## Usage
Append this code to location show comment:
```html

```
> All mentioned [`options of FB comment plugin`](https://developers.facebook.com/docs/plugins/comments/) are available.
In addition, you can also use some of the following custom options:

| Option | Type | Default | Description |
| ------ | ---- | ------- | ----------- |
| `lang` | code lang | `en_US` | language the plugin will display (example: `vi_VN`, `ja_JP`...) |
| `loader_bg` | color | `rgba(0,0,0,0.8)` | adjust background color when plugin is loading |
| `loader_text` | color | `white` | adjust text color when plugin is loading |
| `origin` | host name | `*` | domain name will be sent the message. you can specify the hostname of the embedded website to increase security |
| `no_socket` | boolean | `false` | whether to disable `WebSocket` to save resources |
| `active` | boolean | `true` | if this plugin is enabled if `false` then the plugin displays a blank page |
| `no_popup` | boolean | `false` | remove loading popup and use error warnings when you customize them |

## Package NPM
This package allows you to send change requests to the plugin without losing the SDK reload time. A useful thing for SPA website
### Install
```bash
pnpm add embed-fbcmt-client
```

You can use this plugin anywhere I will give an example with `Vue`
```vue

Change lang to Japanese

import { ref } from "vue"
import { setPropValue } from "embed-fbcmt-client/vue"

const cmtRef = ref<HTMLIFrameElement>()

```
### Functions
```ts
function setPropValue(el: HTMLIFrameElement | Ref, propName: string, value: string): Promise
```
- Options:
- `el`: iframe embed plugin
- `propName`: option name set
- `value`: value set to prop
- Return: `Promise` a promise that resolves when the set option succeeds or fails

```ts
function listenEvent(
el: HTMLIFrameElement,
cb: (event: { type: "success" | "loading" | "error"; code: CODES }) => void
): () => void
```
- Options:
- `el`: iframe embed plugin
- `cb`: this function is cakked every time something changes in the embed
- Return: `() => void` cancel

```ts
function listenResize(
el: HTMLIFrameElement,
type: "width" | "height",
cb: (size: number) => void
): () => void
```
- Options:
- `el`: iframe embed plugin
- `cb`: this function is cakked every time something changes in the embed
- Return: `() => void` cancel

### For vue
```ts
function useEmbed(el: HTMLIFrameElement | Ref): {
code: CODES // code status embed
loading: boolean // true is loading
error: boolean // true is error emited
}
```
component:
```vue

import { EmbedFbCmt } from "embed-fbcmt-client/vue"

```

```ts
function useEmbedSize(
el: HTMLIFrameElement | Ref | undefined
): {
width: Ref
height: Ref
}
```

```ts
function useEmbedHeight(
el: HTMLIFrameElement | Ref | undefined
): Ref
```