Commit 3b71de7e authored by JC Brand's avatar JC Brand

Replace jQuery-based event emitter with Backbone.Events

parent 216606ae
# Changelog
## 2.0.5
## 3.0.0 (Unreleased)
- Breaking change: Callbacks for `converse.on` now no longer receive an event
object as first parameter. [jcbrand]
## 2.0.5 (Unreleased)
- #743, #751, #753 Update to Strophe 1.2.12. SASL-EXTERNAL now has reduced priority, so it won't
be prioritized above other auth mechanisms. [jcbrand]
- #755: create composer.json to add this project in packagist.org [fabiomontefuscolo]
......
......@@ -1047,7 +1047,7 @@ Allows you to show or hide buttons on the chat boxes' toolbars.
Provides a button with a picture of a telephone on it.
When the call button is pressed, it will emit an event that can be used by a third-party library to initiate a call.::
converse.listen.on('callButtonClicked', function(event, data) {
converse.listen.on('callButtonClicked', function(data) {
console.log('Strophe connection is', data.connection);
console.log('Bare buddy JID is', data.model.get('jid'));
// ... Third-party library code ...
......
......@@ -151,7 +151,7 @@ For example:
.. code-block:: javascript
converse.listen.on('serviceDiscovered', function (event, feature) {
converse.listen.on('serviceDiscovered', function (feature) {
if (feature.get('var') === converse.env.Strophe.NS.MAM) {
converse.archive.query()
}
......@@ -687,7 +687,7 @@ grouping:
.. code-block:: javascript
converse.listen.on('message', function (event, messageXML) { ... });
converse.listen.on('message', function (messageXML) { ... });
* **once(eventName, callback, [context])**:
......@@ -704,7 +704,7 @@ grouping:
.. code-block:: javascript
converse.listen.once('message', function (event, messageXML) { ... });
converse.listen.once('message', function (messageXML) { ... });
* **not(eventName, callback)**
......@@ -719,5 +719,5 @@ grouping:
.. code-block:: javascript
converse.listen.not('message', function (event, messageXML) { ... });
converse.listen.not('message', function (messageXML) { ... });
......@@ -160,15 +160,9 @@
}
},
'listen': {
'once': function (evt, handler, context) {
converse.once(evt, handler, context);
},
'on': function (evt, handler, context) {
converse.on(evt, handler, context);
},
'not': function (evt, handler) {
converse.off(evt, handler);
},
'once': converse.once,
'on': converse.on,
'not': converse.off,
'stanza': function (name, options, handler) {
if (typeof options === 'function') {
handler = options;
......
......@@ -43,41 +43,10 @@
interpolate : /\{\{([\s\S]+?)\}\}/g
};
// We create an object to act as the "this" context for event handlers (as
// defined below and accessible via converse_api.listen).
// We don't want the inner converse object to be the context, since it
// contains sensitive information, and we don't want it to be something in
// the DOM or window, because then anyone can trigger converse events.
var event_context = {};
var converse = {
templates: {},
emit: function (evt, data) {
$(event_context).trigger(evt, data);
},
once: function (evt, handler, context) {
if (context) {
handler = handler.bind(context);
}
$(event_context).one(evt, handler);
},
on: function (evt, handler, context) {
if (_.contains(['ready', 'initialized'], evt)) {
converse.log('Warning: The "'+evt+'" event has been deprecated and will be removed, please use "connected".');
}
if (context) {
handler = handler.bind(context);
}
$(event_context).bind(evt, handler);
},
off: function (evt, handler) {
$(event_context).unbind(evt, handler);
}
};
var converse = {};
converse.templates = {};
_.extend(converse, Backbone.Events);
converse.emit = converse.trigger;
// Make converse pluggable
pluggable.enable(converse, 'converse', 'pluggable');
......@@ -141,6 +110,8 @@
// out or disconnecting in the previous session.
// This happens in tests.
// We therefore first clean up.
converse.off();
converse.stopListening();
converse._tearDown();
}
......
......@@ -278,7 +278,7 @@
};
var onFeatureAdded = function (evt, feature) {
var onFeatureAdded = function (feature) {
var prefs = feature.get('preferences') || {};
if (feature.get('var') === Strophe.NS.MAM && prefs['default'] !== converse.message_archiving) {
// Ask the server for archiving preferences
......
......@@ -505,7 +505,7 @@
}
});
var renderMinimizeButton = function (evt, view) {
var renderMinimizeButton = function (view) {
// Inserts a "minimize" button in the chatview's header
var $el = view.$el.find('.toggle-chatbox-button');
var $new_el = converse.templates.chatbox_minimize(
......@@ -519,7 +519,7 @@
};
converse.on('chatBoxOpened', renderMinimizeButton);
converse.on('controlBoxOpened', function (evt, chatbox) {
converse.on('controlBoxOpened', function (chatbox) {
// Wrapped in anon method because at scan time, chatboxviews
// attr not set yet.
if (converse.connection.connected) {
......
......@@ -205,7 +205,7 @@
}
};
converse.handleChatStateNotification = function (evt, contact) {
converse.handleChatStateNotification = function (contact) {
/* Event handler for on('contactStatusChanged').
* Will show an HTML5 notification to indicate that the chat
* status has changed.
......@@ -215,7 +215,7 @@
}
};
converse.handleMessageNotification = function (evt, message) {
converse.handleMessageNotification = function (message) {
/* Event handler for the on('message') event. Will call methods
* to play sounds and show HTML5 notifications.
*/
......@@ -229,19 +229,19 @@
}
};
converse.handleContactRequestNotification = function (evt, contact) {
converse.handleContactRequestNotification = function (contact) {
if (converse.areDesktopNotificationsEnabled(true)) {
converse.showContactRequestNotification(contact);
}
};
converse.handleFeedback = function (evt, data) {
converse.handleFeedback = function (data) {
if (converse.areDesktopNotificationsEnabled(true)) {
converse.showFeedbackNotification(data);
}
};
converse.requestPermission = function (evt) {
converse.requestPermission = function () {
if (converse.supports_html5_notification &&
! _.contains(['denied', 'granted'], Notification.permission)) {
// Ask user to enable HTML5 notifications
......
......@@ -132,7 +132,7 @@
}
};
var updateVCardForChatBox = function (evt, chatbox) {
var updateVCardForChatBox = function (chatbox) {
if (!converse.use_vcards) { return; }
var jid = chatbox.model.get('jid'),
contact = converse.roster.get(jid);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment