11<script >
2- import { fade } from ' svelte/transition' ;
3- import { onMount } from ' svelte' ;
4- import { PUBLIC_LIVECHAT_HOST , PUBLIC_LIVECHAT_ENTRY_ICON } from ' $env/static/public' ;
5- import { getSettingDetail } from ' $lib/services/setting-service' ;
2+ import { fade } from ' svelte/transition' ;
3+ import { onMount } from ' svelte' ;
4+ import { PUBLIC_LIVECHAT_HOST , PUBLIC_LIVECHAT_ENTRY_ICON } from ' $env/static/public' ;
5+ import { getSettingDetail } from ' $lib/services/setting-service' ;
66
7- let showChatIcon = false ;
8- let showChatBox = false ;
9- let chatUrl = PUBLIC_LIVECHAT_HOST ;
7+ let showChatIcon = false ;
8+ let showChatBox = false ;
9+ let chatUrl = PUBLIC_LIVECHAT_HOST ;
1010
11- onMount (async () => {
12- const agentSettings = await getSettingDetail (" Agent" );
13- chatUrl = ` ${ PUBLIC_LIVECHAT_HOST } chat/${ agentSettings .hostAgentId } ?isFrame=true` ;
14- showChatIcon = true ;
15- });
11+ onMount (async () => {
12+ const agentSettings = await getSettingDetail (" Agent" );
13+ chatUrl = ` ${ PUBLIC_LIVECHAT_HOST } chat/${ agentSettings .hostAgentId } ?isFrame=true` ;
14+ showChatIcon = true ;
15+ });
1616
17- // Handle event from iframe
18- window .onmessage = async function (e ) {
19- if (e .data .action == ' close' ) {
20- showChatIcon = true ;
21- showChatBox = false ;
22- }
23- };
17+ // Handle event from iframe
18+ window .onmessage = async function (e ) {
19+ if (e .data .action == ' close' ) {
20+ showChatIcon = true ;
21+ showChatBox = false ;
22+ }
23+ };
2424
25- function handleChatBox () {
26- showChatIcon = false ;
27- showChatBox = true ;
28- }
25+ function handleChatBox () {
26+ showChatIcon = false ;
27+ showChatBox = true ;
28+ }
2929 </script >
3030
3131<div class =" fixed-bottom float-bottom-right" >
32- {#if showChatBox }
33- <div transition:fade ={{ delay : 250 , duration : 300 }}>
34- <iframe
35- src ={chatUrl }
36- width =" 380px"
37- height =" 650px"
38- class =" border border-2 rounded-3 m-3 float-end chat-iframe"
39- title =" live chat"
40- >
41- </iframe >
42- </div >
43- {/if }
32+ {#if showChatBox }
33+ <div transition:fade ={{ delay : 250 , duration : 300 }}>
34+ <iframe
35+ src ={chatUrl }
36+ width =" 380px"
37+ height =" 650px"
38+ class =" border border-2 rounded-3 m-3 float-end chat-iframe"
39+ title =" live chat"
40+ id =" chat-frame"
41+ >
42+ </iframe >
43+ </div >
44+ {/if }
4445
45- {#if showChatIcon }
46- <div class ="mb-3 float-end wave-effect" transition:fade ={{ delay : 100 , duration : 500 }}>
47- <button class ="btn btn-transparent" on:click ={handleChatBox }>
48- <img alt ="live chat" class ="avatar-md rounded-circle" src ={PUBLIC_LIVECHAT_ENTRY_ICON } />
49- </button >
50- </div >
51- {/if }
46+ {#if showChatIcon }
47+ <div class ="mb-3 float-end wave-effect" transition:fade ={{ delay : 100 , duration : 500 }}>
48+ <button class ="btn btn-transparent" on:click ={() => handleChatBox () }>
49+ <img alt ="live chat" class ="avatar-md rounded-circle" src ={PUBLIC_LIVECHAT_ENTRY_ICON } />
50+ </button >
51+ </div >
52+ {/if }
5253</div >
5354
5455<style >
55- .wave-effect :hover {
56- animation : wave 0.82s cubic-bezier (.36 ,.07 ,.19 ,.97 ) both ;
57- transform : translate3d (0 , 0 , 0 );
58- backface-visibility : hidden ;
59- perspective : 1000px ;
60- }
61-
62- @keyframes wave {
63- 10% , 90% {
64- transform : translate3d (-1px , 0 , 0 );
65- }
66-
67- 20% , 80% {
68- transform : translate3d (2px , 0 , 0 );
56+ .wave-effect :hover {
57+ animation : wave 0.82s cubic-bezier (.36 ,.07 ,.19 ,.97 ) both ;
58+ transform : translate3d (0 , 0 , 0 );
59+ backface-visibility : hidden ;
60+ perspective : 1000px ;
6961 }
7062
71- 30% , 50% , 70% {
72- transform : translate3d (-4px , 0 , 0 );
73- }
63+ @keyframes wave {
64+ 10% , 90% {
65+ transform : translate3d (-1px , 0 , 0 );
66+ }
67+
68+ 20% , 80% {
69+ transform : translate3d (2px , 0 , 0 );
70+ }
7471
75- 40% , 60% {
76- transform : translate3d (4px , 0 , 0 );
72+ 30% , 50% , 70% {
73+ transform : translate3d (-4px , 0 , 0 );
74+ }
75+
76+ 40% , 60% {
77+ transform : translate3d (4px , 0 , 0 );
78+ }
7779 }
78- }
7980
80- .float-bottom-right {
81- width : fit-content ;
82- margin-right : 0px ;
83- margin-left : auto ;
84- }
81+ .float-bottom-right {
82+ width : fit-content ;
83+ margin-right : 0px ;
84+ margin-left : auto ;
85+ }
8586 </style >
0 commit comments