@product7/product7-js 0.7.3 → 0.7.5
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.
- package/dist/product7-js.js +77 -12
- package/dist/product7-js.js.map +1 -1
- package/dist/product7-js.min.js +1 -1
- package/dist/product7-js.min.js.map +1 -1
- package/package.json +1 -1
- package/src/widgets/LiveChatWidget.js +47 -5
- package/src/widgets/liveChat/LiveChatState.js +1 -0
- package/src/widgets/liveChat/views/PreChatFormView.js +30 -8
package/dist/product7-js.js
CHANGED
|
@@ -8956,6 +8956,7 @@
|
|
|
8956
8956
|
this.messagesModuleEnabled = options.messagesModuleEnabled !== false;
|
|
8957
8957
|
|
|
8958
8958
|
this.requireEmailBeforeChat = options.requireEmailBeforeChat || false;
|
|
8959
|
+
this.allowAnonymousChat = options.allowAnonymousChat !== false;
|
|
8959
8960
|
this.allowAttachments = options.allowAttachments !== false;
|
|
8960
8961
|
this.allowEmoji = options.allowEmoji !== false;
|
|
8961
8962
|
this.showReplyTime = options.showReplyTime !== false;
|
|
@@ -11758,20 +11759,31 @@
|
|
|
11758
11759
|
return this.element;
|
|
11759
11760
|
}
|
|
11760
11761
|
|
|
11762
|
+
_isNameRequired() {
|
|
11763
|
+
return this.state.allowAnonymousChat === false;
|
|
11764
|
+
}
|
|
11765
|
+
|
|
11761
11766
|
_updateContent() {
|
|
11767
|
+
const nameRequired = this._isNameRequired();
|
|
11768
|
+
const namePlaceholder = nameRequired ? 'Your name' : 'Your name (optional)';
|
|
11769
|
+
const subtitle = nameRequired
|
|
11770
|
+
? 'Enter your name and email so we can get back to you.'
|
|
11771
|
+
: 'Enter your email so we can get back to you.';
|
|
11772
|
+
|
|
11762
11773
|
this.element.innerHTML = `
|
|
11763
11774
|
<div class="liveChat-prechat-overlay">
|
|
11764
11775
|
<div class="liveChat-prechat-card">
|
|
11765
11776
|
<h4 class="liveChat-prechat-title">Before we continue</h4>
|
|
11766
|
-
<p class="liveChat-prechat-subtitle"
|
|
11777
|
+
<p class="liveChat-prechat-subtitle">${subtitle}</p>
|
|
11767
11778
|
<form class="liveChat-prechat-form" novalidate>
|
|
11768
11779
|
<div class="liveChat-prechat-field">
|
|
11769
11780
|
<input
|
|
11770
11781
|
type="text"
|
|
11771
11782
|
name="name"
|
|
11772
11783
|
class="liveChat-prechat-input"
|
|
11773
|
-
placeholder="
|
|
11784
|
+
placeholder="${namePlaceholder}"
|
|
11774
11785
|
autocomplete="name"
|
|
11786
|
+
${nameRequired ? 'required' : ''}
|
|
11775
11787
|
/>
|
|
11776
11788
|
</div>
|
|
11777
11789
|
<div class="liveChat-prechat-field">
|
|
@@ -11783,8 +11795,8 @@
|
|
|
11783
11795
|
autocomplete="email"
|
|
11784
11796
|
required
|
|
11785
11797
|
/>
|
|
11786
|
-
<span class="liveChat-prechat-error" style="display:none;"></span>
|
|
11787
11798
|
</div>
|
|
11799
|
+
<span class="liveChat-prechat-error" style="display:none;"></span>
|
|
11788
11800
|
<button type="submit" class="liveChat-prechat-submit">
|
|
11789
11801
|
Start chat
|
|
11790
11802
|
</button>
|
|
@@ -11804,6 +11816,15 @@
|
|
|
11804
11816
|
});
|
|
11805
11817
|
}
|
|
11806
11818
|
|
|
11819
|
+
_validate(nameRequired, name, email) {
|
|
11820
|
+
if (nameRequired && !name) return { msg: 'Please enter your name.', field: 'name' };
|
|
11821
|
+
if (!email) return { msg: 'Please enter your email address.', field: 'email' };
|
|
11822
|
+
if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) {
|
|
11823
|
+
return { msg: 'Please enter a valid email address.', field: 'email' };
|
|
11824
|
+
}
|
|
11825
|
+
return null;
|
|
11826
|
+
}
|
|
11827
|
+
|
|
11807
11828
|
async _handleSubmit() {
|
|
11808
11829
|
if (this._isSubmitting) return;
|
|
11809
11830
|
|
|
@@ -11814,11 +11835,13 @@
|
|
|
11814
11835
|
|
|
11815
11836
|
const email = emailInput.value.trim();
|
|
11816
11837
|
const name = nameInput.value.trim();
|
|
11838
|
+
const nameRequired = this._isNameRequired();
|
|
11817
11839
|
|
|
11818
|
-
|
|
11819
|
-
|
|
11840
|
+
const error = this._validate(nameRequired, name, email);
|
|
11841
|
+
if (error) {
|
|
11842
|
+
errorEl.textContent = error.msg;
|
|
11820
11843
|
errorEl.style.display = 'block';
|
|
11821
|
-
emailInput.focus();
|
|
11844
|
+
(error.field === 'name' ? nameInput : emailInput).focus();
|
|
11822
11845
|
return;
|
|
11823
11846
|
}
|
|
11824
11847
|
|
|
@@ -11834,7 +11857,7 @@
|
|
|
11834
11857
|
if (this.options.onIdentifyContact) {
|
|
11835
11858
|
await this.options.onIdentifyContact({
|
|
11836
11859
|
name: name || undefined,
|
|
11837
|
-
email,
|
|
11860
|
+
email: email || undefined,
|
|
11838
11861
|
});
|
|
11839
11862
|
}
|
|
11840
11863
|
|
|
@@ -12130,10 +12153,7 @@
|
|
|
12130
12153
|
|
|
12131
12154
|
async _handleStartConversation(messageContent, pendingAttachments) {
|
|
12132
12155
|
try {
|
|
12133
|
-
if (
|
|
12134
|
-
this.LiveChatState.requireEmailBeforeChat &&
|
|
12135
|
-
!this.LiveChatState.isIdentified
|
|
12136
|
-
) {
|
|
12156
|
+
if (!this.LiveChatState.isIdentified) {
|
|
12137
12157
|
this.LiveChatState.pendingMessage = {
|
|
12138
12158
|
content: messageContent,
|
|
12139
12159
|
attachments: pendingAttachments,
|
|
@@ -12831,9 +12851,15 @@
|
|
|
12831
12851
|
this.liveChatOptions.textColor = s.text_color;
|
|
12832
12852
|
stylesChanged = true;
|
|
12833
12853
|
}
|
|
12834
|
-
|
|
12854
|
+
let themeChanged = false;
|
|
12855
|
+
if (
|
|
12856
|
+
s.theme &&
|
|
12857
|
+
!this._hasExplicitOption('theme') &&
|
|
12858
|
+
s.theme !== this.liveChatOptions.theme
|
|
12859
|
+
) {
|
|
12835
12860
|
this.liveChatOptions.theme = s.theme;
|
|
12836
12861
|
stylesChanged = true;
|
|
12862
|
+
themeChanged = true;
|
|
12837
12863
|
}
|
|
12838
12864
|
if (stylesChanged) {
|
|
12839
12865
|
applyliveChatCustomStyles({
|
|
@@ -12843,6 +12869,9 @@
|
|
|
12843
12869
|
theme: this.liveChatOptions.theme,
|
|
12844
12870
|
});
|
|
12845
12871
|
}
|
|
12872
|
+
if (themeChanged && this._widgetContainer) {
|
|
12873
|
+
this._widgetContainer.className = `liveChat-widget theme-${this.liveChatOptions.theme}`;
|
|
12874
|
+
}
|
|
12846
12875
|
|
|
12847
12876
|
// Launcher position & padding
|
|
12848
12877
|
if (s.launcher_position && !this._hasExplicitOption('position')) {
|
|
@@ -12901,6 +12930,36 @@
|
|
|
12901
12930
|
this.LiveChatState.homeModuleEnabled !== false ? 'home' : 'help';
|
|
12902
12931
|
}
|
|
12903
12932
|
}
|
|
12933
|
+
if (
|
|
12934
|
+
typeof s.help_module_enabled === 'boolean' &&
|
|
12935
|
+
!this._hasExplicitOption('enableHelp')
|
|
12936
|
+
) {
|
|
12937
|
+
this.LiveChatState.enableHelp = s.help_module_enabled;
|
|
12938
|
+
if (
|
|
12939
|
+
!s.help_module_enabled &&
|
|
12940
|
+
this.LiveChatState.currentView === 'help'
|
|
12941
|
+
) {
|
|
12942
|
+
this.LiveChatState.currentView =
|
|
12943
|
+
this.LiveChatState.homeModuleEnabled !== false
|
|
12944
|
+
? 'home'
|
|
12945
|
+
: 'messages';
|
|
12946
|
+
}
|
|
12947
|
+
}
|
|
12948
|
+
if (
|
|
12949
|
+
typeof s.changelog_module_enabled === 'boolean' &&
|
|
12950
|
+
!this._hasExplicitOption('enableChangelog')
|
|
12951
|
+
) {
|
|
12952
|
+
this.LiveChatState.enableChangelog = s.changelog_module_enabled;
|
|
12953
|
+
if (
|
|
12954
|
+
!s.changelog_module_enabled &&
|
|
12955
|
+
this.LiveChatState.currentView === 'changelog'
|
|
12956
|
+
) {
|
|
12957
|
+
this.LiveChatState.currentView =
|
|
12958
|
+
this.LiveChatState.homeModuleEnabled !== false
|
|
12959
|
+
? 'home'
|
|
12960
|
+
: 'messages';
|
|
12961
|
+
}
|
|
12962
|
+
}
|
|
12904
12963
|
|
|
12905
12964
|
// Feature flags
|
|
12906
12965
|
if (
|
|
@@ -12918,6 +12977,12 @@
|
|
|
12918
12977
|
) {
|
|
12919
12978
|
this.LiveChatState.requireEmailBeforeChat = s.require_email_before_chat;
|
|
12920
12979
|
}
|
|
12980
|
+
if (
|
|
12981
|
+
typeof s.allow_anonymous_chat === 'boolean' &&
|
|
12982
|
+
!this._hasExplicitOption('allowAnonymousChat')
|
|
12983
|
+
) {
|
|
12984
|
+
this.LiveChatState.allowAnonymousChat = s.allow_anonymous_chat;
|
|
12985
|
+
}
|
|
12921
12986
|
if (
|
|
12922
12987
|
typeof s.allow_attachments === 'boolean' &&
|
|
12923
12988
|
!this._hasExplicitOption('allowAttachments')
|