mirror of
https://github.com/wassname/talk.git
synced 2026-07-22 13:00:29 +08:00
[CORL-181] Comment Count Injection (#2581)
* feat: inject comment counts * fix: tests * feat: integrate stream embed with coral counts * chore: refactor constants * test: test for count bundle * test: test live comment count integration with stream embed * feat: use defer * fix: snapshot * feat: auto add count.js in when calling Coral.createStreamEmbed * fix: tests * fix: rm duplicate test * chore: remove unuse file
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
import { COUNT_SELECTOR } from "coral-framework/constants";
|
||||
|
||||
/** Injects a global CoralCount callback into the window object to be used in JSONP */
|
||||
function injectJSONPCallback() {
|
||||
(window as any).CoralCount = {
|
||||
setCount: (data: { ref: string; html: string }) => {
|
||||
// Find all the elements with ref.
|
||||
const elements = document.querySelectorAll(
|
||||
`${COUNT_SELECTOR}[data-coral-ref='${data.ref}']`
|
||||
);
|
||||
Array.prototype.forEach.call(elements, (element: HTMLElement) => {
|
||||
element.innerHTML = data.html;
|
||||
});
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export default injectJSONPCallback;
|
||||
Reference in New Issue
Block a user