@ -1,8 +1,8 @@
< template >
< div class = "newMessageBanner" >
< label for = "newMessageInput" > < / label >
< textarea id = "newMessageInput" class = "newMessageInput" placeholder = "type a message ..." v -model = " msg.content.text " / >
< icon v -on :click ="sendMessage()" id = "sendMessageBtn" style = "position: absolute; right: 1rem; bottom: 0.5rem;" ic = "./sym/ic_send_white_24px.svg" / >
< textarea @input ="resizeMessageBanner()" ref = "newMessageInput" id = "newMessageInput" class = "newMessageInput" placeholder = "type a message ..." v -model = " msg.content.text " / >
< icon @click.native ="sendMessage()" id = "sendMessageBtn" style = "position: absolute; right: 1rem; bottom: 0.5rem;" ic = "./sym/ic_send_white_24px.svg" / >
< / div >
< / template >
@ -15,20 +15,23 @@ export default {
components : {
icon
} ,
mounted ( ) {
ResizeListener ( document . getElementById ( "newMessageInput" ) ) ;
/ * d o c u m e n t . g e t E l e m e n t B y I d ( " s e n d M e s s a g e B t n " ) . a d d E v e n t L i s t e n e r ( " c l i c k " , ( ) = > {
if ( document . getElementById ( "newMessageInput" ) . value !== '' ) {
main . methods . sendMessage ( document . getElementById ( "newMessageInput" ) . value )
document . getElementById ( "newMessageInput" ) . value = ''
/ / s e n d M e s s a g e . m e t h o d s . c a l l S e n d M e s s a g e ( t h i s . d a t a . m e s s a g e )
}
} ) * /
} ,
methods : {
sendMessage ( ) {
if ( this . msg . content . text !== "" ) {
this . msg . time = Date . now ( )
main . methods . sendWebSocket ( this . msg )
this . msg . content . text = ""
this . resizeMessageBanner ( )
}
} ,
resizeMessageBanner ( ) {
let id = this . $refs . newMessageInput
id . style . height = '1.25rem'
id . style . height = ` ${ id . scrollHeight } px `
let msgContainer = document . getElementById ( "messagesContainer" )
msgContainer . style . height
= ` calc(100% - ${ id . parentElement . clientHeight } px) `
/ / m s g C o n t a i n e r . s c r o l l T o ( 0 , m s g C o n t a i n e r . s c r o l l H e i g h t )
}
} ,
data ( ) {
@ -43,17 +46,6 @@ export default {
}
}
}
export const ResizeListener = id => {
id . addEventListener ( "input" , function ( ) {
this . style . height = '1.25rem'
this . style . height = ` ${ this . scrollHeight } px `
let msgContainer = document . getElementById ( "messagesContainer" )
msgContainer . style . height
= ` calc(100% - ${ this . parentElement . clientHeight } px) `
/ / m s g C o n t a i n e r . s c r o l l T o ( 0 , m s g C o n t a i n e r . s c r o l l H e i g h t )
} ) ;
}
< / script >
< style scoped >