I'm trying to change the title of a converse.js chat box that opens when sent a new message.
I've got the id of the pop-up chat window stored in a variable chatbox_id
, and I'm trying to use jquery inside an ajax success function to de-reference that variable and set the "chat-title" text field, but the syntax I have is not correct:
converse.plugins.add('name_lookup', {
initialize: function () {
var _converse = this._converse;
_converse.on('pluginsInitialized', function () {
_converse.on('chatBoxInitialized', function (chatbox) {
var title = chatbox.model.attributes.fullname;
var chatbox_id = chatbox.model.attributes.box_id;
var data;
$.ajax({
type: "POST",
url: 'lookup.php',
async: false,
data: "number=" + num_title[1],
success: function(data, status, xhr) {
chatbox.model.attributes.fullname = data;
$('#' + chatbox_id).children('chat-title').text(data);
}
});
I've tried other syntactical routes such as:
$('#' + charbox_id + ' chat-title').text(data);
along with
$('#' + charbox_id).children('chat-title').text(data);
But none seem to work. I'm sure I'm missing something obvious here, but Googling for such things as "use jquery to set nested div tag using a variable for parent id" yielded the attempts above.
If there is a conversejs helper function to set the chat-title value in the model, and have converse automatically manage refresh of the chatbox title text, that would be great too.
Any help appreciated.