Skip to content

Commit 53b77b0

Browse files
committed
Minimize chat window while an active chat when clicking X, Prevent default behavior to close the connection while chatting by accident
1 parent edc0435 commit 53b77b0

File tree

7 files changed

+63
-7
lines changed

7 files changed

+63
-7
lines changed

assets/js/shared/chat.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,58 @@ jQuery(function initForm($) {
164164
// Close the session
165165
return chat.sessionClose();
166166
};
167+
168+
// Toggle/minimize chat window instead of closing connection
169+
chat.toggle = (event) => {
170+
if (chat.isOpen) {
171+
zammadDebugMessage('Close or Minimize');
172+
return chat.maybeMinimize(event);
173+
}
174+
zammadDebugMessage('Open');
175+
return chat.open(event);
176+
};
177+
178+
// Adds a minimize functionality
179+
chat.maybeMinimize = (event) => {
180+
zammadDebugMessage(
181+
'Minimize or close chat window, depending on chat status.',
182+
);
183+
184+
// If there is no session ID OR waiting in queue OR no messages yet, we close the window and end connection
185+
if (!chat.sessionId || chat.inQueue || !chat.lastAddedType) {
186+
// Close chat as it is the default
187+
zammadDebugMessage('Close chat.');
188+
return chat.close(event);
189+
}
190+
191+
// Otherwise we proceed to minimize
192+
zammadDebugMessage('Minimize running chat.');
193+
194+
const remainerHeight =
195+
chat.el.height() - chat.el.find('.zammad-chat-header').outerHeight();
196+
197+
return chat.el.animate(
198+
{
199+
bottom: -remainerHeight,
200+
},
201+
500,
202+
function minimizeChatWindow() {
203+
chat.el.css('bottom', '');
204+
chat.el.removeClass('zammad-chat-is-open');
205+
chat.isOpen = false;
206+
chat.isMinimized = true;
207+
},
208+
);
209+
};
210+
211+
// Extends function scrollToBottom( to open minimized chat window if new message arrives
212+
chat.originalScrollToBottom = chat.scrollToBottom;
213+
chat.scrollToBottom = (arg) => {
214+
if (chat.isMinimized && !chat.isOpen) {
215+
chat.open();
216+
}
217+
chat.originalScrollToBottom(arg);
218+
};
167219
} else if (!form.length) {
168220
zammadDebugMessage('The Fallback Form is missing. Maybe a caching issue?');
169221
}

dist/js/chat.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

includes/functions/chat.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ function zammad_init_chat($chat_id = 1, $args = array())
7878
'loaderWaitingMessage' => '',
7979
'waitingListWaitingMessage' => __('Sorry for the delay, still connecting.', 'zammad-wp'),
8080
'waitingListTimeoutMessage' => sprintf(
81-
// translators: Placeholder is "click here" link text
81+
// translators: Placeholder is "click here" link text
8282
__(
8383
'We do not want to let you wait anytime longer. Please feel free to use the form instead or <a class="js-restart" href="#restart">%s</a> to try again.',
8484
'zammad-wp'

includes/functions/form.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ function zammad_init_form($form_element = '#feedback-form', $args = array())
5252
);
5353

5454
// Localize Script
55-
wp_add_inline_script('zammad_wp_form', 'const formOptions =' . json_encode( wp_parse_args($args, $defaults), JSON_UNESCAPED_UNICODE ), 'before');
55+
wp_add_inline_script('zammad_wp_form', 'const formOptions =' . json_encode(wp_parse_args($args, $defaults), JSON_UNESCAPED_UNICODE), 'before');
5656

5757
// Enqueue styles
5858
wp_enqueue_style('zammad_wp_form');

plugin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*/
1414

1515
// Useful global constants.
16-
define('ZAMMAD_WP_VERSION', '0.5.0');
16+
define('ZAMMAD_WP_VERSION', '0.6.0');
1717
define('ZAMMAD_WP_URL', plugin_dir_url(__FILE__));
1818
define('ZAMMAD_WP_PATH', plugin_dir_path(__FILE__));
1919
define('ZAMMAD_WP_INC', ZAMMAD_WP_PATH . 'includes/');

readme.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ Contributors: werepack, philippmuenchen
33
Donate link: https://www.paypal.me/ouun
44
Tags: zammad, live-chat, ticketing, forms, feedback
55
Requires at least: 4.5
6-
Tested up to: 5.5
7-
Stable tag: 0.5.0
6+
Tested up to: 5.5.1
7+
Stable tag: 0.6.0
88

99
This plugin helps you embed Zammad Chats & Forms into your WordPress site and gives you access to the Zammad API if required.
1010

@@ -25,6 +25,10 @@ Use `composer require ouun/zammad-wp` to install
2525

2626
== Changelog ==
2727

28+
= 0.6.0 =
29+
* Minimize chat window while an active chat when clicking X
30+
* Prevent default behavior to close the connection while chatting by accident
31+
2832
= 0.5.0 =
2933
* Adds more options to set custom messages
3034

script.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
/**
2-
* 10up Scaffold
2+
* Zammad for Wordpress Scaffold
33
*/

0 commit comments

Comments
 (0)