Commit 0963f5c4 authored by JC Brand's avatar JC Brand

Add 'override' method for overriding converse Views and Models.

parent bb54874f
...@@ -4676,6 +4676,29 @@ ...@@ -4676,6 +4676,29 @@
'off': function (evt, handler) { 'off': function (evt, handler) {
converse.off(evt, handler); converse.off(evt, handler);
}, },
'override': function (obj, attributes) {
/* Helper method for overriding or extending Converse's Backbone Views or Models
*
* When a method is overriden, the original will still be available
* on the _super attribute of the object being overridden.
*
* obj: The Backbone View or Model
* attributes: A hash of attributes, such as you would pass to Backbone.Model.extend or Backbone.View.extend
*/
if (!obj.prototype._super) {
obj.prototype._super = {};
}
_.each(attributes, function (value, key) {
if (key === 'events') {
obj.prototype[key] = _.extend(value, obj.prototype[key]);
} else {
if (typeof key === 'function') {
obj.prototype._super[key] = obj.prototype[key];
}
obj.prototype[key] = value;
}
});
},
'registerPlugin': function (name, callback) { 'registerPlugin': function (name, callback) {
converse.plugins[name] = callback; converse.plugins[name] = callback;
}, },
......
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