Changeset View
Changeset View
Standalone View
Standalone View
web/static/js/widgets/chatinput.js
- This file was added.
class ChatInputWidget | |||||
{ | |||||
/** | |||||
* Configuration: | |||||
* - submit: handler function for submit the text to a chat room | |||||
*/ | |||||
constructor(id, config) | |||||
{ | |||||
this.config = config || {} | |||||
this.id = id | |||||
this.render() | |||||
} | |||||
/** | |||||
* Renders text chat input widget | |||||
*/ | |||||
render() | |||||
{ | |||||
let icon = '<span class="glyphicon glyphicon-comment"></span>' | |||||
let html = `<span class="input-group-addon">${icon}</span> | |||||
<input id="chat_txt_input" name="txt_input" value="" class="form-control" autofocus=true />` | |||||
$('#' + this.id) | |||||
.html(html) | |||||
.on('keypress', 'input', e => { | |||||
let txt | |||||
if (e.keyCode == 13 && this.config.submit && (txt = $(e.target).val())) { | |||||
this.config.submit(e, txt) | |||||
$(e.target).val('') | |||||
} | |||||
}) | |||||
} | |||||
} | |||||
export default ChatInputWidget |