Advertisement
Sax

Correct Placement of Mathjax.Hub.Typeset

Sax
Jul 3rd, 2017
344
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var context = {};
  2.  
  3. $("#chat").ready(function () {
  4.  
  5.     $("#user_message").hide();
  6.  
  7.     $("#chat").show();
  8.  
  9.     var mobile = $(document).width() < 420;
  10.    
  11.     function size_check() {
  12.         MathJax.Hub.Typeset();
  13.         if (!mobile) {
  14.             $("#chat_box").height("auto");
  15.         } else {
  16.             $("#chat").height(window.innerHeight);
  17.             $("#chat_box").height("100vh");
  18.         }
  19.         if ($("#chat_box").outerHeight() > $("#chat_box").parent().outerHeight() - $("#message_input").outerHeight()) {
  20.             $("#chat_box").outerHeight($("#chat_box").parent().outerHeight() - $("#message_input").outerHeight());
  21.             // console.log($("#chat_box").height(), $("#chat_box").parent().height(), $("#message_input").height())
  22.         }
  23.         // console.log($('#chat_box')[0].scrollHeight);
  24.         var height = $('#chat_box')[0].scrollHeight;
  25.         $('#chat_box').scrollTop(height);
  26.     }
  27.  
  28.     size_check();
  29.  
  30.     $(window).resize(function () {
  31.         size_check();
  32.     });
  33.  
  34.     $("#chat").hide();
  35.  
  36.     var send_message = function (text) {
  37.         $("#text_input").val("");
  38.         var message_box = $("#user_message").clone();
  39.         message_box.show();
  40.         message_box.find("p").text(text);
  41.         message_box.removeAttr("id");
  42.         message_box.appendTo("#chat_box");
  43.         $.get("/send", { text: text, context: context }, function (data) {
  44.             context = data.context;
  45.             console.log(data.text);
  46.             var message_box = $("#bot_message").clone();
  47.             message_box.removeAttr("id");
  48.             message_box.find("p").text(data.text);
  49.             message_box.appendTo("#chat_box");
  50.             var height = $('#chat_box')[0].scrollHeight;
  51.             $('#chat_box').scrollTop(height);
  52.             size_check();
  53.         })
  54.         size_check();
  55.     }
  56.  
  57.     $("#btn_chat").click(function () {
  58.         // console.log($("#text_input").val());
  59.         $('#text_input').focusout();
  60.         send_message($("#text_input").val());
  61.     })
  62.  
  63.     $('#text_input').keypress(function (e) {
  64.         if (e.which == 13) {
  65.             $("#btn_chat").click();
  66.             return false;
  67.         }
  68.     });
  69.  
  70.     // var original_pad = $("#message_input").css("padding-bottom");
  71.  
  72.     // $('#text_input').focusin(function (e) {
  73.     //     if (mobile) {
  74.     //         $("#message_input").css("padding-bottom", "50vh");
  75.     //         size_check()
  76.     //     }
  77.     // });
  78.  
  79.     // $('#text_input').focusout(function (e) {
  80.     //     if (mobile) {
  81.     //         $("#message_input").css("padding-bottom", original_pad);
  82.     //         size_check()
  83.     //     }
  84.     // });
  85.  
  86.     console.log("jquery ready")
  87.  
  88.     $("#chat").show();
  89.  
  90. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement