Guest User

Untitled

a guest
Jan 17th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 KB | None | 0 0
  1. <div id="controls">
  2. <input id="textbox" name="sendtext" class="controls-elements" placeholder="Напишите сообщение и нажмите Enter" type="text"></input>
  3. <button id="send" onclick="buttonOtprav()" class="controls-elements" type="submit">Отправить</button>
  4. </div>
  5.  
  6. var username = "";
  7. function send_message(conv,message){
  8. if (conv.length > 4) {
  9. conv = conv + "<br>";
  10. }
  11. $("#converse").html(conv +"<div class='message-box left-img'><div class='picture'><img src='/my2/a.png' title='user name'></div><div class='mes'><span class = 'current-msg'>" + "<span id='chat-bot'>Бот: </span><p>" + message + "</p></span></div></div>");
  12. $(".current-msg").hide();
  13. $(".current-msg").delay(500).fadeIn();
  14. $(".current-msg").removeClass("current-msg");
  15. }
  16.  
  17. function get_username(conv){
  18. send_message(conv,"Привет, могу ли я чем то помочь?");
  19. }
  20.  
  21. function ai(conv,message){
  22. if (username<4) {
  23. username = message;
  24. send_message(conv,"Hi, "+ username + ". How are you?");
  25. }
  26. else{
  27. // $("#send").click(function(){
  28. $.get("getresponse.php", {q:message}, function(data, status){
  29. // alert("Data: " + data + "nStatus: " + status);
  30. send_message(conv,data);
  31. });
  32. // });
  33. }
  34. }
  35.  
  36. $(function(){
  37. var open = false;
  38. var conv = $("#converse").html();
  39. get_username(conv);
  40. $("#send").click(function(){
  41. var usermsg = $("#textbox").val();
  42. conv = $("#converse").html();
  43. console.log(conv.length);
  44. if (usermsg != "") {
  45. $("#textbox").val("");
  46. if (conv.length > 4) {
  47. conv = conv + "<br>";
  48. }
  49. $("#converse").html(conv + "<div class='message-box right-img'><div class='picture'><img src='/my2/user.png' title='user name'></div><div class='mes'><span><span id='chat-user'>Пользователь: </span><p>" + usermsg + "</p></span></div></div>");
  50. $("#converse").scrollTop($("#converse").prop("scrollHeight"));
  51. conv = $("#converse").html();
  52. ai(conv,usermsg);
  53. }
  54. });
  55. $("#chat-button").click(function(){
  56. $("#chat-box").animate({"right":"0px"});
  57. });
  58. $("#cancel").click(function(){
  59. $("#chat-box").animate({"right":"-300px"});
  60. });
  61. });
Add Comment
Please, Sign In to add comment