feat(chat): add input and send message length configure item

#20
This commit is contained in:
OldHawk
2017-12-08 18:25:06 +08:00
parent b52e34650b
commit 8e0468cb64
3 changed files with 32 additions and 5 deletions

View File

@@ -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
}

View File

@@ -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;
}
};

View File

@@ -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;
}