diff --git a/config/env/torrents.js b/config/env/torrents.js index ef1863a6..aaad9510 100644 --- a/config/env/torrents.js +++ b/config/env/torrents.js @@ -691,6 +691,7 @@ module.exports = { * @expires: banned expires time setting, in this time, user cannot connect chat server */ chat: { + messageMaxLength: 1000, ban: { expires: 60 * 60 * 1000 * 1 } diff --git a/modules/chat/client/controllers/chat.client.controller.js b/modules/chat/client/controllers/chat.client.controller.js index 6c453e6c..edcf83c1 100644 --- a/modules/chat/client/controllers/chat.client.controller.js +++ b/modules/chat/client/controllers/chat.client.controller.js @@ -128,12 +128,36 @@ } } + /** + * selectRange + * @param start + * @param end + * @returns {*} + */ + $.fn.selectRange = function (start, end) { + if (!end) end = start; + return this.each(function () { + if (this.setSelectionRange) { + this.focus(); + this.setSelectionRange(start, end); + } else if (this.createTextRange) { + var range = this.createTextRange(); + range.collapse(true); + range.moveEnd('character', end); + range.moveStart('character', start); + range.select(); + } + }); + }; /** * $watch 'vm.messages' * when changed, scroll to bottom */ - $scope.$watch('vm.messages.length', function (newValue, oldValue) { - //mtDebug.info('vm.messages changed'); + $scope.$watch('vm.messageText', function (newValue, oldValue) { + if (newValue.length > vm.chatConfig.messageMaxLength) { + vm.messageText = newValue.substr(0, vm.chatConfig.messageMaxLength); + $('#messageText').focus().val(vm.messageText).selectRange(vm.cursorPosition + 1); + } }); $scope.$watch('vm.fontStyleBold', function (newValue, oldValue) { if (newValue) { @@ -231,6 +255,8 @@ evt.preventDefault(); } } + } else { + vm.cursorPosition = evt.currentTarget.selectionStart; } }; diff --git a/modules/chat/client/less/chat.less b/modules/chat/client/less/chat.less index 38e9b362..75b4a4e0 100644 --- a/modules/chat/client/less/chat.less +++ b/modules/chat/client/less/chat.less @@ -21,7 +21,7 @@ } } .chat-body { - height: ~"calc(100% - 160px)"; + height: ~"calc(100% - 180px)"; padding: 10px 10px; overflow-y: auto; word-break: break-all; @@ -187,7 +187,7 @@ } } .chat-footer { - height: 120px; + height: 140px; border-top: solid 1px lighten(@gray-light, 40%); background-color: lighten(@gray-light, 43%); .footer-function { @@ -218,7 +218,7 @@ textarea { resize: none; width: ~"calc(100% + 2px)"; - height: 80px; + height: 100px; margin-left: -1px; border-radius: 0 0 3px 3px; }