JSFiddle - React, Tailwind, and code Playground

by Michael Prosser

HTML

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<div class="classchat">
  <div class="chatWindow" data-player-id="Johnny Richael">
    <div class="chatTopBar">
      <span>Johnny Richael</span>
      <button onclick="if(!$(this).parent().parent().hasClass('minimized')){ $(this).html('&#9633;'); $(this).parent().parent().addClass('minimized'); } else { $(this).html('-'); $(this).parent().parent().removeClass('minimized'); }">-</button><button onclick="$(this).parent().parent().remove();">x</button>
    </div>
    <div class="chatConversation">
      <!-- conversation here -->
      <div class="chatFrom">
        Hi Michael, can you tell me how to find the last coin?
      </div>
      <div class="chatTo">
        Sure Johnny, it is at the end of the rainbow.
      </div>
      <div class="chatFrom">
        Hi Michael, can you tell me how to find the last coin?
      </div>
      <div class="chatTo">
        Sure Johnny, it is at the end of the rainbow.
      </div>
      <div class="chatFrom">
        Hi Michael, can you tell me how to find the last coin?
      </div>
      <div class="chatTo">
        Sure Johnny, it is at the end of the rainbow.
      </div>
      <div class="chatFrom">
        Hi Michael, can you tell me how to find the last coin?
      </div>
      <div class="chatTo">
        Sure Johnny, it is at the end of the rainbow.
      </div>
    </div>
    <form class="chatBar" onsubmit="sockets.chatter('playerid',$(this).find(\'.input\').text()); $(this).find(\'.input\').html(''); return false;">
    <div class="input" contenteditable="true"></div><button>Send</button>
    </form>
  </div>
</div>

CSS

.classchat{
   perspective:500px;
   position:fixed;
   left:0px;
   top:0px;
   right:0px;
   bottom:0px;
   z-index:9999999999999999999999;
}
.chatWindow{
  position:fixed;
  right:0%;
  width:240px;
  padding:5px;
  min-height:80px;
  background-color:#111;
  border:solid 0px #222;
  bottom:0%;
  max-height:calc(100% - 16px);
  transition:all 0.5s;
   -webkit-box-shadow: 0px 0px 0px 0px rgba(13,164,184,1);
  -moz-box-shadow: 0px 0px 0px 0px rgba(13,164,184,1);
  box-shadow: 0px 0px 0px 0px rgba(13,164,184,1);
}
.chatWindow.minimized{
  height: 24px;
    min-height: 24px;
}
.chatWindow .chatTopBar{
  text-align:right;
  margin-bottom:5px;
}
.chatWindow.notify{
  background-color:#fff;
  -webkit-box-shadow: 0px 0px 5px 3px rgba(13,164,184,1);
-moz-box-shadow: 0px 0px 5px 3px rgba(13,164,184,1);
box-shadow: 0px 0px 5px 3px rgba(13,164,184,1);
z-index:99999999999999999999;
}
.chatWindow .chatTopBar span{
  float:left;
  color:#27c7ea;
  padding:5px;
  font-family:helvetica;
  font-size:11px;
  font-weight:bold;
}
.chatWindow .chatTopBar button{
  background-color:#333;
  width:24px;
  line-height:24px;
  color:#ccc;
  font-size:10px;
  font-family:helvetica;
  padding:0px;
  border:none;
  margin-left:1px;
  cursor:pointer;
  transition:all 0.3s;
  outline:none;
}
.chatWindow .chatTopBar button:hover{
  background-color:#666;
  color:#fff;
}
.chatWindow .chatConversation{
  position:relative;
  display:block;
  background-color:#333;
  color:aliceblue;
  height:calc(100% - 60px);
  padding:10px;
  max-height:200px;
  overflow:auto;
  min-height: 120px;
}
.chatWindow.minimized .chatConversation{
  display:none;
}
.chatFrom{
  background-color:#0686a2;
  -webkit-border-radius: 10px;
  -webkit-border-bottom-left-radius: 0;
  -moz-border-radius: 10px;
  -moz-border-radius-bottomleft: 0;
  border-radius: 10px;
  border-bottom-left-radius: 0;
  padding:8px;
  font-size:12px;
  font-family:helvetica;
  margin-bottom:10px;
  margin-right:20%;
}
.chatTo{
 ...

JavaScript

chatNotifySound = function() {
    var snd = new  Audio("https://aninoob.com/public_assets/sounds/hits/misc/10.mp3"); 
    snd.play();
}

chatWindow = function(playerid,message){

	var messageHTML = '';

  if(message){

		messageHTML = '<div class="chatFrom">' + message + '</div>';

  }

	var ui = $('.chatWindow[data-player-id=\'' + playerid + '\']');
  
  if(!ui.length){
  
  	ui = $('<div class="chatWindow notify" data-player-id="' + playerid + '"><div class="chatTopBar"><span>' + playerid + '</span><button onclick="if(!$(this).parent().parent().hasClass(\'minimized\')){ $(this).html(\'&#9633;\'); $(this).parent().parent().addClass(\'minimized\'); } else { $(this).html(\'-\'); $(this).parent().parent().removeClass(\'minimized\'); }">-</button><button onclick="$(this).parent().parent().remove();">x</button></div><div class="chatConversation">' + messageHTML + '</div><form class="chatBar" onsubmit="sockets.chatter(\'' + playerid + '\',$(this).find(\'.input\').text()); $(this).find(\'.input\').html(\'\'); return false;"><div class="input" contenteditable="true"></div><button onclick="sendMessage();">Send</button></form><embed src="https://aninoob.com/public_assets/sounds/hits/misc/10.mp3" autostart="false" width="0" height="0" id="sound_' + playerid + '" enablejavascript="true"></audio></div>');
    
    $('.classchat').append(ui);
    
    chatNotifySound();
    
    ui.click(function(){
    
     ui.removeClass('notify');
    
    });
      
    setTimeout(function(){

      ui.removeClass('notify');

    },3000);
      
  } else {
  
  	ui.find('.chatConversation').append(messageHTML).scrollTop(100000000);
  
  }

}


setTimeout(function(){

	chatWindow('Johnny Richael','hello michael');
  
  setTimeout(function(){

		chatWindow('Harry Blaut','hello michael');

  },1000);
  
},1000);