diff --git a/converse.js b/converse.js index f116154a5..5d1fee961 100644 --- a/converse.js +++ b/converse.js @@ -297,7 +297,7 @@ // Translation machinery // --------------------- - var __ = $.proxy(utils.__, this); + var __ = utils.__.bind(this); var ___ = utils.___; // Default configuration values @@ -565,7 +565,7 @@ return; } converse.connection.vcard.get( - $.proxy(function (iq) { // Successful callback + function (iq) { // Successful callback var $vcard = $(iq).find('vCard'); var fullname = $vcard.find('FN').text(), img = $vcard.find('BINVAL').text(), @@ -585,7 +585,7 @@ } } if (callback) { callback(iq, jid, fullname, img, img_type, url); } - }, this), + }.bind(this), jid, function (iq) { // Error callback 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; } ev.preventDefault(); 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; } ev.preventDefault(); var height = this.applyHeightResistance(this.resized_chatbox.height); @@ -765,18 +765,18 @@ this.resized_chatbox.model.set({'height': height}); } 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')) { converse.clearMsgCounter(); } this.windowState = ev.type; - },this)); + }.bind(this)); - $(window).on("resize", _.debounce($.proxy(function (ev) { + $(window).on("resize", _.debounce(function (ev) { this.chatboxviews.trimChats(); - },this), 200)); + }.bind(this), 200)); }; this.ping = function (jid, success, error, timeout) { @@ -836,14 +836,14 @@ this.onReconnected = function () { // We need to re-register all the event handlers on the newly // created connection. - this.initStatus($.proxy(function () { + this.initStatus(function () { this.registerPingHandler(); this.rosterview.registerRosterXHandler(); this.rosterview.registerPresenceHandler(); this.chatboxes.registerMessageHandler(); this.xmppstatus.sendPresence(); this.giveFeedback(__('Contacts')); - }, this)); + }.bind(this)); }; this.enableCarbons = function () { @@ -859,14 +859,14 @@ type: 'set' }) .c('enable', {xmlns: 'urn:xmpp:carbons:2'}); - this.connection.addHandler($.proxy(function (iq) { + this.connection.addHandler(function (iq) { if ($(iq).find('error').length > 0) { converse.log('ERROR: An error occured while trying to enable message carbons.'); } else { this.session.save({carbons_enabled: true}); converse.log('Message carbons have been enabled.'); } - }, this), null, "iq", null, "enablecarbons"); + }.bind(this), null, "iq", null, "enablecarbons"); this.connection.send(carbons_iq); }; @@ -881,7 +881,7 @@ this.minimized_chats = new converse.MinimizedChats({model: this.chatboxes}); this.features = new this.Features(); this.enableCarbons(); - this.initStatus($.proxy(function () { + this.initStatus(function () { this.registerPingHandler(); this.registerIntervalHandler(); this.chatboxes.onConnected(); @@ -897,7 +897,7 @@ this.callback(); } } - }, this)); + }.bind(this)); converse.emit('ready'); }; @@ -1076,7 +1076,7 @@ // query message from our contact. Otherwise, it is us who will // send the query message to them. this.save({'otr_status': UNENCRYPTED}); - var session = this.getSession($.proxy(function (session) { + var session = this.getSession(function (session) { this.otr = new OTR({ fragment_size: 140, send_interval: 200, @@ -1084,18 +1084,18 @@ instance_tag: session.instance_tag, debug: this.debug }); - this.otr.on('status', $.proxy(this.updateOTRStatus, this)); - this.otr.on('smp', $.proxy(this.onSMP, this)); + this.otr.on('status', this.updateOTRStatus.bind(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)); - this.otr.on('io', $.proxy(function (msg) { + }.bind(this)); + this.otr.on('io', function (msg) { this.trigger('sendMessageStanza', msg); - }, this)); - this.otr.on('error', $.proxy(function (msg) { + }.bind(this)); + this.otr.on('error', function (msg) { this.trigger('showOTRError', msg); - }, this)); + }.bind(this)); this.trigger('showHelpMessages', [__('Exchanging private key with contact.')]); if (query_msg) { @@ -1103,7 +1103,7 @@ } else { this.otr.sendQueryMsg(); } - }, this)); + }.bind(this)); }, endOTR: function () { @@ -1463,10 +1463,10 @@ } if (state === COMPOSING) { 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) { 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) { this.model.set('chat_state', state); @@ -1689,7 +1689,7 @@ maximize: function () { var chatboxviews = converse.chatboxviews; // 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 * to make space available if need be. */ @@ -1697,7 +1697,7 @@ converse.refreshWebkit(); this.setChatState(ACTIVE).focus(); converse.emit('chatBoxMaximized', this); - }, this)); + }.bind(this)); }, minimize: function (ev) { @@ -1715,14 +1715,14 @@ if ((contact) && (!contact.get('vcard_updated'))) { converse.getVCard( jid, - $.proxy(function (iq, jid, fullname, image, image_type, url) { + function (iq, jid, fullname, image, image_type, url) { this.model.save({ 'fullname' : fullname || jid, 'url': url, 'image_type': image_type, 'image': image }); - }, this), + }.bind(this), function () { converse.log("ChatBoxView.initialize: An error occured while fetching vcard"); } @@ -2084,7 +2084,7 @@ converse.connection.disco.info( $(target).attr('data-room-jid'), null, - $.proxy(function (stanza) { + function (stanza) { var $stanza = $(stanza); // All MUC features found here: http://xmpp.org/registrar/disco-features.html $dd.find('span.spinner').replaceWith( @@ -2117,7 +2117,7 @@ 'label_temp_room': _('Temporary room'), 'label_unmoderated': __('Unmoderated') })); - }, this)); + }.bind(this)); } }, @@ -2331,7 +2331,7 @@ }, show: function () { - converse.controlboxtoggle.hide($.proxy(function () { + converse.controlboxtoggle.hide(function () { this.$el.show('fast', function () { if (converse.rosterview) { converse.rosterview.update(); @@ -2339,7 +2339,7 @@ converse.refreshWebkit(); }.bind(this)); converse.emit('controlBoxOpened', this); - }, this)); + }.bind(this)); return this; }, @@ -2509,7 +2509,7 @@ suggestion: _.template('

{{value}}

') } }); - $el.on('typeahead:selected', $.proxy(function (ev, suggestion, dname) { + $el.on('typeahead:selected', function (ev, suggestion, dname) { var reason = prompt( __(___('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.") @@ -2518,7 +2518,7 @@ this.chatroomview.directInvite(suggestion.jid, reason); } $(ev.target).typeahead('val', ''); - }, this)); + }.bind(this)); return this; } @@ -2614,16 +2614,16 @@ this.model.save({hidden_occupants: true}); $el.removeClass('icon-hide-users').addClass('icon-show-users'); 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)); + }.bind(this)); } else { this.model.save({hidden_occupants: false}); $el.removeClass('icon-show-users').addClass('icon-hide-users'); 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)); + }.bind(this)); } }, @@ -2702,12 +2702,12 @@ case 'admin': this.setAffiliation( this.model.get('jid'), args[0], 'admin', args[1], - undefined, $.proxy(this.onCommandError, this)); + undefined, this.onCommandError.bind(this)); break; case 'ban': this.setAffiliation( this.model.get('jid'), args[0], 'outcast', args[1], - undefined, $.proxy(this.onCommandError, this)); + undefined, this.onCommandError.bind(this)); break; case 'clear': this.clearChatRoomMessages(); @@ -2715,7 +2715,7 @@ case 'deop': this.modifyRole( this.model.get('jid'), args[0], 'participant', args[1], - undefined, $.proxy(this.onCommandError, this)); + undefined, this.onCommandError.bind(this)); break; case 'help': this.showHelpMessages([ @@ -2739,17 +2739,17 @@ case 'kick': this.modifyRole( this.model.get('jid'), args[0], 'none', args[1], - undefined, $.proxy(this.onCommandError, this)); + undefined, this.onCommandError.bind(this)); break; case 'mute': this.modifyRole( this.model.get('jid'), args[0], 'visitor', args[1], - undefined, $.proxy(this.onCommandError, this)); + undefined, this.onCommandError.bind(this)); break; case 'member': this.setAffiliation( this.model.get('jid'), args[0], 'member', args[1], - undefined, $.proxy(this.onCommandError, this)); + undefined, this.onCommandError.bind(this)); break; case 'nick': converse.connection.send($pres({ @@ -2761,17 +2761,17 @@ case 'owner': this.setAffiliation( this.model.get('jid'), args[0], 'owner', args[1], - undefined, $.proxy(this.onCommandError, this)); + undefined, this.onCommandError.bind(this)); break; case 'op': this.modifyRole( this.model.get('jid'), args[0], 'moderator', args[1], - undefined, $.proxy(this.onCommandError, this)); + undefined, this.onCommandError.bind(this)); break; case 'revoke': this.setAffiliation( this.model.get('jid'), args[0], 'none', args[1], - undefined, $.proxy(this.onCommandError, this)); + undefined, this.onCommandError.bind(this)); break; case 'topic': converse.connection.send( @@ -2785,7 +2785,7 @@ case 'voice': this.modifyRole( this.model.get('jid'), args[0], 'participant', args[1], - undefined, $.proxy(this.onCommandError, this)); + undefined, this.onCommandError.bind(this)); break; default: this.createChatRoomMessage(text); @@ -2841,7 +2841,7 @@ msg.up.cnode(extended_presence); } 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); return converse.connection.send(msg); @@ -2859,7 +2859,7 @@ presence.c("status", exit_msg); } 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); converse.connection.send(presence); }, @@ -2881,7 +2881,7 @@ $form.append(''); $form.append(''); $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) { @@ -2904,8 +2904,8 @@ if (!--count) { that.sendConfiguration( configArray, - $.proxy(that.onConfigSaved, that), - $.proxy(that.onErrorConfigSaved, that) + that.onConfigSaved.bind(that), + that.onErrorConfigSaved.bind(that) ); } }); @@ -2973,7 +2973,7 @@ label_password: __('Password: '), label_submit: __('Submit') })); - this.$('.chatroom-form').on('submit', $.proxy(this.submitPassword, this)); + this.$('.chatroom-form').on('submit', this.submitPassword.bind(this)); }, showDisconnectMessage: function (msg) { @@ -3058,7 +3058,7 @@ disconnect_msgs = [], msgs = [], 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'); if (Strophe.getBareJidFromJid($item.attr('jid')) === converse.bare_jid && $item.attr('affiliation') === 'owner') { this.$el.find('a.configure-chatroom-button').show(); @@ -3068,7 +3068,7 @@ 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 from_nick = Strophe.unescapeNode(Strophe.getResourceFromJid($el.attr('from'))); if (is_self && code === "210") { @@ -3086,8 +3086,8 @@ msgs.push($(stat).text()); // Sometimes the status contains human readable text and not a code. } } - }, this)); - }, this)); + }.bind(this)); + }.bind(this)); if (disconnect_msgs.length > 0) { for (i=0; i').attr('href', url).text(url)); - }, this)); + }.bind(this)); } if (this.fields) { $form.append(''); - $form.on('submit', $.proxy(this.submitRegistrationForm, this)); + $form.on('submit', this.submitRegistrationForm.bind(this)); $form.append(''); - $form.find('input[type=button]').on('click', $.proxy(this.cancelRegistration, this)); + $form.find('input[type=button]').on('click', this.cancelRegistration.bind(this)); } else { $form.append(''); - $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) { - $query.children().each($.proxy(function (idx, field) { + $query.children().each(function (idx, field) { var $field = $(field); if (field.tagName.toLowerCase() === 'instructions') { this.instructions = Strophe.getText(field); return; } else if (field.tagName.toLowerCase() === 'x') { 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)); + }.bind(this)); } return; } this.fields[field.tagName.toLowerCase()] = Strophe.getText(field); - }, this)); + }.bind(this)); this.form_type = 'legacy'; }, _setFieldsFromXForm: function ($xform) { this.title = $xform.find('title').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'); if (_var) { this.fields[_var.toLowerCase()] = $(field).children('value').text(); @@ -5492,7 +5490,7 @@ // TODO: other option seems to be type="fixed" console.log("WARNING: Found field we couldn't parse"); } - }, this)); + }.bind(this)); this.form_type = 'xform'; }, @@ -5876,7 +5874,7 @@ }; this._initializePlugins = function () { - _.each(this.plugins, $.proxy(function (plugin) { + _.each(this.plugins, function (plugin) { plugin.converse = converse; _.each(Object.keys(plugin.overrides), function (key) { /* We automatically override all methods and Backbone views and @@ -5894,9 +5892,9 @@ plugin.initialize.bind(plugin)(this); } else { // This will be deprecated in 0.10 - $.proxy(plugin, this)(this); + plugin.bind(this)(this); } - }, this)); + }.bind(this)); }; // Initialization @@ -5914,15 +5912,15 @@ var wrappedChatBox = function (chatbox) { var view = converse.chatboxviews.get(chatbox.get('jid')); return { - 'open': $.proxy(view.show, view), - 'close': $.proxy(view.close, view), - 'endOTR': $.proxy(chatbox.endOTR, chatbox), - 'focus': $.proxy(view.focus, view), - 'get': $.proxy(chatbox.get, chatbox), - 'initiateOTR': $.proxy(chatbox.initiateOTR, chatbox), - 'maximize': $.proxy(chatbox.maximize, chatbox), - 'minimize': $.proxy(chatbox.minimize, chatbox), - 'set': $.proxy(chatbox.set, chatbox) + 'open': view.show.bind(view), + 'close': view.close.bind(view), + 'endOTR': chatbox.endOTR.bind(chatbox), + 'focus': view.focus.bind(view), + 'get': chatbox.get.bind(chatbox), + 'initiateOTR': chatbox.initiateOTR.bind(chatbox), + 'maximize': chatbox.maximize.bind(chatbox), + 'minimize': chatbox.minimize.bind(chatbox), + 'set': chatbox.set.bind(chatbox) }; };