Commit 3a33529e authored by Killian Kemps's avatar Killian Kemps
Browse files

Fix characters count in writing message

The characters count function is now triggered when a user replies to a
tweet and the receiver's name is automatically added to the message.
It is also triggered when the user uses the username autocompletion.
parent fc9cda1f
......@@ -118,23 +118,23 @@ MainSidebar.prototype.textareaListener = function(){
updateNumberCharacters();
_updateNameSuggestion();
}.bind(this));
}
function updateNumberCharacters(){
var numberCharacters = this.messageTextarea.value.length;
this.numberCharactersLeft.textContent = numberCharacters;
var updateNumberCharacters = function updateNumberCharacters(){
var numberCharacters = this.messageTextarea.value.length;
this.numberCharactersLeft.textContent = numberCharacters;
// If number of characters negative, display in red
if(numberCharacters > 140){
this.numberCharactersLeft.className = "red";
this.sendTweetButton.disabled = true;
}
else if (numberCharacters == 0){
this.sendTweetButton.disabled = true;
}
else{
this.numberCharactersLeft.className = "";
this.sendTweetButton.disabled = false;
}
// If number of characters negative, display in red
if(numberCharacters > 140){
this.numberCharactersLeft.className = "red";
this.sendTweetButton.disabled = true;
}
else if (numberCharacters == 0){
this.sendTweetButton.disabled = true;
}
else{
this.numberCharactersLeft.className = "";
this.sendTweetButton.disabled = false;
}
}
......@@ -240,6 +240,7 @@ var _chooseCompletion = function(e){
var leftSplit = messageTextarea.value.substring(0, mentionIndex);
var middle = usernames.substr(usernames.indexOf('@'));
messageTextarea.value = leftSplit + middle + rightSplit;
updateNumberCharacters();
} else if (e.keyCode === 40) {
e.preventDefault();
......@@ -339,6 +340,7 @@ MainSidebar.prototype.insertMessage = function(message){
this.messageTextarea.value = message + ' ';
this.messageTextarea.focus();
_setCursor(this.messageTextarea, this.messageTextarea.value.length);
updateNumberCharacters();
}
MainSidebar.prototype.toggleNotificationPanel = function(forceOpen){
......
......@@ -22,6 +22,17 @@ describe("mainSidebar", function(){
document.body.appendChild(messageTextarea);
var numberCharactersLeft = document.createElement('span');
numberCharactersLeft.id = "numberCharactersLeft";
numberCharactersLeft.value = "0";
document.body.appendChild(numberCharactersLeft);
var sendTweetButton = document.createElement('button');
sendTweetButton.id = "sendTweetButton";
document.body.appendChild(sendTweetButton);
socket = {emit: function(){}};
});
......@@ -79,6 +90,10 @@ describe("mainSidebar", function(){
.getElementsByTagName('li');
var messageTextarea = document.getElementById('messageTextarea');
var numberCharactersLeft = document.getElementById('numberCharactersLeft');
var sendTweetButton = document.getElementById('sendTweetButton');
suggestions[1].style.backgroundColor = 'rgb(245, 245, 220)';
_setCursor(messageTextarea, 7);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment