Replace $.proxy calls with bind (which is polyfilled in strophe.js)

This commit is contained in:
JC Brand 2015-06-27 06:36:25 +02:00
parent fc95622d72
commit 9f7174dedc

View File

@ -297,7 +297,7 @@
// Translation machinery // Translation machinery
// --------------------- // ---------------------
var __ = $.proxy(utils.__, this); var __ = utils.__.bind(this);
var ___ = utils.___; var ___ = utils.___;
// Default configuration values // Default configuration values
@ -565,7 +565,7 @@
return; return;
} }
converse.connection.vcard.get( converse.connection.vcard.get(
$.proxy(function (iq) { // Successful callback function (iq) { // Successful callback
var $vcard = $(iq).find('vCard'); var $vcard = $(iq).find('vCard');
var fullname = $vcard.find('FN').text(), var fullname = $vcard.find('FN').text(),
img = $vcard.find('BINVAL').text(), img = $vcard.find('BINVAL').text(),
@ -585,7 +585,7 @@
} }
} }
if (callback) { callback(iq, jid, fullname, img, img_type, url); } if (callback) { callback(iq, jid, fullname, img, img_type, url); }
}, this), }.bind(this),
jid, jid,
function (iq) { // Error callback function (iq) { // Error callback
var contact = converse.roster.get(jid); var contact = converse.roster.get(jid);
@ -749,13 +749,13 @@
} }
}); });
$(document).on('mousemove', $.proxy(function (ev) { $(document).on('mousemove', function (ev) {
if (!this.resized_chatbox || !this.allow_dragresize) { return true; } if (!this.resized_chatbox || !this.allow_dragresize) { return true; }
ev.preventDefault(); ev.preventDefault();
this.resized_chatbox.resizeChatBox(ev); this.resized_chatbox.resizeChatBox(ev);
}, this)); }.bind(this));
$(document).on('mouseup', $.proxy(function (ev) { $(document).on('mouseup', function (ev) {
if (!this.resized_chatbox || !this.allow_dragresize) { return true; } if (!this.resized_chatbox || !this.allow_dragresize) { return true; }
ev.preventDefault(); ev.preventDefault();
var height = this.applyHeightResistance(this.resized_chatbox.height); var height = this.applyHeightResistance(this.resized_chatbox.height);
@ -765,18 +765,18 @@
this.resized_chatbox.model.set({'height': height}); this.resized_chatbox.model.set({'height': height});
} }
this.resized_chatbox = null; this.resized_chatbox = null;
}, this)); }.bind(this));
$(window).on("blur focus", $.proxy(function (ev) { $(window).on("blur focus", function (ev) {
if ((this.windowState != ev.type) && (ev.type == 'focus')) { if ((this.windowState != ev.type) && (ev.type == 'focus')) {
converse.clearMsgCounter(); converse.clearMsgCounter();
} }
this.windowState = ev.type; this.windowState = ev.type;
},this)); }.bind(this));
$(window).on("resize", _.debounce($.proxy(function (ev) { $(window).on("resize", _.debounce(function (ev) {
this.chatboxviews.trimChats(); this.chatboxviews.trimChats();
},this), 200)); }.bind(this), 200));
}; };
this.ping = function (jid, success, error, timeout) { this.ping = function (jid, success, error, timeout) {
@ -836,14 +836,14 @@
this.onReconnected = function () { this.onReconnected = function () {
// We need to re-register all the event handlers on the newly // We need to re-register all the event handlers on the newly
// created connection. // created connection.
this.initStatus($.proxy(function () { this.initStatus(function () {
this.registerPingHandler(); this.registerPingHandler();
this.rosterview.registerRosterXHandler(); this.rosterview.registerRosterXHandler();
this.rosterview.registerPresenceHandler(); this.rosterview.registerPresenceHandler();
this.chatboxes.registerMessageHandler(); this.chatboxes.registerMessageHandler();
this.xmppstatus.sendPresence(); this.xmppstatus.sendPresence();
this.giveFeedback(__('Contacts')); this.giveFeedback(__('Contacts'));
}, this)); }.bind(this));
}; };
this.enableCarbons = function () { this.enableCarbons = function () {
@ -859,14 +859,14 @@
type: 'set' type: 'set'
}) })
.c('enable', {xmlns: 'urn:xmpp:carbons:2'}); .c('enable', {xmlns: 'urn:xmpp:carbons:2'});
this.connection.addHandler($.proxy(function (iq) { this.connection.addHandler(function (iq) {
if ($(iq).find('error').length > 0) { if ($(iq).find('error').length > 0) {
converse.log('ERROR: An error occured while trying to enable message carbons.'); converse.log('ERROR: An error occured while trying to enable message carbons.');
} else { } else {
this.session.save({carbons_enabled: true}); this.session.save({carbons_enabled: true});
converse.log('Message carbons have been enabled.'); converse.log('Message carbons have been enabled.');
} }
}, this), null, "iq", null, "enablecarbons"); }.bind(this), null, "iq", null, "enablecarbons");
this.connection.send(carbons_iq); this.connection.send(carbons_iq);
}; };
@ -881,7 +881,7 @@
this.minimized_chats = new converse.MinimizedChats({model: this.chatboxes}); this.minimized_chats = new converse.MinimizedChats({model: this.chatboxes});
this.features = new this.Features(); this.features = new this.Features();
this.enableCarbons(); this.enableCarbons();
this.initStatus($.proxy(function () { this.initStatus(function () {
this.registerPingHandler(); this.registerPingHandler();
this.registerIntervalHandler(); this.registerIntervalHandler();
this.chatboxes.onConnected(); this.chatboxes.onConnected();
@ -897,7 +897,7 @@
this.callback(); this.callback();
} }
} }
}, this)); }.bind(this));
converse.emit('ready'); converse.emit('ready');
}; };
@ -1076,7 +1076,7 @@
// query message from our contact. Otherwise, it is us who will // query message from our contact. Otherwise, it is us who will
// send the query message to them. // send the query message to them.
this.save({'otr_status': UNENCRYPTED}); this.save({'otr_status': UNENCRYPTED});
var session = this.getSession($.proxy(function (session) { var session = this.getSession(function (session) {
this.otr = new OTR({ this.otr = new OTR({
fragment_size: 140, fragment_size: 140,
send_interval: 200, send_interval: 200,
@ -1084,18 +1084,18 @@
instance_tag: session.instance_tag, instance_tag: session.instance_tag,
debug: this.debug debug: this.debug
}); });
this.otr.on('status', $.proxy(this.updateOTRStatus, this)); this.otr.on('status', this.updateOTRStatus.bind(this));
this.otr.on('smp', $.proxy(this.onSMP, this)); this.otr.on('smp', this.onSMP.bind(this));
this.otr.on('ui', $.proxy(function (msg) { this.otr.on('ui', function (msg) {
this.trigger('showReceivedOTRMessage', msg); this.trigger('showReceivedOTRMessage', msg);
}, this)); }.bind(this));
this.otr.on('io', $.proxy(function (msg) { this.otr.on('io', function (msg) {
this.trigger('sendMessageStanza', msg); this.trigger('sendMessageStanza', msg);
}, this)); }.bind(this));
this.otr.on('error', $.proxy(function (msg) { this.otr.on('error', function (msg) {
this.trigger('showOTRError', msg); this.trigger('showOTRError', msg);
}, this)); }.bind(this));
this.trigger('showHelpMessages', [__('Exchanging private key with contact.')]); this.trigger('showHelpMessages', [__('Exchanging private key with contact.')]);
if (query_msg) { if (query_msg) {
@ -1103,7 +1103,7 @@
} else { } else {
this.otr.sendQueryMsg(); this.otr.sendQueryMsg();
} }
}, this)); }.bind(this));
}, },
endOTR: function () { endOTR: function () {
@ -1463,10 +1463,10 @@
} }
if (state === COMPOSING) { if (state === COMPOSING) {
this.chat_state_timeout = setTimeout( this.chat_state_timeout = setTimeout(
$.proxy(this.setChatState, this), converse.TIMEOUTS.PAUSED, PAUSED); this.setChatState.bind(this), converse.TIMEOUTS.PAUSED, PAUSED);
} else if (state === PAUSED) { } else if (state === PAUSED) {
this.chat_state_timeout = setTimeout( this.chat_state_timeout = setTimeout(
$.proxy(this.setChatState, this), converse.TIMEOUTS.INACTIVE, INACTIVE); this.setChatState.bind(this), converse.TIMEOUTS.INACTIVE, INACTIVE);
} }
if (!no_save && this.model.get('chat_state') != state) { if (!no_save && this.model.get('chat_state') != state) {
this.model.set('chat_state', state); this.model.set('chat_state', state);
@ -1689,7 +1689,7 @@
maximize: function () { maximize: function () {
var chatboxviews = converse.chatboxviews; var chatboxviews = converse.chatboxviews;
// Restores a minimized chat box // Restores a minimized chat box
this.$el.insertAfter(chatboxviews.get("controlbox").$el).show('fast', $.proxy(function () { this.$el.insertAfter(chatboxviews.get("controlbox").$el).show('fast', function () {
/* Now that the chat box is visible, we can call trimChats /* Now that the chat box is visible, we can call trimChats
* to make space available if need be. * to make space available if need be.
*/ */
@ -1697,7 +1697,7 @@
converse.refreshWebkit(); converse.refreshWebkit();
this.setChatState(ACTIVE).focus(); this.setChatState(ACTIVE).focus();
converse.emit('chatBoxMaximized', this); converse.emit('chatBoxMaximized', this);
}, this)); }.bind(this));
}, },
minimize: function (ev) { minimize: function (ev) {
@ -1715,14 +1715,14 @@
if ((contact) && (!contact.get('vcard_updated'))) { if ((contact) && (!contact.get('vcard_updated'))) {
converse.getVCard( converse.getVCard(
jid, jid,
$.proxy(function (iq, jid, fullname, image, image_type, url) { function (iq, jid, fullname, image, image_type, url) {
this.model.save({ this.model.save({
'fullname' : fullname || jid, 'fullname' : fullname || jid,
'url': url, 'url': url,
'image_type': image_type, 'image_type': image_type,
'image': image 'image': image
}); });
}, this), }.bind(this),
function () { function () {
converse.log("ChatBoxView.initialize: An error occured while fetching vcard"); converse.log("ChatBoxView.initialize: An error occured while fetching vcard");
} }
@ -2084,7 +2084,7 @@
converse.connection.disco.info( converse.connection.disco.info(
$(target).attr('data-room-jid'), $(target).attr('data-room-jid'),
null, null,
$.proxy(function (stanza) { function (stanza) {
var $stanza = $(stanza); var $stanza = $(stanza);
// All MUC features found here: http://xmpp.org/registrar/disco-features.html // All MUC features found here: http://xmpp.org/registrar/disco-features.html
$dd.find('span.spinner').replaceWith( $dd.find('span.spinner').replaceWith(
@ -2117,7 +2117,7 @@
'label_temp_room': _('Temporary room'), 'label_temp_room': _('Temporary room'),
'label_unmoderated': __('Unmoderated') 'label_unmoderated': __('Unmoderated')
})); }));
}, this)); }.bind(this));
} }
}, },
@ -2331,7 +2331,7 @@
}, },
show: function () { show: function () {
converse.controlboxtoggle.hide($.proxy(function () { converse.controlboxtoggle.hide(function () {
this.$el.show('fast', function () { this.$el.show('fast', function () {
if (converse.rosterview) { if (converse.rosterview) {
converse.rosterview.update(); converse.rosterview.update();
@ -2339,7 +2339,7 @@
converse.refreshWebkit(); converse.refreshWebkit();
}.bind(this)); }.bind(this));
converse.emit('controlBoxOpened', this); converse.emit('controlBoxOpened', this);
}, this)); }.bind(this));
return this; return this;
}, },
@ -2509,7 +2509,7 @@
suggestion: _.template('<p data-jid="{{jid}}">{{value}}</p>') suggestion: _.template('<p data-jid="{{jid}}">{{value}}</p>')
} }
}); });
$el.on('typeahead:selected', $.proxy(function (ev, suggestion, dname) { $el.on('typeahead:selected', function (ev, suggestion, dname) {
var reason = prompt( var reason = prompt(
__(___('You are about to invite %1$s to the chat room "%2$s". '), suggestion.value, this.model.get('id')) + __(___('You are about to invite %1$s to the chat room "%2$s". '), suggestion.value, this.model.get('id')) +
__("You may optionally include a message, explaining the reason for the invitation.") __("You may optionally include a message, explaining the reason for the invitation.")
@ -2518,7 +2518,7 @@
this.chatroomview.directInvite(suggestion.jid, reason); this.chatroomview.directInvite(suggestion.jid, reason);
} }
$(ev.target).typeahead('val', ''); $(ev.target).typeahead('val', '');
}, this)); }.bind(this));
return this; return this;
} }
@ -2614,16 +2614,16 @@
this.model.save({hidden_occupants: true}); this.model.save({hidden_occupants: true});
$el.removeClass('icon-hide-users').addClass('icon-show-users'); $el.removeClass('icon-hide-users').addClass('icon-show-users');
this.$('form.sendXMPPMessage, .chat-area').animate({width: '100%'}); this.$('form.sendXMPPMessage, .chat-area').animate({width: '100%'});
this.$('div.participants').animate({width: 0}, $.proxy(function () { this.$('div.participants').animate({width: 0}, function () {
this.scrollDown(); this.scrollDown();
}, this)); }.bind(this));
} else { } else {
this.model.save({hidden_occupants: false}); this.model.save({hidden_occupants: false});
$el.removeClass('icon-show-users').addClass('icon-hide-users'); $el.removeClass('icon-show-users').addClass('icon-hide-users');
this.$('.chat-area, form.sendXMPPMessage').css({width: ''}); this.$('.chat-area, form.sendXMPPMessage').css({width: ''});
this.$('div.participants').show().animate({width: 'auto'}, $.proxy(function () { this.$('div.participants').show().animate({width: 'auto'}, function () {
this.scrollDown(); this.scrollDown();
}, this)); }.bind(this));
} }
}, },
@ -2702,12 +2702,12 @@
case 'admin': case 'admin':
this.setAffiliation( this.setAffiliation(
this.model.get('jid'), args[0], 'admin', args[1], this.model.get('jid'), args[0], 'admin', args[1],
undefined, $.proxy(this.onCommandError, this)); undefined, this.onCommandError.bind(this));
break; break;
case 'ban': case 'ban':
this.setAffiliation( this.setAffiliation(
this.model.get('jid'), args[0], 'outcast', args[1], this.model.get('jid'), args[0], 'outcast', args[1],
undefined, $.proxy(this.onCommandError, this)); undefined, this.onCommandError.bind(this));
break; break;
case 'clear': case 'clear':
this.clearChatRoomMessages(); this.clearChatRoomMessages();
@ -2715,7 +2715,7 @@
case 'deop': case 'deop':
this.modifyRole( this.modifyRole(
this.model.get('jid'), args[0], 'participant', args[1], this.model.get('jid'), args[0], 'participant', args[1],
undefined, $.proxy(this.onCommandError, this)); undefined, this.onCommandError.bind(this));
break; break;
case 'help': case 'help':
this.showHelpMessages([ this.showHelpMessages([
@ -2739,17 +2739,17 @@
case 'kick': case 'kick':
this.modifyRole( this.modifyRole(
this.model.get('jid'), args[0], 'none', args[1], this.model.get('jid'), args[0], 'none', args[1],
undefined, $.proxy(this.onCommandError, this)); undefined, this.onCommandError.bind(this));
break; break;
case 'mute': case 'mute':
this.modifyRole( this.modifyRole(
this.model.get('jid'), args[0], 'visitor', args[1], this.model.get('jid'), args[0], 'visitor', args[1],
undefined, $.proxy(this.onCommandError, this)); undefined, this.onCommandError.bind(this));
break; break;
case 'member': case 'member':
this.setAffiliation( this.setAffiliation(
this.model.get('jid'), args[0], 'member', args[1], this.model.get('jid'), args[0], 'member', args[1],
undefined, $.proxy(this.onCommandError, this)); undefined, this.onCommandError.bind(this));
break; break;
case 'nick': case 'nick':
converse.connection.send($pres({ converse.connection.send($pres({
@ -2761,17 +2761,17 @@
case 'owner': case 'owner':
this.setAffiliation( this.setAffiliation(
this.model.get('jid'), args[0], 'owner', args[1], this.model.get('jid'), args[0], 'owner', args[1],
undefined, $.proxy(this.onCommandError, this)); undefined, this.onCommandError.bind(this));
break; break;
case 'op': case 'op':
this.modifyRole( this.modifyRole(
this.model.get('jid'), args[0], 'moderator', args[1], this.model.get('jid'), args[0], 'moderator', args[1],
undefined, $.proxy(this.onCommandError, this)); undefined, this.onCommandError.bind(this));
break; break;
case 'revoke': case 'revoke':
this.setAffiliation( this.setAffiliation(
this.model.get('jid'), args[0], 'none', args[1], this.model.get('jid'), args[0], 'none', args[1],
undefined, $.proxy(this.onCommandError, this)); undefined, this.onCommandError.bind(this));
break; break;
case 'topic': case 'topic':
converse.connection.send( converse.connection.send(
@ -2785,7 +2785,7 @@
case 'voice': case 'voice':
this.modifyRole( this.modifyRole(
this.model.get('jid'), args[0], 'participant', args[1], this.model.get('jid'), args[0], 'participant', args[1],
undefined, $.proxy(this.onCommandError, this)); undefined, this.onCommandError.bind(this));
break; break;
default: default:
this.createChatRoomMessage(text); this.createChatRoomMessage(text);
@ -2841,7 +2841,7 @@
msg.up.cnode(extended_presence); msg.up.cnode(extended_presence);
} }
if (!this.handler) { if (!this.handler) {
this.handler = converse.connection.addHandler($.proxy(this.handleMUCStanza, this)); this.handler = converse.connection.addHandler(this.handleMUCStanza.bind(this));
} }
this.model.set('connection_status', Strophe.Status.CONNECTING); this.model.set('connection_status', Strophe.Status.CONNECTING);
return converse.connection.send(msg); return converse.connection.send(msg);
@ -2859,7 +2859,7 @@
presence.c("status", exit_msg); presence.c("status", exit_msg);
} }
converse.connection.addHandler( converse.connection.addHandler(
$.proxy(function () { this.model.set('connection_status', Strophe.Status.DISCONNECTED); }, this), function () { this.model.set('connection_status', Strophe.Status.DISCONNECTED); }.bind(this),
null, "presence", null, presenceid); null, "presence", null, presenceid);
converse.connection.send(presence); converse.connection.send(presence);
}, },
@ -2881,7 +2881,7 @@
$form.append('<input type="submit" class="save-submit" value="'+__('Save')+'"/>'); $form.append('<input type="submit" class="save-submit" value="'+__('Save')+'"/>');
$form.append('<input type="button" class="cancel-submit" value="'+__('Cancel')+'"/>'); $form.append('<input type="button" class="cancel-submit" value="'+__('Cancel')+'"/>');
$form.on('submit', this.saveConfiguration.bind(this)); $form.on('submit', this.saveConfiguration.bind(this));
$form.find('input[type=button]').on('click', $.proxy(this.cancelConfiguration, this)); $form.find('input[type=button]').on('click', this.cancelConfiguration.bind(this));
}, },
sendConfiguration: function(config, onSuccess, onError) { sendConfiguration: function(config, onSuccess, onError) {
@ -2904,8 +2904,8 @@
if (!--count) { if (!--count) {
that.sendConfiguration( that.sendConfiguration(
configArray, configArray,
$.proxy(that.onConfigSaved, that), that.onConfigSaved.bind(that),
$.proxy(that.onErrorConfigSaved, that) that.onErrorConfigSaved.bind(that)
); );
} }
}); });
@ -2973,7 +2973,7 @@
label_password: __('Password: '), label_password: __('Password: '),
label_submit: __('Submit') label_submit: __('Submit')
})); }));
this.$('.chatroom-form').on('submit', $.proxy(this.submitPassword, this)); this.$('.chatroom-form').on('submit', this.submitPassword.bind(this));
}, },
showDisconnectMessage: function (msg) { showDisconnectMessage: function (msg) {
@ -3058,7 +3058,7 @@
disconnect_msgs = [], disconnect_msgs = [],
msgs = [], msgs = [],
reasons = []; reasons = [];
$el.find('x[xmlns="'+Strophe.NS.MUC_USER+'"]').each($.proxy(function (idx, x) { $el.find('x[xmlns="'+Strophe.NS.MUC_USER+'"]').each(function (idx, x) {
var $item = $(x).find('item'); var $item = $(x).find('item');
if (Strophe.getBareJidFromJid($item.attr('jid')) === converse.bare_jid && $item.attr('affiliation') === 'owner') { if (Strophe.getBareJidFromJid($item.attr('jid')) === converse.bare_jid && $item.attr('affiliation') === 'owner') {
this.$el.find('a.configure-chatroom-button').show(); this.$el.find('a.configure-chatroom-button').show();
@ -3068,7 +3068,7 @@
reasons.push($(reason).text()); reasons.push($(reason).text());
} }
}); });
$(x).find('status').each($.proxy(function (idx, stat) { $(x).find('status').each(function (idx, stat) {
var code = stat.getAttribute('code'); var code = stat.getAttribute('code');
var from_nick = Strophe.unescapeNode(Strophe.getResourceFromJid($el.attr('from'))); var from_nick = Strophe.unescapeNode(Strophe.getResourceFromJid($el.attr('from')));
if (is_self && code === "210") { if (is_self && code === "210") {
@ -3086,8 +3086,8 @@
msgs.push($(stat).text()); // Sometimes the status contains human readable text and not a code. msgs.push($(stat).text()); // Sometimes the status contains human readable text and not a code.
} }
} }
}, this)); }.bind(this));
}, this)); }.bind(this));
if (disconnect_msgs.length > 0) { if (disconnect_msgs.length > 0) {
for (i=0; i<disconnect_msgs.length; i++) { for (i=0; i<disconnect_msgs.length; i++) {
@ -3204,16 +3204,16 @@
registerMessageHandler: function () { registerMessageHandler: function () {
converse.connection.addHandler( converse.connection.addHandler(
$.proxy(function (message) { function (message) {
this.onMessage(message); this.onMessage(message);
return true; return true;
}, this), null, 'message', 'chat'); }.bind(this), null, 'message', 'chat');
converse.connection.addHandler( converse.connection.addHandler(
$.proxy(function (message) { function (message) {
this.onInvite(message); this.onInvite(message);
return true; return true;
}, this), 'jabber:x:conference', 'message'); }.bind(this), 'jabber:x:conference', 'message');
}, },
onConnected: function () { onConnected: function () {
@ -3222,7 +3222,7 @@
this.registerMessageHandler(); this.registerMessageHandler();
this.fetch({ this.fetch({
add: true, add: true,
success: $.proxy(function (collection, resp) { success: function (collection, resp) {
collection.each(function (chatbox) { collection.each(function (chatbox) {
if (chatbox.get('id') !== 'controlbox' && !chatbox.get('minimized')) { if (chatbox.get('id') !== 'controlbox' && !chatbox.get('minimized')) {
chatbox.trigger('show'); chatbox.trigger('show');
@ -3235,7 +3235,7 @@
}); });
} }
this.get('controlbox').save({connected:true}); this.get('controlbox').save({connected:true});
}, this) }.bind(this)
}); });
}, },
@ -4382,11 +4382,11 @@
var matches, rejects; var matches, rejects;
if (q.length === 0) { if (q.length === 0) {
if (this.model.get('state') === OPENED) { if (this.model.get('state') === OPENED) {
this.model.contacts.each($.proxy(function (item) { this.model.contacts.each(function (item) {
if (item.showInRoster()) { if (item.showInRoster()) {
this.get(item.get('id')).$el.show(); this.get(item.get('id')).$el.show();
} }
}, this)); }.bind(this));
} }
this.showIfNecessary(); this.showIfNecessary();
} else { } else {
@ -4395,12 +4395,12 @@
if (matches.length === this.model.contacts.length) { // hide the whole group if (matches.length === this.model.contacts.length) { // hide the whole group
this.hide(); this.hide();
} else { } else {
_.each(matches, $.proxy(function (item) { _.each(matches, function (item) {
this.get(item.get('id')).$el.hide(); this.get(item.get('id')).$el.hide();
}, this)); }.bind(this));
_.each(this.model.contacts.reject(contains.not('fullname', q)), $.proxy(function (item) { _.each(this.model.contacts.reject(contains.not('fullname', q)), function (item) {
this.get(item.get('id')).$el.show(); this.get(item.get('id')).$el.show();
}, this)); }.bind(this));
this.showIfNecessary(); this.showIfNecessary();
} }
} }
@ -4546,7 +4546,7 @@
silent: true, // We use the success handler to handle groups that were added, silent: true, // We use the success handler to handle groups that were added,
// we need to first have all groups before positionFetchedGroups // we need to first have all groups before positionFetchedGroups
// will work properly. // will work properly.
success: $.proxy(function (collection, resp, options) { success: function (collection, resp, options) {
if (collection.length !== 0) { if (collection.length !== 0) {
this.positionFetchedGroups(collection, resp, options); this.positionFetchedGroups(collection, resp, options);
} }
@ -4567,7 +4567,7 @@
} }
} }
}); });
}, this) }.bind(this)
}); });
return this; return this;
}, },
@ -4671,7 +4671,7 @@
window.setTimeout( window.setTimeout(
function () { function () {
converse.connection.flush(); converse.connection.flush();
$.proxy(converse.roster.subscribeToSuggestedItems, converse.roster)(msg); converse.roster.subscribeToSuggestedItems.bind(converse.roster)(msg);
}, },
t t
); );
@ -4684,10 +4684,10 @@
registerPresenceHandler: function () { registerPresenceHandler: function () {
converse.connection.addHandler( converse.connection.addHandler(
$.proxy(function (presence) { function (presence) {
converse.roster.presenceHandler(presence); converse.roster.presenceHandler(presence);
return true; return true;
}, this), null, 'presence', null); }.bind(this), null, 'presence', null);
}, },
onGroupAdd: function (group) { onGroupAdd: function (group) {
@ -4749,7 +4749,7 @@
* roster DOM element. * roster DOM element.
*/ */
model.sort(); model.sort();
model.each($.proxy(function (group, idx) { model.each(function (group, idx) {
var view = this.get(group.get('name')); var view = this.get(group.get('name'));
if (!view) { if (!view) {
view = new converse.RosterGroupView({model: group}); view = new converse.RosterGroupView({model: group});
@ -4760,7 +4760,7 @@
} else { } else {
this.appendGroup(view); this.appendGroup(view);
} }
}, this)); }.bind(this));
}, },
positionGroup: function (view) { positionGroup: function (view) {
@ -4817,9 +4817,7 @@
} else { } else {
groups = [HEADER_CURRENT_CONTACTS]; groups = [HEADER_CURRENT_CONTACTS];
} }
_.each(groups, $.proxy(function (name) { _.each(groups, _.bind(this.addContactToGroup, this, contact));
this.addContactToGroup(contact, name);
}, this));
}, },
addRosterContact: function (contact) { addRosterContact: function (contact) {
@ -4841,13 +4839,13 @@
this.set({ this.set({
'status' : this.getStatus() 'status' : this.getStatus()
}); });
this.on('change', $.proxy(function (item) { this.on('change', function (item) {
if (this.get('fullname') === undefined) { if (this.get('fullname') === undefined) {
converse.getVCard( converse.getVCard(
null, // No 'to' attr when getting one's own vCard null, // No 'to' attr when getting one's own vCard
$.proxy(function (iq, jid, fullname, image, image_type, url) { function (iq, jid, fullname, image, image_type, url) {
this.save({'fullname': fullname}); this.save({'fullname': fullname});
}, this) }.bind(this)
); );
} }
if (_.has(item.changed, 'status')) { if (_.has(item.changed, 'status')) {
@ -4856,7 +4854,7 @@
if (_.has(item.changed, 'status_message')) { if (_.has(item.changed, 'status_message')) {
converse.emit('statusMessageChanged', this.get('status_message')); converse.emit('statusMessageChanged', this.get('status_message'));
} }
}, this)); }.bind(this));
}, },
constructPresence: function (type, status_message) { constructPresence: function (type, status_message) {
@ -5054,8 +5052,8 @@
if (this.browserStorage.records.length === 0) { if (this.browserStorage.records.length === 0) {
// browserStorage is empty, so we've likely never queried this // browserStorage is empty, so we've likely never queried this
// domain for features yet // domain for features yet
converse.connection.disco.info(converse.domain, null, $.proxy(this.onInfo, this)); converse.connection.disco.info(converse.domain, null, this.onInfo.bind(this));
converse.connection.disco.items(converse.domain, null, $.proxy(this.onItems, this)); converse.connection.disco.items(converse.domain, null, this.onItems.bind(this));
} else { } else {
this.fetch({add:true}); this.fetch({add:true});
} }
@ -5089,12 +5087,12 @@
}, },
onItems: function (stanza) { onItems: function (stanza) {
$(stanza).find('query item').each($.proxy(function (idx, item) { $(stanza).find('query item').each(function (idx, item) {
converse.connection.disco.info( converse.connection.disco.info(
$(item).attr('jid'), $(item).attr('jid'),
null, null,
$.proxy(this.onInfo, this)); this.onInfo.bind(this));
}, this)); }(this));
}, },
onInfo: function (stanza) { onInfo: function (stanza) {
@ -5104,14 +5102,14 @@
// This isn't an IM server component // This isn't an IM server component
return; return;
} }
$stanza.find('feature').each($.proxy(function (idx, feature) { $stanza.find('feature').each(function (idx, feature) {
var namespace = $(feature).attr('var'); var namespace = $(feature).attr('var');
this[namespace] = true; this[namespace] = true;
this.create({ this.create({
'var': namespace, 'var': namespace,
'from': $stanza.attr('from') 'from': $stanza.attr('from')
}); });
}, this)); }(this));
} }
}); });
@ -5151,7 +5149,7 @@
*/ */
var conn = converse.connection; var conn = converse.connection;
var connect_cb = conn._connect_cb.bind(conn); var connect_cb = conn._connect_cb.bind(conn);
conn._connect_cb = $.proxy(function (req, callback, raw) { conn._connect_cb = function (req, callback, raw) {
if (!this._registering) { if (!this._registering) {
connect_cb(req, callback, raw); connect_cb(req, callback, raw);
} else { } else {
@ -5159,7 +5157,7 @@
this._registering = false; this._registering = false;
} }
} }
}, this); }.bind(this);
}, },
getRegistrationFields: function (req, _callback, raw) { getRegistrationFields: function (req, _callback, raw) {
@ -5250,12 +5248,12 @@
cancel: __('Cancel'), cancel: __('Cancel'),
info_message: __('Requesting a registration form from the XMPP server') info_message: __('Requesting a registration form from the XMPP server')
})); }));
$form.find('button.cancel').on('click', $.proxy(this.cancelRegistration, this)); $form.find('button.cancel').on('click', this.cancelRegistration.bind(this));
this.reset({ this.reset({
domain: Strophe.getDomainFromJid(domain), domain: Strophe.getDomainFromJid(domain),
_registering: true _registering: true
}); });
converse.connection.connect(this.domain, "", $.proxy(this.onRegistering, this)); converse.connection.connect(this.domain, "", this.onRegistering.bind(this));
return false; return false;
}, },
@ -5335,7 +5333,7 @@
}.bind(this)); }.bind(this));
} else { } else {
// Show fields // Show fields
_.each(Object.keys(this.fields), $.proxy(function (key) { _.each(Object.keys(this.fields), function (key) {
if (key == "username") { if (key == "username") {
$input = templates.form_username({ $input = templates.form_username({
domain: ' @'+this.domain, domain: ' @'+this.domain,
@ -5353,20 +5351,20 @@
} }
} }
$form.append($input); $form.append($input);
}, this)); }.bind(this));
// Show urls // Show urls
_.each(this.urls, $.proxy(function (url) { _.each(this.urls, function (url) {
$form.append($('<a target="blank"></a>').attr('href', url).text(url)); $form.append($('<a target="blank"></a>').attr('href', url).text(url));
}, this)); }.bind(this));
} }
if (this.fields) { if (this.fields) {
$form.append('<input type="submit" class="save-submit" value="'+__('Register')+'"/>'); $form.append('<input type="submit" class="save-submit" value="'+__('Register')+'"/>');
$form.on('submit', $.proxy(this.submitRegistrationForm, this)); $form.on('submit', this.submitRegistrationForm.bind(this));
$form.append('<input type="button" class="cancel-submit" value="'+__('Cancel')+'"/>'); $form.append('<input type="button" class="cancel-submit" value="'+__('Cancel')+'"/>');
$form.find('input[type=button]').on('click', $.proxy(this.cancelRegistration, this)); $form.find('input[type=button]').on('click', this.cancelRegistration.bind(this));
} else { } else {
$form.append('<input type="button" class="submit" value="'+__('Return')+'"/>'); $form.append('<input type="button" class="submit" value="'+__('Return')+'"/>');
$form.find('input[type=button]').on('click', $.proxy(this.cancelRegistration, this)); $form.find('input[type=button]').on('click', this.cancelRegistration.bind(this));
} }
}, },
@ -5463,28 +5461,28 @@
}, },
_setFieldsFromLegacy: function ($query) { _setFieldsFromLegacy: function ($query) {
$query.children().each($.proxy(function (idx, field) { $query.children().each(function (idx, field) {
var $field = $(field); var $field = $(field);
if (field.tagName.toLowerCase() === 'instructions') { if (field.tagName.toLowerCase() === 'instructions') {
this.instructions = Strophe.getText(field); this.instructions = Strophe.getText(field);
return; return;
} else if (field.tagName.toLowerCase() === 'x') { } else if (field.tagName.toLowerCase() === 'x') {
if ($field.attr('xmlns') === 'jabber:x:oob') { if ($field.attr('xmlns') === 'jabber:x:oob') {
$field.find('url').each($.proxy(function (idx, url) { $field.find('url').each(function (idx, url) {
this.urls.push($(url).text()); this.urls.push($(url).text());
}, this)); }.bind(this));
} }
return; return;
} }
this.fields[field.tagName.toLowerCase()] = Strophe.getText(field); this.fields[field.tagName.toLowerCase()] = Strophe.getText(field);
}, this)); }.bind(this));
this.form_type = 'legacy'; this.form_type = 'legacy';
}, },
_setFieldsFromXForm: function ($xform) { _setFieldsFromXForm: function ($xform) {
this.title = $xform.find('title').text(); this.title = $xform.find('title').text();
this.instructions = $xform.find('instructions').text(); this.instructions = $xform.find('instructions').text();
$xform.find('field').each($.proxy(function (idx, field) { $xform.find('field').each(function (idx, field) {
var _var = field.getAttribute('var'); var _var = field.getAttribute('var');
if (_var) { if (_var) {
this.fields[_var.toLowerCase()] = $(field).children('value').text(); this.fields[_var.toLowerCase()] = $(field).children('value').text();
@ -5492,7 +5490,7 @@
// TODO: other option seems to be type="fixed" // TODO: other option seems to be type="fixed"
console.log("WARNING: Found field we couldn't parse"); console.log("WARNING: Found field we couldn't parse");
} }
}, this)); }.bind(this));
this.form_type = 'xform'; this.form_type = 'xform';
}, },
@ -5876,7 +5874,7 @@
}; };
this._initializePlugins = function () { this._initializePlugins = function () {
_.each(this.plugins, $.proxy(function (plugin) { _.each(this.plugins, function (plugin) {
plugin.converse = converse; plugin.converse = converse;
_.each(Object.keys(plugin.overrides), function (key) { _.each(Object.keys(plugin.overrides), function (key) {
/* We automatically override all methods and Backbone views and /* We automatically override all methods and Backbone views and
@ -5894,9 +5892,9 @@
plugin.initialize.bind(plugin)(this); plugin.initialize.bind(plugin)(this);
} else { } else {
// This will be deprecated in 0.10 // This will be deprecated in 0.10
$.proxy(plugin, this)(this); plugin.bind(this)(this);
} }
}, this)); }.bind(this));
}; };
// Initialization // Initialization
@ -5914,15 +5912,15 @@
var wrappedChatBox = function (chatbox) { var wrappedChatBox = function (chatbox) {
var view = converse.chatboxviews.get(chatbox.get('jid')); var view = converse.chatboxviews.get(chatbox.get('jid'));
return { return {
'open': $.proxy(view.show, view), 'open': view.show.bind(view),
'close': $.proxy(view.close, view), 'close': view.close.bind(view),
'endOTR': $.proxy(chatbox.endOTR, chatbox), 'endOTR': chatbox.endOTR.bind(chatbox),
'focus': $.proxy(view.focus, view), 'focus': view.focus.bind(view),
'get': $.proxy(chatbox.get, chatbox), 'get': chatbox.get.bind(chatbox),
'initiateOTR': $.proxy(chatbox.initiateOTR, chatbox), 'initiateOTR': chatbox.initiateOTR.bind(chatbox),
'maximize': $.proxy(chatbox.maximize, chatbox), 'maximize': chatbox.maximize.bind(chatbox),
'minimize': $.proxy(chatbox.minimize, chatbox), 'minimize': chatbox.minimize.bind(chatbox),
'set': $.proxy(chatbox.set, chatbox) 'set': chatbox.set.bind(chatbox)
}; };
}; };