Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
| vendors:cisco:uc:ece:custom-buttons [2026/02/11 16:46] – gerardorourke | vendors:cisco:uc:ece:custom-buttons [2026/02/25 15:54] (current) – [page1.html] gerardorourke | ||
|---|---|---|---|
| Line 5: | Line 5: | ||
| Or perhaps you want to check business hours or availability and only show the button then, but NOT if the chat has just been minimized. | Or perhaps you want to check business hours or availability and only show the button then, but NOT if the chat has just been minimized. | ||
| - | This can be achieved using the below JS code - which can trigger on minimized, maximized (to clear / bring it back to default) and also for messages when sent when minimized (and how many messages are unread / i.e. the badge number - which appears on the out of the box floating roundel when minimized). | + | The below sample proof of concept |
| - | I also included a audio alert when minimized. | + | * show / hide button when chat form is minimized / maximized |
| + | * play an audio alert when a new message arrives if chat form is minimized | ||
| + | * show number of unread messages if chat form is minimized. | ||
| - | < | + | ==== Simple JS - showing the Event Listener and relevant events ==== |
| + | |||
| + | < | ||
| <script language=javascript> | <script language=javascript> | ||
| window.addEventListener(" | window.addEventListener(" | ||
| Line 27: | Line 31: | ||
| alert(" | alert(" | ||
| } | } | ||
| + | | ||
| + | // Detect Close Chat (this is only needed on pages, where chat can be initiated) | ||
| + | if (data.Caller === " | ||
| + | alert(" | ||
| + | } | ||
| // Detect badge count update (where greater than 0) | // Detect badge count update (where greater than 0) | ||
| if (data.Caller === " | if (data.Caller === " | ||
| if (data.Value> | if (data.Value> | ||
| - | var sound = new Audio(" | ||
| alert(" | alert(" | ||
| } | } | ||
| Line 44: | Line 52: | ||
| - | ==== Really | + | ==== A Simple |
| - | Chat would only be initiated from main page - but if it was active - it would be available on Page1 - and a custom button | + | Chat is only be initiated from the 'main' |
| - | <code index.html> | + | This code also includes code for the screen reader - if the chat is minimized - it informs the user that a chat message has been received and the number of unread messages. |
| + | |||
| + | <file javascript | ||
| < | < | ||
| < | < | ||
| - | < | + | < |
| </ | </ | ||
| < | < | ||
| + | <!-- Start of CSS and HTML code for Screen Reader --> | ||
| + | < | ||
| + | .visually-hidden { | ||
| + | position: absolute; | ||
| + | width: 1px; | ||
| + | height: 1px; | ||
| + | padding: 0; | ||
| + | margin: -1px; | ||
| + | overflow: hidden; | ||
| + | clip: rect(0, 0, 0, 0); | ||
| + | white-space: | ||
| + | border: 0; | ||
| + | } | ||
| + | </ | ||
| + | <div id=" | ||
| + | <!-- End of CSS and HTML code for Screen Reader --> | ||
| + | |||
| + | <!-- Start of HTML code for Brief Intro and Chat Button --> | ||
| < | < | ||
| < | < | ||
| < | < | ||
| + | <!-- End of HTML code for Brief Intro and Chat Button --> | ||
| <!-- Configuration for a specific Chat Entrypoint, which sets the EntryPointId, | <!-- Configuration for a specific Chat Entrypoint, which sets the EntryPointId, | ||
| Line 111: | Line 140: | ||
| <script language=javascript> | <script language=javascript> | ||
| function showChatButton() { | function showChatButton() { | ||
| - | | + | |
| } | } | ||
| function hideChatButton() { | function hideChatButton() { | ||
| - | | + | |
| } | } | ||
| - | |||
| window.addEventListener(" | window.addEventListener(" | ||
| Line 123: | Line 151: | ||
| const data = JSON.parse(event.data); | const data = JSON.parse(event.data); | ||
| - | // This shows all ECE events to console (so disable / comment out this console output in production) | + | |
| - | console.log(" | + | console.log(" |
| // Detect minimize | // Detect minimize | ||
| Line 131: | Line 159: | ||
| } | } | ||
| - | // Detect | + | // Detect |
| if (data.Caller === " | if (data.Caller === " | ||
| - | hideChatButton(); | + | |
| + | // Screen reader announcement | ||
| + | var announcer = document.getElementById(" | ||
| + | announcer.textContent = ""; | ||
| } | } | ||
| - | // Detect badge count update | + | |
| + | if (data.Caller === " | ||
| + | showChatButton(); | ||
| + | } | ||
| + | |||
| + | | ||
| if (data.Caller === " | if (data.Caller === " | ||
| - | | + | var unread = data.Value; |
| - | // Note - download this audio file and host on your own webserver - in case the URL changes following a ECE update | + | if (unread > 0) { |
| - | var sound = new Audio("https:// | + | |
| + | var announcer = document.getElementById(" | ||
| + | if (unread === 1) { | ||
| + | // Screen reader announcement | ||
| + | | ||
| + | } else { | ||
| + | announcer.textContent = "Chat message received. You have " + unread + " unread messages."; | ||
| + | } | ||
| + | } | ||
| } | } | ||
| Line 154: | Line 198: | ||
| </ | </ | ||
| </ | </ | ||
| - | </code> | + | </file> |
| ==== page1.html==== | ==== page1.html==== | ||
| - | <code> | + | <file javascript page1.html> |
| < | < | ||
| < | < | ||
| - | < | + | < |
| </ | </ | ||
| < | < | ||
| + | <!-- Start of CSS and HTML code for Screen Reader --> | ||
| + | < | ||
| + | .visually-hidden { | ||
| + | position: absolute; | ||
| + | width: 1px; | ||
| + | height: 1px; | ||
| + | padding: 0; | ||
| + | margin: -1px; | ||
| + | overflow: hidden; | ||
| + | clip: rect(0, 0, 0, 0); | ||
| + | white-space: | ||
| + | border: 0; | ||
| + | } | ||
| + | </ | ||
| + | <div id=" | ||
| + | <!-- End of CSS and HTML code for Screen Reader --> | ||
| - | < | + | <!-- Start of HTML code for Brief Intro and Chat Button (which is DISABLED by default as this is a page where chat is NOT initiated from --> |
| - | < | + | <p>Hello. |
| - | < | + | < |
| + | < | ||
| + | <!-- End of HTML code for Brief Intro and Chat Button --> | ||
| - | <!-- Basic Configuration for Chat without referencing any specific entry point - so if a chat is active | + | <!-- Basic Configuration for a Chat Entrypoint |
| - | < | + | < |
| + | /*eGain Chat server */ | ||
| var egainDockChat = egainDockChat | var egainDockChat = egainDockChat | ||
| egainDockChat.UseCustomButton=true; | egainDockChat.UseCustomButton=true; | ||
| - | |||
| egainDockChat.openHelp = function(){ | egainDockChat.openHelp = function(){ | ||
| egainDockChat.IsChatLaunched = true; | egainDockChat.IsChatLaunched = true; | ||
| startChat(); | startChat(); | ||
| } | } | ||
| - | |||
| if(!egainDockChat.UseCustomButton){ | if(!egainDockChat.UseCustomButton){ | ||
| startChat(); | startChat(); | ||
| } | } | ||
| - | |||
| function startChat(){ | function startChat(){ | ||
| if(!egainDockChat.launchChat){ | if(!egainDockChat.launchChat){ | ||
| Line 211: | Line 270: | ||
| const data = JSON.parse(event.data); | const data = JSON.parse(event.data); | ||
| - | // This shows all ECE events to console (so disable / comment out this console output in production) | + | // This shows all ECE events to console (so disable / comment out this console output in production) |
| - | console.log(" | + | console.log(" |
| // Detect minimize | // Detect minimize | ||
| if (data.Caller === " | if (data.Caller === " | ||
| - | | + | showChatButton(); |
| } | } | ||
| - | // Detect | + | // Detect |
| if (data.Caller === " | if (data.Caller === " | ||
| - | hideChatButton(); | + | hideChatButton(); |
| + | // Clear Screen reader announcement Text | ||
| + | var announcer = document.getElementById(" | ||
| + | announcer.textContent = ""; | ||
| } | } | ||
| - | // Detect badge count update | + | // Detect badge count update |
| if (data.Caller === " | if (data.Caller === " | ||
| - | | + | var unread = data.Value; |
| - | // Note - download this audio file and host on your own webserver - in case the URL changes following a ECE update | + | if (unread > 0) { |
| - | var sound = new Audio("https:// | + | |
| + | var announcer = document.getElementById(" | ||
| + | if (unread === 1) { | ||
| + | // Screen reader announcement | ||
| + | | ||
| + | } else { | ||
| + | announcer.textContent = "Chat message received. You have " + unread + " unread messages."; | ||
| + | } | ||
| + | } | ||
| } | } | ||
| Line 236: | Line 307: | ||
| }); | }); | ||
| </ | </ | ||
| - | |||
| <!-- Cisco Provided ECE JavaScript - required for docked chat --> | <!-- Cisco Provided ECE JavaScript - required for docked chat --> | ||
| Line 243: | Line 313: | ||
| </ | </ | ||
| </ | </ | ||
| - | </code> | + | </file> |