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

Replace jQuery-based event emitter with Backbone.Events

parent 216606ae
# Changelog # 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 - #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] be prioritized above other auth mechanisms. [jcbrand]
- #755: create composer.json to add this project in packagist.org [fabiomontefuscolo] - #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. ...@@ -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. 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.:: 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('Strophe connection is', data.connection);
console.log('Bare buddy JID is', data.model.get('jid')); console.log('Bare buddy JID is', data.model.get('jid'));
// ... Third-party library code ... // ... Third-party library code ...
......
...@@ -151,7 +151,7 @@ For example: ...@@ -151,7 +151,7 @@ For example:
.. code-block:: javascript .. 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) { if (feature.get('var') === converse.env.Strophe.NS.MAM) {
converse.archive.query() converse.archive.query()
} }
...@@ -687,7 +687,7 @@ grouping: ...@@ -687,7 +687,7 @@ grouping:
.. code-block:: javascript .. code-block:: javascript
converse.listen.on('message', function (event, messageXML) { ... }); converse.listen.on('message', function (messageXML) { ... });
* **once(eventName, callback, [context])**: * **once(eventName, callback, [context])**:
...@@ -704,7 +704,7 @@ grouping: ...@@ -704,7 +704,7 @@ grouping:
.. code-block:: javascript .. code-block:: javascript
converse.listen.once('message', function (event, messageXML) { ... }); converse.listen.once('message', function (messageXML) { ... });
* **not(eventName, callback)** * **not(eventName, callback)**
...@@ -719,5 +719,5 @@ grouping: ...@@ -719,5 +719,5 @@ grouping:
.. code-block:: javascript .. code-block:: javascript
converse.listen.not('message', function (event, messageXML) { ... }); converse.listen.not('message', function (messageXML) { ... });
...@@ -160,15 +160,9 @@ ...@@ -160,15 +160,9 @@
} }
}, },
'listen': { 'listen': {
'once': function (evt, handler, context) { 'once': converse.once,
converse.once(evt, handler, context); 'on': converse.on,
}, 'not': converse.off,
'on': function (evt, handler, context) {
converse.on(evt, handler, context);
},
'not': function (evt, handler) {
converse.off(evt, handler);
},
'stanza': function (name, options, handler) { 'stanza': function (name, options, handler) {
if (typeof options === 'function') { if (typeof options === 'function') {
handler = options; handler = options;
......
...@@ -43,41 +43,10 @@ ...@@ -43,41 +43,10 @@
interpolate : /\{\{([\s\S]+?)\}\}/g interpolate : /\{\{([\s\S]+?)\}\}/g
}; };
// We create an object to act as the "this" context for event handlers (as var converse = {};
// defined below and accessible via converse_api.listen). converse.templates = {};
// We don't want the inner converse object to be the context, since it _.extend(converse, Backbone.Events);
// contains sensitive information, and we don't want it to be something in converse.emit = converse.trigger;
// 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);
}
};
// Make converse pluggable // Make converse pluggable
pluggable.enable(converse, 'converse', 'pluggable'); pluggable.enable(converse, 'converse', 'pluggable');
...@@ -141,6 +110,8 @@ ...@@ -141,6 +110,8 @@
// out or disconnecting in the previous session. // out or disconnecting in the previous session.
// This happens in tests. // This happens in tests.
// We therefore first clean up. // We therefore first clean up.
converse.off();
converse.stopListening();
converse._tearDown(); converse._tearDown();
} }
......
...@@ -278,7 +278,7 @@ ...@@ -278,7 +278,7 @@
}; };
var onFeatureAdded = function (evt, feature) { var onFeatureAdded = function (feature) {
var prefs = feature.get('preferences') || {}; var prefs = feature.get('preferences') || {};
if (feature.get('var') === Strophe.NS.MAM && prefs['default'] !== converse.message_archiving) { if (feature.get('var') === Strophe.NS.MAM && prefs['default'] !== converse.message_archiving) {
// Ask the server for archiving preferences // Ask the server for archiving preferences
......
...@@ -505,7 +505,7 @@ ...@@ -505,7 +505,7 @@
} }
}); });
var renderMinimizeButton = function (evt, view) { var renderMinimizeButton = function (view) {
// Inserts a "minimize" button in the chatview's header // Inserts a "minimize" button in the chatview's header
var $el = view.$el.find('.toggle-chatbox-button'); var $el = view.$el.find('.toggle-chatbox-button');
var $new_el = converse.templates.chatbox_minimize( var $new_el = converse.templates.chatbox_minimize(
...@@ -519,7 +519,7 @@ ...@@ -519,7 +519,7 @@
}; };
converse.on('chatBoxOpened', renderMinimizeButton); converse.on('chatBoxOpened', renderMinimizeButton);
converse.on('controlBoxOpened', function (evt, chatbox) { converse.on('controlBoxOpened', function (chatbox) {
// Wrapped in anon method because at scan time, chatboxviews // Wrapped in anon method because at scan time, chatboxviews
// attr not set yet. // attr not set yet.
if (converse.connection.connected) { if (converse.connection.connected) {
......
...@@ -205,7 +205,7 @@ ...@@ -205,7 +205,7 @@
} }
}; };
converse.handleChatStateNotification = function (evt, contact) { converse.handleChatStateNotification = function (contact) {
/* Event handler for on('contactStatusChanged'). /* Event handler for on('contactStatusChanged').
* Will show an HTML5 notification to indicate that the chat * Will show an HTML5 notification to indicate that the chat
* status has changed. * status has changed.
...@@ -215,7 +215,7 @@ ...@@ -215,7 +215,7 @@
} }
}; };
converse.handleMessageNotification = function (evt, message) { converse.handleMessageNotification = function (message) {
/* Event handler for the on('message') event. Will call methods /* Event handler for the on('message') event. Will call methods
* to play sounds and show HTML5 notifications. * to play sounds and show HTML5 notifications.
*/ */
...@@ -229,19 +229,19 @@ ...@@ -229,19 +229,19 @@
} }
}; };
converse.handleContactRequestNotification = function (evt, contact) { converse.handleContactRequestNotification = function (contact) {
if (converse.areDesktopNotificationsEnabled(true)) { if (converse.areDesktopNotificationsEnabled(true)) {
converse.showContactRequestNotification(contact); converse.showContactRequestNotification(contact);
} }
}; };
converse.handleFeedback = function (evt, data) { converse.handleFeedback = function (data) {
if (converse.areDesktopNotificationsEnabled(true)) { if (converse.areDesktopNotificationsEnabled(true)) {
converse.showFeedbackNotification(data); converse.showFeedbackNotification(data);
} }
}; };
converse.requestPermission = function (evt) { converse.requestPermission = function () {
if (converse.supports_html5_notification && if (converse.supports_html5_notification &&
! _.contains(['denied', 'granted'], Notification.permission)) { ! _.contains(['denied', 'granted'], Notification.permission)) {
// Ask user to enable HTML5 notifications // Ask user to enable HTML5 notifications
......
...@@ -132,7 +132,7 @@ ...@@ -132,7 +132,7 @@
} }
}; };
var updateVCardForChatBox = function (evt, chatbox) { var updateVCardForChatBox = function (chatbox) {
if (!converse.use_vcards) { return; } if (!converse.use_vcards) { return; }
var jid = chatbox.model.get('jid'), var jid = chatbox.model.get('jid'),
contact = converse.roster.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