Advertisement
MarkUa

Untitled

Jun 28th, 2019
466
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5.71 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <title>Chat</title>
  6.     <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
  7.    <link rel='stylesheet prefetch' href='https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.6.2/css/font-awesome.min.css'>
  8.      <script src="https://cdn.jsdelivr.net/npm/vue"></script>
  9.  
  10.     <style>
  11. body {
  12.     display: flex;
  13.     justify-content: center;
  14.     font-family: "proxima-nova", "Source Sans Pro", sans-serif;
  15.     font-size: 1em;
  16.     color: #32465a;
  17. }
  18. p,ol,ul,li{
  19.     margin:0;
  20.     padding:0;
  21.     border:0;
  22.     font-size:100%;
  23.     font:inherit;
  24.     vertical-align:baseline
  25. }
  26. ol,ul{list-style:none}
  27. .wrapper {
  28.     float: right;
  29.     background: #e8efef;
  30.     width: 35%;
  31.     height: 600px;
  32.     overflow: hidden;
  33.     position: relative;
  34. }
  35.  
  36. .wrapper .message-content {
  37.     height: auto;
  38.     min-height: calc(100% - 93px);
  39.     max-height: calc(100% - 93px);
  40.     overflow-y: scroll;
  41.     overflow-x: hidden;
  42. }
  43.  
  44. .wrapper .message-content::-webkit-scrollbar {
  45.     width: 5px;
  46.     background: transparent;
  47. }
  48. .wrapper .message-content::-webkit-scrollbar-thumb {
  49.     background-color: rgba(0, 0, 0, 0.3);
  50. }
  51. .wrapper .message-content ul li {
  52.     display: inline-block;
  53.     clear: both;
  54.     float: left;
  55.     margin: 5px 15px;
  56.     width: calc(100% - 25px);
  57.     font-size: 0.9em;
  58. }
  59. .wrapper .message-content ul li:nth-last-child(1) {
  60.     margin-bottom: 20px;
  61. }
  62. .wrapper .message-content ul li.received img {
  63.     margin: 6px 8px 0 0;
  64. }
  65. .wrapper .message-content ul li.received p {
  66.     background: #fff;
  67.     color: #111;
  68. }
  69. .wrapper .message-content ul li.sent img {
  70.     float: right;
  71.     margin: 6px 0 0 8px;
  72. }
  73. .wrapper .message-content ul li.sent p {
  74.     background: #0174AD;
  75.     float: right;
  76.     color: #fff;
  77. }
  78. .wrapper .message-content ul li img {
  79.     width: 22px;
  80.     border-radius: 50%;
  81.     float: left;
  82. }
  83. .wrapper .message-content ul li p {
  84.     display: inline-block;
  85.     padding: 10px 15px;
  86.     border-radius: 10px;
  87.     max-width: 300px;
  88. }
  89. .wrapper .msg-box {
  90.     position: absolute;
  91.     bottom: 0;
  92.     width: 100%;
  93.     z-index: 99;
  94. }
  95. .wrapper .msg-box .wrap {
  96.     position: relative;
  97. }
  98. .wrapper .msg-box .wrap input {
  99.  
  100.     float: left;
  101.     border: none;
  102.     width: calc(100% - 90px);
  103.     padding: 11px 32px 10px 8px;
  104.     font-size: 0.8em;
  105.     height: 20px;
  106.     color: #32465a;
  107. }
  108.  
  109. .wrapper .msg-box .wrap input:focus {
  110.     outline: none;
  111. }
  112.  
  113. .wrapper .msg-box .wrap button {
  114.     float: right;
  115.     border: none;
  116.     width: 50px;
  117.     padding: 12px 0;
  118.     cursor: pointer;
  119.     background: #0174AD;
  120.     color: #f5f5f5;
  121. }
  122. .wrapper .head-img {
  123.     width: 100%;
  124.     height: 60px;
  125.     line-height: 60px;
  126.     background: #f9f9f9;
  127. }
  128. .wrapper .head-img img {
  129.     width: 40px;
  130.     border-radius: 50%;
  131.     float: left;
  132.     margin: 9px 12px 0 9px;
  133. }
  134. .wrapper .head-img p {
  135.     float: left;
  136. }
  137.         input[type="text"]{
  138.  
  139.   background-color : #d1d1d1;
  140.  
  141. }
  142.         </style>
  143. </head>
  144. <body>
  145.  
  146. <div class="wrapper" id="users">
  147.     <div class="head-img">
  148.  
  149.         <p id = "chatdesc"></p>
  150.     </div>
  151.     <div class="message-content" id = "mes">
  152.         <ul>
  153.  
  154.             <div v-for="(message,index) in messages " >
  155.  
  156.  
  157.             <li v-bind:class="{sent:message.iamAuthor,received: !message.iamAuthor}">
  158.  
  159.                 <p> {{ message.text }}</p>
  160.                   <span class="time_date"> {{ message.date }} - {{ message.author }}</span>
  161.  
  162.  
  163.             </li>
  164.             </div>
  165.         </ul>
  166.     </div>
  167.     <div class="msg-box">
  168.         <div class="wrap">
  169.             <input type="text" id="message-txt" placeholder="Enter your message..."  />
  170.             <button  v-on:click="send()"><i class="fa fa-paper-plane" aria-hidden="true" ></i></button>
  171.         </div>
  172.     </div>
  173. </div>
  174.  
  175. <script >
  176.  
  177. $( document ).ready(function() {
  178.     // alert( "ready!" );
  179.     var objDiv = document.getElementById("mes");
  180. objDiv.scrollTop =objDiv.scrollHeight - objDiv.clientHeight;
  181. //document.getElementById("chatdesc").innerHTML = "   Chat of course";
  182. });
  183. function sentMessage() {
  184.     message = $("#message-txt").val();
  185.     if ($.trim(message) == '') {
  186.         return false;
  187.     }
  188.     $('' + message + '').appendTo($('.message-content ul'));
  189.     $('#message-txt').val(null);
  190.  
  191.     $(".message-content").animate({scrollTop: $(document).height()}, "fast");
  192. }
  193. $('.submit').click(function () {
  194.     sentMessage();
  195. });
  196.  
  197. $(window).on('keydown', function (e) {
  198.     if (e.which == 13) {
  199.         sentMessage();
  200.         return false;
  201.     }
  202. });
  203.  
  204.  
  205.  
  206. var vm = new Vue({
  207.   el: '#users',
  208.   data: {
  209.     messages: [
  210.         {text:"When you're backed against the wall, break the god damn thing down.",author: "",date: "",iamAuthor:true},
  211.         {text:"When you're backed against the wall, break the god damn thing down.",author: "",date: "",iamAuthor:false},
  212.         {text:"ddqqw",author: "",date: "",iamAuthor:true}
  213.     ]
  214.   },
  215.   mounted:function(){
  216.   //      alert("rgr");
  217.        $.ajax({
  218.              headers: { "X-CSRFToken":'{{ csrf_token }}'},
  219.            url: '',
  220.            type: 'get', // This is the default though, you don't actually need to always mention it
  221.            data: {
  222.                'csrfmiddlewaretoken': '{{ csrf_token }}'
  223.            },
  224.            success: function (data) {
  225.  
  226.            }.bind(this),
  227.            failure: function (data) {
  228.                alert('Got an error dude');
  229.                //alert(JSON.stringify(data));
  230.  
  231.            }
  232.        });
  233.   },
  234.   methods:{
  235.         send(){
  236.              var objDiv = document.getElementById("mes");
  237. objDiv.scrollTop =objDiv.scrollHeight - objDiv.clientHeight;
  238.             var value = document.getElementById("message-txt").value
  239.  
  240.             if(value &&  (value.length !== value.split(" ").length-1)){
  241.               // alert("NOR Empty");
  242.                 this.messages.push(    {text:value,author: "",date: "",iamAuthor:true})
  243.             }
  244.             else{
  245.                // alert("empty")
  246.             }
  247.  
  248.         }
  249.   }})
  250. </script>
  251.  
  252. </body>
  253. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement