diff --git a/ChangeLog.md b/ChangeLog.md index d3668b23..39799004 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -5,6 +5,7 @@ - Added server group clients list - Improved invite buddy dialog - Improved poke modal system + - Improved modal template for text input * **24.05.19** - Implemented icon upload diff --git a/shared/js/ui/elements/modal.ts b/shared/js/ui/elements/modal.ts index 3dec0145..0e4b15c7 100644 --- a/shared/js/ui/elements/modal.ts +++ b/shared/js/ui/elements/modal.ts @@ -84,6 +84,7 @@ class Modal { properties: ModalProperties; shown: boolean; + open_listener: (() => any)[] = []; close_listener: (() => any)[] = []; close_elements: JQuery; @@ -121,6 +122,7 @@ class Modal { this.close_elements = tag.find(".button-modal-close"); this.close_elements.toggle(this.properties.closeable); this._htmlTag = tag; + this._htmlTag.on('shown.bs.modal', event => { for(const listener of this.open_listener) listener(); }); this._htmlTag.on('hide.bs.modal', event => !this.properties.closeable || this.close()); this._htmlTag.on('hidden.bs.modal', event => this._htmlTag.detach()); } @@ -198,6 +200,13 @@ function createInputModal(headMessage: BodyCreator, question: BodyCreator, valid input.attr("pattern", valid ? null : "^[a]{1000}$").toggleClass("is-invalid", !valid); button_submit.prop("disabled", !valid); }); + input.on('keydown', event => { + if(event.keyCode !== JQuery.Key.Enter || event.shiftKey) + return; + if(button_submit.prop("disabled")) + return; + button_submit.trigger('click'); + }); button_submit.on('click', event => { if(!submited) { @@ -219,6 +228,7 @@ function createInputModal(headMessage: BodyCreator, question: BodyCreator, valid modal.close(); }); + modal.open_listener.push(() => input.focus()); modal.close_listener.push(() => button_cancel.trigger('click')); return modal; }