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

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,18 @@
1
- import type { ChatOptions } from './types';
1
+ import type { ChatOptions, ChatOption } from './types';
2
+ export declare class CrossTalkTabbedChatEmbed {
3
+ private config;
4
+ private newTabbedGChat;
5
+ constructor(config: ChatOptions);
6
+ }
2
7
  export declare class CrossTalkChatEmbed {
8
+ private container;
3
9
  private config;
10
+ private iframe;
4
11
  render(): void;
5
- constructor(config: ChatOptions);
12
+ constructor(container: HTMLElement, config: ChatOption);
13
+ update(config: Partial<ChatOption>): void;
14
+ destroy(): void;
15
+ getIframe(): HTMLIFrameElement | null;
6
16
  }
7
- export declare function initChats(config: ChatOptions): CrossTalkChatEmbed;
17
+ export declare function initTabbedChats(config: ChatOptions): CrossTalkTabbedChatEmbed;
18
+ export declare function initChat(container: HTMLElement, config: ChatOption): CrossTalkChatEmbed;
@@ -7,18 +7,6 @@ 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, wp, theme) {
11
- const baseUrl = 'https://widgets.crosstalk.cc/chat';
12
- const params = new URLSearchParams();
13
- params.append('wp', wp);
14
- if (config.url)
15
- params.append('url', config.url);
16
- else if (config.pageID)
17
- params.append('pageID', config.pageID);
18
- if (theme)
19
- params.append('theme', theme);
20
- return `${baseUrl}?${params.toString()}`;
21
- }
22
10
  function createHash(input) {
23
11
  if (input.length === 0)
24
12
  return "0";
@@ -30,6 +18,18 @@ function createHash(input) {
30
18
  }
31
19
  return hash.toString(16);
32
20
  }
21
+ function buildIframeUrl(url, pageID, wp, theme) {
22
+ const baseUrl = 'https://widgets.crosstalk.cc/chat';
23
+ const params = new URLSearchParams();
24
+ params.append('wp', wp);
25
+ if (url)
26
+ params.append('url', url);
27
+ else if (pageID)
28
+ params.append('pageID', pageID);
29
+ if (theme)
30
+ params.append('theme', theme);
31
+ return `${baseUrl}?${params.toString()}`;
32
+ }
33
33
  function periodicChecks(obj, btnID, isEntity, wp) {
34
34
  const btn = document.getElementById(btnID);
35
35
  if (isEntity)
@@ -51,73 +51,74 @@ function periodicChecks(obj, btnID, isEntity, wp) {
51
51
  }));
52
52
  }, 7000);
53
53
  }
54
- function newGChat(obj, parentDiv, wp, theme) {
55
- const chatHolder = document.createElement("div");
56
- chatHolder.setAttribute("style", "margin-right: 5px");
57
- let pageHash = "";
58
- let isEntity = false;
59
- if (obj.pageID != null && obj.pageID != undefined && obj.pageID != "") {
60
- isEntity = true;
61
- pageHash = createHash(obj.pageID);
62
- }
63
- else if (obj.url != null && obj.url != undefined && obj.url != "")
64
- pageHash = createHash(obj.url);
65
- const iframe = document.createElement("iframe");
66
- const mainChatID = `id_${wp}_${pageHash}`;
67
- iframe.id = mainChatID;
68
- iframe.src = buildIframeUrl(obj, wp, theme);
69
- iframe.setAttribute("class", "crosstalk_frame");
70
- iframe.sandbox = "allow-storage-access-by-user-activation allow-scripts allow-same-origin allow-popups";
71
- iframe.setAttribute("scrolling", "auto");
72
- chatHolder.appendChild(iframe);
73
- const chatShowHideButton = document.createElement("span");
74
- if (theme == 'light')
75
- chatShowHideButton.setAttribute("class", "crosstalk_btn");
76
- else
77
- chatShowHideButton.setAttribute("class", "crosstalk_btn dark");
78
- const onlineSpan = document.createElement("span");
79
- onlineSpan.setAttribute("class", "crosstalk_online");
80
- onlineSpan.innerText = "●";
81
- chatShowHideButton.appendChild(onlineSpan);
82
- const buttonName = document.createElement("span");
83
- buttonName.innerHTML = `<b class='crosstalk_btnTxt'>${obj.title}</b>`;
84
- buttonName.id = `online_${wp}_${pageHash}`;
85
- chatShowHideButton.onclick = function (ev) {
86
- const mainIframe = document.getElementById(mainChatID);
87
- if (mainIframe.style.display === "block") {
88
- mainIframe.style.display = "none";
89
- chatShowHideButton.style.width = "200px";
90
- chatShowHideButton.style.borderTopLeftRadius = "5px";
91
- chatShowHideButton.style.borderTopRightRadius = "5px";
54
+ export class CrossTalkTabbedChatEmbed {
55
+ newTabbedGChat(obj, parentDiv, wp, theme) {
56
+ const chatHolder = document.createElement("div");
57
+ chatHolder.setAttribute("style", "margin-right: 5px");
58
+ let pageHash = "";
59
+ let isEntity = false;
60
+ if (obj.pageID != null && obj.pageID != undefined && obj.pageID != "") {
61
+ isEntity = true;
62
+ pageHash = createHash(obj.pageID);
92
63
  }
93
- else {
94
- mainIframe.style.display = "block";
95
- chatShowHideButton.style.width = "400px";
96
- chatShowHideButton.style.borderTopLeftRadius = "0px";
97
- chatShowHideButton.style.borderTopRightRadius = "0px";
64
+ else if (obj.url != null && obj.url != undefined && obj.url != "")
65
+ pageHash = createHash(obj.url);
66
+ const iframe = document.createElement("iframe");
67
+ const mainChatID = `id_${wp}_${pageHash}`;
68
+ iframe.id = mainChatID;
69
+ iframe.src = buildIframeUrl(obj.url, obj.pageID, wp, theme);
70
+ iframe.setAttribute("class", "crosstalk_frame");
71
+ iframe.sandbox = "allow-storage-access-by-user-activation allow-scripts allow-same-origin allow-popups";
72
+ iframe.setAttribute("scrolling", "auto");
73
+ chatHolder.appendChild(iframe);
74
+ const chatShowHideButton = document.createElement("span");
75
+ if (theme == 'light')
76
+ chatShowHideButton.setAttribute("class", "crosstalk_btn");
77
+ else
78
+ chatShowHideButton.setAttribute("class", "crosstalk_btn dark");
79
+ const onlineSpan = document.createElement("span");
80
+ onlineSpan.setAttribute("class", "crosstalk_online");
81
+ onlineSpan.innerText = "●";
82
+ chatShowHideButton.appendChild(onlineSpan);
83
+ const buttonName = document.createElement("span");
84
+ buttonName.innerHTML = `<b class='crosstalk_btnTxt'>${obj.title}</b>`;
85
+ buttonName.id = `online_${wp}_${pageHash}`;
86
+ chatShowHideButton.onclick = function (ev) {
87
+ const mainIframe = document.getElementById(mainChatID);
88
+ if (mainIframe.style.display === "block") {
89
+ mainIframe.style.display = "none";
90
+ chatShowHideButton.style.width = "200px";
91
+ chatShowHideButton.style.borderTopLeftRadius = "5px";
92
+ chatShowHideButton.style.borderTopRightRadius = "5px";
93
+ }
94
+ else {
95
+ mainIframe.style.display = "block";
96
+ chatShowHideButton.style.width = "400px";
97
+ chatShowHideButton.style.borderTopLeftRadius = "0px";
98
+ chatShowHideButton.style.borderTopRightRadius = "0px";
99
+ }
100
+ };
101
+ chatShowHideButton.appendChild(buttonName);
102
+ chatShowHideButton.id = `button_${mainChatID}`;
103
+ chatHolder.appendChild(chatShowHideButton);
104
+ parentDiv.appendChild(chatHolder);
105
+ if (obj.collapsed == true) {
106
+ const mainIframe = document.getElementById(mainChatID);
107
+ mainIframe.style.visibility = "hidden";
108
+ mainIframe.style.pointerEvents = "none";
109
+ setTimeout(() => {
110
+ mainIframe.style.display = "none";
111
+ mainIframe.style.visibility = "visible";
112
+ mainIframe.style.pointerEvents = "auto";
113
+ chatShowHideButton.style.width = "200px";
114
+ chatShowHideButton.style.borderTopLeftRadius = "5px";
115
+ chatShowHideButton.style.borderTopRightRadius = "5px";
116
+ }, 3000);
98
117
  }
99
- };
100
- chatShowHideButton.appendChild(buttonName);
101
- chatShowHideButton.id = `button_${mainChatID}`;
102
- chatHolder.appendChild(chatShowHideButton);
103
- parentDiv.appendChild(chatHolder);
104
- if (obj.collapsed == true) {
105
- const mainIframe = document.getElementById(mainChatID);
106
- mainIframe.style.visibility = "hidden";
107
- mainIframe.style.pointerEvents = "none";
108
- setTimeout(() => {
109
- mainIframe.style.display = "none";
110
- mainIframe.style.visibility = "visible";
111
- mainIframe.style.pointerEvents = "auto";
112
- chatShowHideButton.style.width = "200px";
113
- chatShowHideButton.style.borderTopLeftRadius = "5px";
114
- chatShowHideButton.style.borderTopRightRadius = "5px";
115
- }, 3000);
118
+ periodicChecks(obj, `online_${wp}_${pageHash}`, isEntity, wp);
116
119
  }
117
- periodicChecks(obj, `online_${wp}_${pageHash}`, isEntity, wp);
118
- }
119
- export class CrossTalkChatEmbed {
120
- render() {
120
+ constructor(config) {
121
+ this.config = config;
121
122
  const link = document.createElement('link');
122
123
  link.rel = 'stylesheet';
123
124
  link.href = 'https://widgets.crosstalk.cc/tab_livechat.css';
@@ -128,17 +129,47 @@ export class CrossTalkChatEmbed {
128
129
  parentDiv.id = "crosstalkChatHolder";
129
130
  document.body.appendChild(parentDiv);
130
131
  }
132
+ parentDiv.setAttribute("class", "crosstalk_parent");
131
133
  if (!this.config.theme)
132
134
  this.config.theme = "light";
133
135
  this.config.pageIDs.forEach(pageID => {
134
- newGChat(pageID, parentDiv, this.config.wp, this.config.theme);
136
+ this.newTabbedGChat(pageID, parentDiv, this.config.wp, this.config.theme);
135
137
  });
136
138
  }
137
- constructor(config) {
139
+ }
140
+ export class CrossTalkChatEmbed {
141
+ render() {
142
+ this.container.innerHTML = '';
143
+ this.iframe = document.createElement('iframe');
144
+ this.iframe.src = buildIframeUrl(this.config.url, this.config.pageID, this.config.wp, this.config.theme);
145
+ this.iframe.setAttribute("style", "width: 100%; scrollbar-width:thin !important; min-width: 300px; min-height: 480px;");
146
+ this.iframe.setAttribute("frameborder", "0");
147
+ this.iframe.sandbox = "allow-storage-access-by-user-activation allow-scripts allow-same-origin allow-popups";
148
+ this.container.appendChild(this.iframe);
149
+ }
150
+ constructor(container, config) {
151
+ this.container = container;
138
152
  this.config = config;
153
+ this.iframe = null;
154
+ this.render();
155
+ }
156
+ update(config) {
157
+ this.config = Object.assign(Object.assign({}, this.config), config);
139
158
  this.render();
140
159
  }
160
+ destroy() {
161
+ if (this.iframe && this.iframe.parentNode) {
162
+ this.iframe.parentNode.removeChild(this.iframe);
163
+ this.iframe = null;
164
+ }
165
+ }
166
+ getIframe() {
167
+ return this.iframe;
168
+ }
169
+ }
170
+ export function initTabbedChats(config) {
171
+ return new CrossTalkTabbedChatEmbed(config);
141
172
  }
142
- export function initChats(config) {
143
- return new CrossTalkChatEmbed(config);
173
+ export function initChat(container, config) {
174
+ return new CrossTalkChatEmbed(container, config);
144
175
  }
package/dist/index.d.ts CHANGED
@@ -2,5 +2,5 @@ export { CrossTalkCommentsEmbed, initComments } from './CrossTalkCommentsEmbed';
2
2
  export { CrossTalkVideoPlayerEmbed, initPlayer } from './CrossTalkVideoPlayerEmbed';
3
3
  export { CrossTalkPollEmbed, initPoll } from './CrossTalkPollEmbed';
4
4
  export { CrossTalkAISummaryEmbed, initAISummary } from './CrossTalkAISummaryEmbed';
5
- export { CrossTalkChatEmbed, initChats } from './CrossTalkLiveChatEmbed';
5
+ export { CrossTalkTabbedChatEmbed, initTabbedChats, CrossTalkChatEmbed, initChat } from './CrossTalkLiveChatEmbed';
6
6
  export type { CommentsEmbedOptions, VideoPlayerEmbedOptions, PollEmbedOptions, AISummaryOptions, ChatOptions, ChatPageOptions } from './types';
package/dist/index.js CHANGED
@@ -3,4 +3,4 @@ export { CrossTalkCommentsEmbed, initComments } from './CrossTalkCommentsEmbed';
3
3
  export { CrossTalkVideoPlayerEmbed, initPlayer } from './CrossTalkVideoPlayerEmbed';
4
4
  export { CrossTalkPollEmbed, initPoll } from './CrossTalkPollEmbed';
5
5
  export { CrossTalkAISummaryEmbed, initAISummary } from './CrossTalkAISummaryEmbed';
6
- export { CrossTalkChatEmbed, initChats } from './CrossTalkLiveChatEmbed';
6
+ export { CrossTalkTabbedChatEmbed, initTabbedChats, CrossTalkChatEmbed, initChat } from './CrossTalkLiveChatEmbed';
package/dist/types.d.ts CHANGED
@@ -35,4 +35,8 @@ export interface ChatOptions {
35
35
  theme?: string;
36
36
  pageIDs?: ChatPageOptions[];
37
37
  }
38
+ export interface ChatOption extends ChatPageOptions {
39
+ wp?: string;
40
+ theme?: string;
41
+ }
38
42
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "crosstalk-comments-livechat-sdk",
3
- "version": "0.0.6-beta.4",
3
+ "version": "0.0.6-beta.6",
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",