| 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 |
}); |