Use $.proxy to set correct context for event handlers.
This commit is contained in:
parent
2852ca088c
commit
df4c14826f
83
converse.js
83
converse.js
@ -1,5 +1,5 @@
|
|||||||
/*!
|
/*!
|
||||||
* Converse.js (Web-based instant messaging with XMPP)
|
* Converse.js (XMPP-based instant messaging with Strophe.js and backbone.js)
|
||||||
* http://opkode.com
|
* http://opkode.com
|
||||||
*
|
*
|
||||||
* Copyright (c) 2012 Jan-Carel Brand
|
* Copyright (c) 2012 Jan-Carel Brand
|
||||||
@ -8,10 +8,6 @@
|
|||||||
|
|
||||||
var xmppchat = (function (jarnxmpp, $, console) {
|
var xmppchat = (function (jarnxmpp, $, console) {
|
||||||
var ob = jarnxmpp;
|
var ob = jarnxmpp;
|
||||||
/* FIXME: XEP-0136 specifies 'urn:xmpp:archive' but the mod_archive_odbc
|
|
||||||
* add-on for ejabberd wants the URL below. This might break for other
|
|
||||||
* Jabber servers.
|
|
||||||
*/
|
|
||||||
ob.messages = {};
|
ob.messages = {};
|
||||||
ob.messages.ClientStorage = (function () {
|
ob.messages.ClientStorage = (function () {
|
||||||
// TODO: Messages must be encrypted with a key and salt
|
// TODO: Messages must be encrypted with a key and salt
|
||||||
@ -41,6 +37,10 @@ var xmppchat = (function (jarnxmpp, $, console) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
ob.collections = {
|
ob.collections = {
|
||||||
|
/* FIXME: XEP-0136 specifies 'urn:xmpp:archive' but the mod_archive_odbc
|
||||||
|
* add-on for ejabberd wants the URL below. This might break for other
|
||||||
|
* Jabber servers.
|
||||||
|
*/
|
||||||
'URI': 'http://www.xmpp.org/extensions/xep-0136.html#ns'
|
'URI': 'http://www.xmpp.org/extensions/xep-0136.html#ns'
|
||||||
};
|
};
|
||||||
ob.collections.getLastCollection = function (jid, callback) {
|
ob.collections.getLastCollection = function (jid, callback) {
|
||||||
@ -132,6 +132,7 @@ xmppchat.ChatBoxView = Backbone.View.extend({
|
|||||||
if (minutes.length==1) {minutes = '0'+minutes;}
|
if (minutes.length==1) {minutes = '0'+minutes;}
|
||||||
time = now.toLocaleTimeString().substring(0,5);
|
time = now.toLocaleTimeString().substring(0,5);
|
||||||
$chat_content = $(this.el).find('.chat-content');
|
$chat_content = $(this.el).find('.chat-content');
|
||||||
|
$chat_content.find('div.chat-event').remove();
|
||||||
$chat_content.append(this.message_template({
|
$chat_content.append(this.message_template({
|
||||||
'sender': 'me',
|
'sender': 'me',
|
||||||
'time': time,
|
'time': time,
|
||||||
@ -1240,67 +1241,63 @@ xmppchat.XMPPStatusView = Backbone.View.extend({
|
|||||||
|
|
||||||
// Event handlers
|
// Event handlers
|
||||||
// --------------
|
// --------------
|
||||||
$(document).ready(function () {
|
$(document).ready($.proxy(function () {
|
||||||
var chatdata = jQuery('div#collective-xmpp-chat-data'),
|
var chatdata = jQuery('div#collective-xmpp-chat-data'),
|
||||||
$toggle = $('a#toggle-online-users');
|
$toggle = $('a#toggle-online-users');
|
||||||
|
|
||||||
$toggle.unbind('click');
|
$toggle.unbind('click');
|
||||||
|
|
||||||
xmppchat.username = chatdata.attr('username');
|
this.username = chatdata.attr('username');
|
||||||
xmppchat.base_url = chatdata.attr('base_url');
|
this.base_url = chatdata.attr('base_url');
|
||||||
|
|
||||||
$(document).unbind('jarnxmpp.connected');
|
$(document).unbind('jarnxmpp.connected');
|
||||||
$(document).bind('jarnxmpp.connected', function () {
|
$(document).bind('jarnxmpp.connected', $.proxy(function () {
|
||||||
|
this.connection.xmlInput = function (body) { console.log(body); };
|
||||||
|
this.connection.xmlOutput = function (body) { console.log(body); };
|
||||||
|
|
||||||
xmppchat.connection.xmlInput = function (body) {
|
this.connection.bare_jid = Strophe.getBareJidFromJid(this.connection.jid);
|
||||||
console.log(body);
|
this.connection.domain = Strophe.getDomainFromJid(this.connection.jid);
|
||||||
};
|
// XXX: Better if configurable?
|
||||||
|
this.connection.muc_domain = 'conference.' + this.connection.domain;
|
||||||
|
|
||||||
xmppchat.connection.xmlOutput = function (body) {
|
this.roster = this.Roster(_, $, console);
|
||||||
console.log(body);
|
this.rosterview = Backbone.View.extend(this.RosterView(this.roster, _, $, console));
|
||||||
};
|
|
||||||
|
|
||||||
xmppchat.connection.bare_jid = Strophe.getBareJidFromJid(xmppchat.connection.jid);
|
this.connection.addHandler(
|
||||||
|
$.proxy(function (presence) {
|
||||||
|
this.roster.presenceHandler(presence);
|
||||||
|
return true;
|
||||||
|
}, this), null, 'presence', null);
|
||||||
|
|
||||||
xmppchat.roster = xmppchat.Roster(_, $, console);
|
this.connection.roster.registerCallback(this.roster.rosterHandler);
|
||||||
xmppchat.rosterview = Backbone.View.extend(xmppchat.RosterView(xmppchat.roster, _, $, console));
|
this.roster.getRoster();
|
||||||
|
|
||||||
xmppchat.connection.addHandler(function (presence) {
|
this.chatboxes = new this.ChatBoxes();
|
||||||
xmppchat.roster.presenceHandler(presence);
|
this.chatboxesview = new this.ChatBoxesView({
|
||||||
return true;
|
'model': this.chatboxes
|
||||||
}, null, 'presence', null);
|
|
||||||
|
|
||||||
xmppchat.connection.roster.registerCallback(xmppchat.roster.rosterHandler);
|
|
||||||
xmppchat.roster.getRoster();
|
|
||||||
|
|
||||||
xmppchat.chatboxes = new xmppchat.ChatBoxes();
|
|
||||||
xmppchat.chatboxesview = new xmppchat.ChatBoxesView({
|
|
||||||
'model': xmppchat.chatboxes
|
|
||||||
});
|
});
|
||||||
|
|
||||||
xmppchat.connection.addHandler(
|
this.connection.addHandler(
|
||||||
function (message) {
|
$.proxy(function (message) {
|
||||||
xmppchat.chatboxesview.messageReceived(message);
|
this.chatboxesview.messageReceived(message);
|
||||||
return true;
|
return true;
|
||||||
},
|
}, this), null, 'message', 'chat');
|
||||||
null, 'message', 'chat');
|
|
||||||
|
|
||||||
// XMPP Status
|
// XMPP Status
|
||||||
xmppchat.xmppstatus = new xmppchat.XMPPStatus();
|
this.xmppstatus = new this.XMPPStatus();
|
||||||
xmppchat.xmppstatusview = new xmppchat.XMPPStatusView({
|
this.xmppstatusview = new this.XMPPStatusView({
|
||||||
'model': xmppchat.xmppstatus
|
'model': this.xmppstatus
|
||||||
});
|
});
|
||||||
|
|
||||||
xmppchat.xmppstatus.sendPresence();
|
this.xmppstatus.sendPresence();
|
||||||
|
|
||||||
// Controlbox toggler
|
// Controlbox toggler
|
||||||
$toggle.bind('click', function (e) {
|
$toggle.bind('click', function (e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
if ($("div#online-users-container").is(':visible')) {
|
if ($("div#online-users-container").is(':visible')) {
|
||||||
xmppchat.chatboxesview.closeChat('online-users-container');
|
this.chatboxesview.closeChat('online-users-container');
|
||||||
} else {
|
} else {
|
||||||
xmppchat.chatboxesview.openChat('online-users-container');
|
this.chatboxesview.openChat('online-users-container');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
}, this));
|
||||||
});
|
}, xmppchat));
|
||||||
|
Loading…
Reference in New Issue
Block a user