-
Notifications
You must be signed in to change notification settings - Fork 74
/
lite-chatbox.min.js
8 lines (8 loc) · 1.4 KB
/
lite-chatbox.min.js
1
2
3
4
5
6
7
8
const TipsType={tipsNormal:"tips",tipsPrimary:"tips-primary",tipsSuccess:"tips-success",tipsInfo:"tips-info",tipsWarning:"tips-warning",tipsDanger:"tips-danger"},TitleType={admin:"admin",owner:"owner"};function beforeRenderingHTML(e,s){let t="",n=document.querySelector(s);for(let i=0;i<e.length;i++)!e[i].isRender&&(-1!==e[i].messageType.indexOf("tips")?t+=renderTipHtml(e[i].html,TipsType[e[i].messageType]||"tips"):t+=renderMessageHtml(e[i]),e[i].isRender=!0);n.innerHTML+=t,setTimeout(()=>{n.scrollHeight>n.clientHeight&&(n.scrollTop=n.scrollHeight,n="",t="")},300)}function renderMessageHtml(e){return`<div class="c${e.position} cmsg">
<img class="headIcon ${e.diamond?"":"radius"}" src="${e.headIcon}" ondragstart="return false;" oncontextmenu="return false;"/>
<span class="name">
${renderTitleHtml(e.htitle,TitleType[e.htitleType]||"")}
<span>${escapeHtml(e.name)||" "}</span>
</span>
<span class="content">${"raw"===e.messageType?e.html:escapeHtml(e.html)}</span>
</div>`}function renderTitleHtml(e,s){return e?`<span class="htitle ${s}" style="margin: 0 4px 0 0;">${e}</span>`:""}function renderTipHtml(e,s){return e?`<div class="tips"><span class="${s}" style="margin-bottom: 20px;">${escapeHtml(e)}</span></div>`:""}function escapeHtml(e){return e.replace(/[\u0000-\u002F\u003A-\u0040\u005B-\u0060\u007B-\u00FF]/g,e=>"&#"+("000"+e.charCodeAt(0)).slice(-4)+";")}