[lib.content-controller] remove auto_grow() to move it local (inside template [vue.auth.channel]) + added management for ENTER but not SHIFT+ENTER

This commit is contained in:
xdrm-brackets 2018-04-02 21:15:28 +02:00
parent dad14da4a8
commit 7328645735
2 changed files with 86 additions and 17 deletions

View File

@ -56,21 +56,7 @@ export default class ContentController{
} }
/* (6) Textarea auto_grow /* (6) Change username
*
* @e<Event> Textarea event
*
---------------------------------------------------------*/
auto_grow(e){
setTimeout(() => {
e.target.style.height = '0';
e.target.style.height = `calc( ${e.target.scrollHeight}px )`;
}, 1);
}
/* (7) Change username
* *
* @username<String> New username * @username<String> New username
---------------------------------------------------------*/ ---------------------------------------------------------*/
@ -135,5 +121,23 @@ export default class ContentController{
} }
/* (8) Send message
*
---------------------------------------------------------*/
send_message(_msg=null){
/* (1) Manage invalid _msg */
if( typeof _msg !== 'string' || _msg.length <= 0 )
return true;
/* (2) Send message */
console.log(`SEND: "${_msg}"`);
return true;
}
} }

View File

@ -22,7 +22,7 @@
</section> </section>
<section class='message-input'> <section class='message-input'>
<textarea :placeholder='`Message #${gs.room.get(`text`).name}`' @keydown='gs.content.auto_grow'></textarea> <textarea :value='message' :placeholder='`Message #${gs.room.get(`text`).name}`' @keydown='keydown' @keyup='keyup'></textarea>
</section> </section>
</div> </div>
@ -34,7 +34,72 @@ export default {
name: 'channel-', name: 'channel-',
data(){ return { gs: gs.get }; } data(){ return {
gs: gs.get,
message: '', // message text
pressed: {
16: false // SHIFT key
}
}; },
methods: {
/* (1) Auto-grow text area
*
---------------------------------------------------------*/
auto_grow(e){
setTimeout(() => {
e.target.style.height = '0';
e.target.style.height = `calc( ${e.target.scrollHeight}px )`;
}, 1);
},
/* (2) Mange Key Down
*
---------------------------------------------------------*/
keydown(e){
// Manage auto grow
this.auto_grow(e);
// register pressed keys
this.pressed[e.keyCode] = true;
// if not ENTER OR SHIFT -> do nothing
if( e.keyCode !== 13 || this.pressed[16] )
return;
// bufferize message + remove trailing line
let buffer = e.target.value.replace(/\n*$/, '');
this.message = buffer;
// send message
if( !gs.get.content.send_message(buffer) )
return;
// empty message
this.message = '';
},
/* (3) Mange Key Up
*
---------------------------------------------------------*/
keyup(e){
// unregister pressed keys
this.pressed[e.keyCode] = false;
}
}
} }