-
Notifications
You must be signed in to change notification settings - Fork 74
/
Copy pathlitewebchatinput.min.js
1 lines (1 loc) · 2.94 KB
/
litewebchatinput.min.js
1
function insertAtCursor(e,t){if(document.selection)e.focus(),sel=document.selection.createRange(),sel.text=t;else if(e.selectionStart||"0"==e.selectionStart){var n=e.selectionStart,l=e.selectionEnd;e.value=e.value.substring(0,n)+t+e.value.substring(l,e.value.length),e.selectionStart=n+t.length,e.selectionEnd=n+t.length}else e.value+=t}function inputFile(e){e.enable&&(sendFile=e.sendFileFunc,fileBtn.onclick=function(){var e=document.createElement("input");e.type="file",e.style.display="none",e.onchange=function(){var e=this.files[0];sendFile(e)},e.click()},e.enableDropFile&&(downChild.ondrop=function(e){e.preventDefault(),downChild.style.border="none";var t=e.dataTransfer.files[0];sendFile(t)},downChild.ondragover=function(e){e.preventDefault(),downChild.style.border="3px solid #1E90FF"},downChild.ondragleave=function(e){e.preventDefault(),downChild.style.border="none"}))}var upperChild=document.querySelector(".lite-chatbox"),oLine=document.querySelector(".lite-chatinput hr"),downChild=document.querySelector(".lite-chatinput"),emojiBtn=document.getElementById("emojiBtn"),fileBtn=document.getElementById("fileBtn"),editFullScreen=document.getElementById("editFullScreen"),exitFullScreen=document.getElementById("exitFullScreen"),emojiMart=document.getElementById("emojiMart"),toolMusk=document.getElementById("toolMusk"),pickerOptions={locale:"zh",onEmojiSelect:function(e){emojiMart.style.display="none",toolMusk.style.display="none",insertAtCursor(document.querySelector(".lite-chatinput textarea"),e.native)}},picker=new EmojiMart.Picker(pickerOptions);emojiMart.appendChild(picker),oLine.onmousedown=function(e){oLine.style.backgroundColor="#1E90FF";var t=e||event,n=t.clientY,l=upperChild.offsetHeight,o=downChild.offsetHeight;return document.onmousemove=function(e){var t=e||event,i=t.clientY-n;100<l+i&&100<o-i&&(upperChild.style.height=`calc(100% - ${o-i}px)`,downChild.style.height=o-i+"px")},document.onmouseup=function(){oLine.style.backgroundColor="#fff",document.onmousedown=null,document.onmousemove=null},!1},emojiBtn.onclick=function(){emojiMart.style.display="block",toolMusk.style.display="block";let e=emojiMart.offsetHeight;var t=downChild.clientHeight,n=upperChild.clientHeight;e<n?(emojiMart.style.bottom=`${t+3}px`,emojiMart.style.top=""):(emojiMart.style.bottom="",emojiMart.style.top="10px")},editFullScreen.onclick=function(){downHeight=downChild.clientHeight,upperHeight=upperChild.clientHeight,downChild.style.height="100%",upperChild.style.height="0px",editFullScreen.style.display="none",exitFullScreen.style.display="block",oLine.style.display="none"},exitFullScreen.onclick=function(){0!=upperHeight?(downChild.style.height=`${downHeight}px`,upperChild.style.height=`calc(100% - ${downHeight}px)`):(upperChild.style.height="calc(100% - 150px)",downChild.style.height="150px"),exitFullScreen.style.display="none",editFullScreen.style.display="block",oLine.style.display="block"},toolMusk.onclick=function(){emojiMart.style.display="none",toolMusk.style.display="none"};