Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var context = {};
- $("#chat").ready(function () {
- $("#user_message").hide();
- $("#chat").show();
- var mobile = $(document).width() < 420;
- function size_check() {
- MathJax.Hub.Typeset();
- if (!mobile) {
- $("#chat_box").height("auto");
- } else {
- $("#chat").height(window.innerHeight);
- $("#chat_box").height("100vh");
- }
- if ($("#chat_box").outerHeight() > $("#chat_box").parent().outerHeight() - $("#message_input").outerHeight()) {
- $("#chat_box").outerHeight($("#chat_box").parent().outerHeight() - $("#message_input").outerHeight());
- // console.log($("#chat_box").height(), $("#chat_box").parent().height(), $("#message_input").height())
- }
- // console.log($('#chat_box')[0].scrollHeight);
- var height = $('#chat_box')[0].scrollHeight;
- $('#chat_box').scrollTop(height);
- }
- size_check();
- $(window).resize(function () {
- size_check();
- });
- $("#chat").hide();
- var send_message = function (text) {
- $("#text_input").val("");
- var message_box = $("#user_message").clone();
- message_box.show();
- message_box.find("p").text(text);
- message_box.removeAttr("id");
- message_box.appendTo("#chat_box");
- $.get("/send", { text: text, context: context }, function (data) {
- context = data.context;
- console.log(data.text);
- var message_box = $("#bot_message").clone();
- message_box.removeAttr("id");
- message_box.find("p").text(data.text);
- message_box.appendTo("#chat_box");
- var height = $('#chat_box')[0].scrollHeight;
- $('#chat_box').scrollTop(height);
- size_check();
- })
- size_check();
- }
- $("#btn_chat").click(function () {
- // console.log($("#text_input").val());
- $('#text_input').focusout();
- send_message($("#text_input").val());
- })
- $('#text_input').keypress(function (e) {
- if (e.which == 13) {
- $("#btn_chat").click();
- return false;
- }
- });
- // var original_pad = $("#message_input").css("padding-bottom");
- // $('#text_input').focusin(function (e) {
- // if (mobile) {
- // $("#message_input").css("padding-bottom", "50vh");
- // size_check()
- // }
- // });
- // $('#text_input').focusout(function (e) {
- // if (mobile) {
- // $("#message_input").css("padding-bottom", original_pad);
- // size_check()
- // }
- // });
- console.log("jquery ready")
- $("#chat").show();
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement