PluginProbe
Leyka / 3.17
Leyka v3.17
3.32.3 2.3.2 2.3.3 2.3.4 2.3.5 2.3.6 2.3.6.1 2.3.7 2.3.8 2.3.9 3.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1 3.10 3.11 3.11.1 3.12 3.13 3.14 3.15 3.16 3.17 All 89 releases
leyka / js / settings-helpchat.js

settings-helpchat.js in Leyka 3.17, at js/settings-helpchat.js

121 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1
2 // Help chat:
3 jQuery(document).ready(function($){
4
5 let $chat = $('.help-chat'),
6 $chat_button = $('.help-chat-button'),
7 $loading = $chat.find('.leyka-loader');
8
9 if( !$chat.length ) {
10 return;
11 }
12
13 // function disable_form() {
14 // $chat.find('input[type=text]').prop('disabled', true);
15 // $chat.find('textarea').prop('disabled', true);
16 // $chat.find('.button').hide();
17 // }
18 //
19 // function enable_form() {
20 // $chat.find('input[type=text]').prop('disabled', false);
21 // $chat.find('textarea').prop('disabled', false);
22 // $chat.find('.button').show();
23 // }
24
25 function show_loading() {
26 $loading.show();
27 }
28
29 function hide_loading() {
30 $loading.hide();
31 }
32
33 function show_ok_message() {
34 $chat.find('.ok-message').show();
35 $chat.removeClass('fix-height');
36 }
37
38 function hide_ok_message() {
39 $chat.find('.ok-message').hide();
40 $chat.addClass('fix-height');
41 }
42
43 function show_form() {
44 $chat.find('.form').show();
45 }
46
47 function hide_form() {
48 $chat.find('.form').hide();
49 }
50
51 function validate_form() {
52 return true;
53 }
54
55 function show_help_chat() {
56 $chat_button.hide();
57 $chat.show();
58 }
59
60 function hide_help_chat() {
61 $chat.hide();
62 $chat_button.show();
63 }
64
65 $chat.find('.form').submit(function(e){
66
67 e.preventDefault();
68
69 if(!validate_form()) {
70 return;
71 }
72
73 hide_form();
74 show_loading();
75
76 $.post(leyka.ajaxurl, {
77 action: 'leyka_send_feedback',
78 name: $chat.find('#leyka-help-chat-name').val(),
79 topic: "Сообщение из формы обратной связи Лейки",
80 email: $chat.find('#leyka-help-chat-email').val(),
81 text: $chat.find('#leyka-help-chat-message').val(),
82 nonce: $chat.find('#leyka_feedback_sending_nonce').val()
83 }, null).done(function(response) {
84
85 if(response === '0') {
86 show_ok_message();
87 hide_form();
88 } else {
89 alert('Ошибка!');
90 show_form();
91 }
92
93 }).fail(function() {
94 show_form();
95 }).always(function() {
96 hide_loading();
97 });
98
99 });
100
101 $chat_button.click(function(e){
102
103 e.preventDefault();
104
105 show_help_chat();
106 hide_ok_message();
107 show_form();
108
109 });
110
111 $chat.find('.close').click(function(e){
112
113 e.preventDefault();
114
115 hide_help_chat();
116 hide_form();
117 show_ok_message();
118
119 });
120
121 });