Hi,
Iβm working on a writing indicator, which shows up next to the name on the online liste, whenever the user writes something inside the textarea. Problem is, it only shows up for the person that writes but not for other tabs/clients.
Here is my code:
Online list template: imports/ui/components/chat/chat_onlinelist.html
<template name="onlineliste">
<div id="online-liste" class="onlineList">
{{#each characters}}
<div class="characterBasicInteraction" oncontextmenu="return false;">
<span class="typeIndicator" id="typeInd_{{name}}">β</span>
<!-- TypeIndicator shows up here, code gets id with this.name
and uses it to change jquery fadeIn/fadeOut -->
<a href="/c/{{name}}" target="_blank" class="{{name}}" {{checkIfFriend}}><li>{{name}}</li></a>
<div id="panel_{{name}}" class="panelChat">
<span><b>{{name}}</b></span>
<span id="whisp">FlΓΌstern</span>
{{{checkIfFriendButton}}}
<span>Bookmark</span>
<span>Ignore</span>
<span>Report</span>
</div>
</div>
{{/each}}
</div>
</template>
Now I tried 3 approaches so far, all had the same outcome as mentioned above.
First Approach, Event keydown textarea in imports/ui/components/chat/chat.js
'keydown textarea'(event, template) {
var character = Session.get("activeChar");
var getIndicator = "#typeInd_"+character;
//setup before functions
var typingTimer; //timer identifier
var doneTypingInterval = 5000; //time in ms (5 seconds)
//on keyup, start the countdown
template.$('textarea').keyup(function(){
clearTimeout(typingTimer);
if (template.$('textarea').val()) {
typingTimer = setTimeout(doneTyping, doneTypingInterval);
}
});
//user is "finished typing,"
function doneTyping () {
template.$(getIndicator).fadeOut();
}
template.$(getIndicator).fadeIn();
template.$(".input-box_text").focusout(function() {
template.$(getIndicator).fadeOut();
})
}
Approach 2: Writing the function in imports/api/chat/chat.js to have it on the server (?) and load it inside imports/ui/components/chat/chat.js
typeIndicator = function typeIndicator (character, getIndicator) {
var typingTimer; //timer identifier
var doneTypingInterval = 5000; //time in ms (5 seconds)
//on keyup, start the countdown
$('textarea').keyup(function(){
clearTimeout(typingTimer);
if ($('textarea').val()) {
typingTimer = setTimeout(doneTyping, doneTypingInterval);
}
});
//user is "finished typing," do something
function doneTyping () {
$(getIndicator).fadeOut();
}
//$(getIndicator).fadeIn();
$(getIndicator).fadeIn();
$(".input-box_text").focusout(function() {
$(getIndicator).fadeOut();
});
};
'keydown textarea'(event, template) {
var character = Session.get("activeChar");
var getIndicator = "#typeInd_"+character;
TypeIndicator(character, getIndicator);
}
Approach 3: Basically the same as 2 but this time I didnβt use the blaze-template.events helper
document.addEventListener("keydown", event => {
var character = Session.get("activeChar");
var getIndicator = "#typeInd_"+character;
typeIndicator(character, getIndicator);
});
So it looks like those changes do nothing different. Can someone help? Thank you!