crosstalk-comments-livechat-sdk 0.0.6-beta.2 → 0.0.6-beta.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,6 @@
1
1
  import type { ChatOptions } from './types';
2
2
  export declare class CrossTalkChatEmbed {
3
3
  private config;
4
- parentDiv: HTMLElement;
5
4
  render(): void;
6
5
  constructor(config: ChatOptions);
7
6
  }
@@ -7,16 +7,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- function buildIframeUrl(config) {
10
+ function buildIframeUrl(config, wp, theme) {
11
11
  const baseUrl = 'https://widgets.crosstalk.cc/chat';
12
12
  const params = new URLSearchParams();
13
- params.append('wp', config.wp);
13
+ params.append('wp', wp);
14
14
  if (config.url)
15
15
  params.append('url', config.url);
16
16
  else if (config.pageID)
17
17
  params.append('pageID', config.pageID);
18
- if (config.theme)
19
- params.append('theme', config.theme);
18
+ if (theme)
19
+ params.append('theme', theme);
20
20
  return `${baseUrl}?${params.toString()}`;
21
21
  }
22
22
  function createHash(input) {
@@ -30,11 +30,11 @@ function createHash(input) {
30
30
  }
31
31
  return hash.toString(16);
32
32
  }
33
- function periodicChecks(obj, btnID, isEntity) {
33
+ function periodicChecks(obj, btnID, isEntity, wp) {
34
34
  const btn = document.getElementById(btnID);
35
35
  if (isEntity)
36
36
  setInterval(() => {
37
- fetch(`https://crosstalk.cc/api/chat/numberOfUsersForEntity?wpName=${obj.wp}&entity=${obj.pageID}`).then((v) => __awaiter(this, void 0, void 0, function* () {
37
+ fetch(`https://crosstalk.cc/api/chat/numberOfUsersForEntity?wpName=${wp}&entity=${obj.pageID}`).then((v) => __awaiter(this, void 0, void 0, function* () {
38
38
  if (v.ok) {
39
39
  const data = yield v.json();
40
40
  btn.innerHTML = `<b class='crosstalk_btnTxt'>(${data}) ${obj.title}</b>`;
@@ -43,7 +43,7 @@ function periodicChecks(obj, btnID, isEntity) {
43
43
  }, 7000);
44
44
  else
45
45
  setInterval(() => {
46
- fetch(`https://crosstalk.cc/api/chat/numberOfUsersForURL?wpName=${obj.wp}&url=${obj.url}`).then((v) => __awaiter(this, void 0, void 0, function* () {
46
+ fetch(`https://crosstalk.cc/api/chat/numberOfUsersForURL?wpName=${wp}&url=${obj.url}`).then((v) => __awaiter(this, void 0, void 0, function* () {
47
47
  if (v.ok) {
48
48
  const data = yield v.json();
49
49
  btn.innerHTML = `<b class='crosstalk_btnTxt'>(${data}) ${obj.title}</b>`;
@@ -51,7 +51,7 @@ function periodicChecks(obj, btnID, isEntity) {
51
51
  }));
52
52
  }, 7000);
53
53
  }
54
- function newGChat(obj, parentDiv) {
54
+ function newGChat(obj, parentDiv, wp, theme) {
55
55
  const chatHolder = document.createElement("div");
56
56
  chatHolder.setAttribute("style", "margin-right: 5px");
57
57
  let pageHash = "";
@@ -63,15 +63,15 @@ function newGChat(obj, parentDiv) {
63
63
  else if (obj.url != null && obj.url != undefined && obj.url != "")
64
64
  pageHash = createHash(obj.url);
65
65
  const iframe = document.createElement("iframe");
66
- const mainChatID = `id_${obj.wp}_${pageHash}`;
66
+ const mainChatID = `id_${wp}_${pageHash}`;
67
67
  iframe.id = mainChatID;
68
- iframe.src = buildIframeUrl(obj);
68
+ iframe.src = buildIframeUrl(obj, wp, theme);
69
69
  iframe.setAttribute("class", "crosstalk_frame");
70
70
  iframe.sandbox = "allow-storage-access-by-user-activation allow-scripts allow-same-origin allow-popups";
71
71
  iframe.setAttribute("scrolling", "auto");
72
72
  chatHolder.appendChild(iframe);
73
73
  const chatShowHideButton = document.createElement("span");
74
- if (obj.theme == 'light')
74
+ if (theme == 'light')
75
75
  chatShowHideButton.setAttribute("class", "crosstalk_btn");
76
76
  else
77
77
  chatShowHideButton.setAttribute("class", "crosstalk_btn dark");
@@ -81,7 +81,7 @@ function newGChat(obj, parentDiv) {
81
81
  chatShowHideButton.appendChild(onlineSpan);
82
82
  const buttonName = document.createElement("span");
83
83
  buttonName.innerHTML = `<b class='crosstalk_btnTxt'>${obj.title}</b>`;
84
- buttonName.id = `online_${obj.wp}_${pageHash}`;
84
+ buttonName.id = `online_${wp}_${pageHash}`;
85
85
  chatShowHideButton.onclick = function (ev) {
86
86
  const mainIframe = document.getElementById(mainChatID);
87
87
  if (mainIframe.style.display === "block") {
@@ -114,25 +114,28 @@ function newGChat(obj, parentDiv) {
114
114
  chatShowHideButton.style.borderTopRightRadius = "5px";
115
115
  }, 3000);
116
116
  }
117
- periodicChecks(obj, `online_${obj.wp}_${pageHash}`, isEntity);
117
+ periodicChecks(obj, `online_${wp}_${pageHash}`, isEntity, wp);
118
118
  }
119
119
  export class CrossTalkChatEmbed {
120
120
  render() {
121
- document.head.insertAdjacentHTML('beforebegin', '<link rel="stylesheet" href="https://widgets.crosstalk.cc/tab_livechat.css" />');
122
- this.parentDiv = document.getElementById("crosstalkChatHolder");
123
- if (!this.parentDiv) {
124
- this.parentDiv = document.createElement("div");
125
- this.parentDiv.id = "crosstalkChatHolder";
126
- document.body.appendChild(this.parentDiv);
121
+ const link = document.createElement('link');
122
+ link.rel = 'stylesheet';
123
+ link.href = 'https://widgets.crosstalk.cc/tab_livechat.css';
124
+ document.head.appendChild(link);
125
+ var parentDiv = document.getElementById("crosstalkChatHolder");
126
+ if (!parentDiv) {
127
+ parentDiv = document.createElement("div");
128
+ parentDiv.id = "crosstalkChatHolder";
129
+ document.body.appendChild(parentDiv);
127
130
  }
131
+ if (!this.config.theme)
132
+ this.config.theme = "light";
128
133
  this.config.pageIDs.forEach(pageID => {
129
- pageID.theme = this.config.theme;
130
- newGChat(pageID, this.parentDiv);
134
+ newGChat(pageID, parentDiv, this.config.wp, this.config.theme);
131
135
  });
132
136
  }
133
137
  constructor(config) {
134
138
  this.config = config;
135
- this.parentDiv = undefined;
136
139
  this.render();
137
140
  }
138
141
  }
package/dist/types.d.ts CHANGED
@@ -4,7 +4,9 @@ interface BaseOptions {
4
4
  pageID?: string;
5
5
  theme?: string;
6
6
  }
7
- export interface ChatPageOptions extends BaseOptions {
7
+ export interface ChatPageOptions {
8
+ url?: string;
9
+ pageID?: string;
8
10
  collapsed?: boolean;
9
11
  title?: string;
10
12
  }
@@ -29,6 +31,7 @@ export interface AISummaryOptions {
29
31
  theme?: string;
30
32
  }
31
33
  export interface ChatOptions {
34
+ wp?: string;
32
35
  theme?: string;
33
36
  pageIDs?: ChatPageOptions[];
34
37
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "crosstalk-comments-livechat-sdk",
3
- "version": "0.0.6-beta.2",
3
+ "version": "0.0.6-beta.4",
4
4
  "description": "Add Comments, Live Chat, and Video Player Embeds to your website with CrossTalk Comments and Live Chat!",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",