Update plugins to not depend on converse-core

To illustrate that this is not necessary (and also not possible with
non-bundled plugins).
This commit is contained in:
JC Brand 2016-12-20 10:42:20 +00:00
parent b701c4830f
commit 9b48b2d6bd
17 changed files with 285 additions and 227 deletions

View File

@ -78,8 +78,8 @@ Below is an example code that wraps converse.js as an angular.js service.
"converse-headline", // Support for headline messages "converse-headline", // Support for headline messages
// END: Removable components // END: Removable components
], function(converse_api) { ], function(converse) {
service.api = converse_api; service.api = converse;
return deferred.resolve(); return deferred.resolve();
}); });
require(["converse"]); require(["converse"]);

View File

@ -16,7 +16,6 @@
"moment_with_locales", "moment_with_locales",
"strophe", "strophe",
"utils", "utils",
"converse-core",
"converse-api", "converse-api",
"converse-muc", "converse-muc",
"tpl!chatroom_bookmark_form", "tpl!chatroom_bookmark_form",
@ -27,26 +26,18 @@
factory); factory);
}(this, function ( }(this, function (
$, _, moment, strophe, utils, $, _, moment, strophe, utils,
_converse, converse_api, muc, converse, muc,
tpl_chatroom_bookmark_form, tpl_chatroom_bookmark_form,
tpl_chatroom_bookmark_toggle, tpl_chatroom_bookmark_toggle,
tpl_bookmark, tpl_bookmark,
tpl_bookmarks_list tpl_bookmarks_list
) { ) {
var __ = utils.__.bind(_converse), var Strophe = converse.env.Strophe,
___ = utils.___, $iq = converse.env.$iq,
Strophe = converse_api.env.Strophe, b64_sha1 = converse.env.b64_sha1;
$iq = converse_api.env.$iq,
b64_sha1 = converse_api.env.b64_sha1;
// Add new HTML templates. converse.plugins.add('converse-bookmarks', {
_converse.templates.chatroom_bookmark_form = tpl_chatroom_bookmark_form;
_converse.templates.chatroom_bookmark_toggle = tpl_chatroom_bookmark_toggle;
_converse.templates.bookmark = tpl_bookmark;
_converse.templates.bookmarks_list = tpl_bookmarks_list;
converse_api.plugins.add('converse-bookmarks', {
overrides: { overrides: {
// Overrides mentioned here will be picked up by converse.js's // Overrides mentioned here will be picked up by converse.js's
// plugin architecture they will replace existing methods on the // plugin architecture they will replace existing methods on the
@ -73,7 +64,9 @@
}, },
generateHeadingHTML: function () { generateHeadingHTML: function () {
var html = this.__super__.generateHeadingHTML.apply(this, arguments); var _converse = this.__super__._converse,
__ = _converse.__,
html = this.__super__.generateHeadingHTML.apply(this, arguments);
if (_converse.allow_bookmarks) { if (_converse.allow_bookmarks) {
var div = document.createElement('div'); var div = document.createElement('div');
div.innerHTML = html; div.innerHTML = html;
@ -97,6 +90,7 @@
* for this room, and if so use it. * for this room, and if so use it.
* Otherwise delegate to the super method. * Otherwise delegate to the super method.
*/ */
var _converse = this.__super__._converse;
if (_.isUndefined(_converse.bookmarks) || !_converse.allow_bookmarks) { if (_.isUndefined(_converse.bookmarks) || !_converse.allow_bookmarks) {
return this.__super__.checkForReservedNick.apply(this, arguments); return this.__super__.checkForReservedNick.apply(this, arguments);
} }
@ -119,6 +113,7 @@
setBookmarkState: function () { setBookmarkState: function () {
/* Set whether the room is bookmarked or not. /* Set whether the room is bookmarked or not.
*/ */
var _converse = this.__super__._converse;
if (!_.isUndefined(_converse.bookmarks)) { if (!_.isUndefined(_converse.bookmarks)) {
var models = _converse.bookmarks.where({'jid': this.model.get('jid')}); var models = _converse.bookmarks.where({'jid': this.model.get('jid')});
if (!models.length) { if (!models.length) {
@ -130,7 +125,9 @@
}, },
renderBookmarkForm: function () { renderBookmarkForm: function () {
var $body = this.$('.chatroom-body'); var _converse = this.__super__._converse,
__ = _converse.__,
$body = this.$('.chatroom-body');
$body.children().addClass('hidden'); $body.children().addClass('hidden');
// Remove any existing forms // Remove any existing forms
$body.find('form.chatroom-form').remove(); $body.find('form.chatroom-form').remove();
@ -150,6 +147,7 @@
onBookmarkFormSubmitted: function (ev) { onBookmarkFormSubmitted: function (ev) {
ev.preventDefault(); ev.preventDefault();
var _converse = this.__super__._converse;
var $form = $(ev.target), that = this; var $form = $(ev.target), that = this;
_converse.bookmarks.createBookmark({ _converse.bookmarks.createBookmark({
'jid': this.model.get('jid'), 'jid': this.model.get('jid'),
@ -169,6 +167,7 @@
ev.preventDefault(); ev.preventDefault();
ev.stopPropagation(); ev.stopPropagation();
} }
var _converse = this.__super__._converse;
var models = _converse.bookmarks.where({'jid': this.model.get('jid')}); var models = _converse.bookmarks.where({'jid': this.model.get('jid')});
if (!models.length) { if (!models.length) {
this.renderBookmarkForm(); this.renderBookmarkForm();
@ -186,7 +185,16 @@
/* The initialize function gets called as soon as the plugin is /* The initialize function gets called as soon as the plugin is
* loaded by converse.js's plugin machinery. * loaded by converse.js's plugin machinery.
*/ */
var _converse = this._converse; var _converse = this._converse,
__ = _converse.__,
___ = _converse.___;
// Add new HTML templates.
_converse.templates.chatroom_bookmark_form = tpl_chatroom_bookmark_form;
_converse.templates.chatroom_bookmark_toggle = tpl_chatroom_bookmark_toggle;
_converse.templates.bookmark = tpl_bookmark;
_converse.templates.bookmarks_list = tpl_bookmarks_list;
// Configuration values for this plugin // Configuration values for this plugin
// ==================================== // ====================================
// Refer to docs/source/configuration.rst for explanations of these // Refer to docs/source/configuration.rst for explanations of these

View File

@ -8,7 +8,6 @@
(function (root, factory) { (function (root, factory) {
define("converse-chatview", [ define("converse-chatview", [
"converse-core",
"converse-api", "converse-api",
"tpl!chatbox", "tpl!chatbox",
"tpl!new_day", "tpl!new_day",
@ -18,8 +17,7 @@
"tpl!avatar" "tpl!avatar"
], factory); ], factory);
}(this, function ( }(this, function (
_converse, converse,
converse_api,
tpl_chatbox, tpl_chatbox,
tpl_new_day, tpl_new_day,
tpl_action, tpl_action,
@ -28,28 +26,19 @@
tpl_avatar tpl_avatar
) { ) {
"use strict"; "use strict";
_converse.templates.chatbox = tpl_chatbox; var $ = converse.env.jQuery,
_converse.templates.new_day = tpl_new_day; utils = converse.env.utils,
_converse.templates.action = tpl_action; Strophe = converse.env.Strophe,
_converse.templates.message = tpl_message; $msg = converse.env.$msg,
_converse.templates.toolbar = tpl_toolbar; _ = converse.env._,
_converse.templates.avatar = tpl_avatar; moment = converse.env.moment;
var $ = converse_api.env.jQuery,
utils = converse_api.env.utils,
Strophe = converse_api.env.Strophe,
$msg = converse_api.env.$msg,
_ = converse_api.env._,
__ = utils.__.bind(_converse),
moment = converse_api.env.moment;
var KEY = { var KEY = {
ENTER: 13, ENTER: 13,
FORWARD_SLASH: 47 FORWARD_SLASH: 47
}; };
converse_api.plugins.add('converse-chatview', { converse.plugins.add('converse-chatview', {
overrides: { overrides: {
// Overrides mentioned here will be picked up by converse.js's // Overrides mentioned here will be picked up by converse.js's
@ -60,6 +49,7 @@
ChatBoxViews: { ChatBoxViews: {
onChatBoxAdded: function (item) { onChatBoxAdded: function (item) {
var _converse = this.__super__._converse;
var view = this.get(item.get('id')); var view = this.get(item.get('id'));
if (!view) { if (!view) {
view = new _converse.ChatBoxView({model: item}); view = new _converse.ChatBoxView({model: item});
@ -77,6 +67,17 @@
/* The initialize function gets called as soon as the plugin is /* The initialize function gets called as soon as the plugin is
* loaded by converse.js's plugin machinery. * loaded by converse.js's plugin machinery.
*/ */
var _converse = this._converse,
__ = _converse.__;
// Add new HTML templates.
_converse.templates.chatbox = tpl_chatbox;
_converse.templates.new_day = tpl_new_day;
_converse.templates.action = tpl_action;
_converse.templates.message = tpl_message;
_converse.templates.toolbar = tpl_toolbar;
_converse.templates.avatar = tpl_avatar;
this.updateSettings({ this.updateSettings({
show_toolbar: true, show_toolbar: true,
chatview_avatar_width: 32, chatview_avatar_width: 32,

View File

@ -8,7 +8,6 @@
(function (root, factory) { (function (root, factory) {
define("converse-controlbox", [ define("converse-controlbox", [
"converse-core",
"converse-api", "converse-api",
"tpl!add_contact_dropdown", "tpl!add_contact_dropdown",
"tpl!add_contact_form", "tpl!add_contact_form",
@ -27,8 +26,7 @@
"converse-rosterview" "converse-rosterview"
], factory); ], factory);
}(this, function ( }(this, function (
_converse, converse,
converse_api,
tpl_add_contact_dropdown, tpl_add_contact_dropdown,
tpl_add_contact_form, tpl_add_contact_form,
tpl_change_status_message, tpl_change_status_message,
@ -44,33 +42,19 @@
tpl_status_option tpl_status_option
) { ) {
"use strict"; "use strict";
_converse.templates.add_contact_dropdown = tpl_add_contact_dropdown;
_converse.templates.add_contact_form = tpl_add_contact_form;
_converse.templates.change_status_message = tpl_change_status_message;
_converse.templates.chat_status = tpl_chat_status;
_converse.templates.choose_status = tpl_choose_status;
_converse.templates.contacts_panel = tpl_contacts_panel;
_converse.templates.contacts_tab = tpl_contacts_tab;
_converse.templates.controlbox = tpl_controlbox;
_converse.templates.controlbox_toggle = tpl_controlbox_toggle;
_converse.templates.login_panel = tpl_login_panel;
_converse.templates.login_tab = tpl_login_tab;
_converse.templates.search_contact = tpl_search_contact;
_converse.templates.status_option = tpl_status_option;
var USERS_PANEL_ID = 'users'; var USERS_PANEL_ID = 'users';
// Strophe methods for building stanzas // Strophe methods for building stanzas
var Strophe = converse_api.env.Strophe, var Strophe = converse.env.Strophe,
utils = converse_api.env.utils; utils = converse.env.utils;
// Other necessary globals // Other necessary globals
var $ = converse_api.env.jQuery, var $ = converse.env.jQuery,
_ = converse_api.env._, _ = converse.env._,
__ = utils.__.bind(_converse), moment = converse.env.moment;
moment = converse_api.env.moment;
converse_api.plugins.add('converse-controlbox', { converse.plugins.add('converse-controlbox', {
overrides: { overrides: {
// Overrides mentioned here will be picked up by converse.js's // Overrides mentioned here will be picked up by converse.js's
@ -132,6 +116,7 @@
ChatBoxViews: { ChatBoxViews: {
onChatBoxAdded: function (item) { onChatBoxAdded: function (item) {
var _converse = this.__super__._converse;
if (item.get('box_id') === 'controlbox') { if (item.get('box_id') === 'controlbox') {
var view = this.get(item.get('id')); var view = this.get(item.get('id'));
if (view) { if (view) {
@ -148,6 +133,7 @@
}, },
closeAllChatBoxes: function () { closeAllChatBoxes: function () {
var _converse = this.__super__._converse;
this.each(function (view) { this.each(function (view) {
if (_converse.disconnection_cause === _converse.LOGOUT || if (_converse.disconnection_cause === _converse.LOGOUT ||
view.model.get('id') !== 'controlbox') { view.model.get('id') !== 'controlbox') {
@ -158,6 +144,7 @@
}, },
getChatBoxWidth: function (view) { getChatBoxWidth: function (view) {
var _converse = this.__super__._converse;
var controlbox = this.get('controlbox'); var controlbox = this.get('controlbox');
if (view.model.get('id') === 'controlbox') { if (view.model.get('id') === 'controlbox') {
/* We return the width of the controlbox or its toggle, /* We return the width of the controlbox or its toggle,
@ -191,6 +178,7 @@
ChatBoxView: { ChatBoxView: {
insertIntoDOM: function () { insertIntoDOM: function () {
var _converse = this.__super__._converse;
this.$el.insertAfter(_converse.chatboxviews.get("controlbox").$el); this.$el.insertAfter(_converse.chatboxviews.get("controlbox").$el);
return this; return this;
} }
@ -201,7 +189,24 @@
/* The initialize function gets called as soon as the plugin is /* The initialize function gets called as soon as the plugin is
* loaded by converse.js's plugin machinery. * loaded by converse.js's plugin machinery.
*/ */
var _converse = this._converse; var _converse = this._converse,
__ = _converse.__;
// Add new HTML templates.
_converse.templates.add_contact_dropdown = tpl_add_contact_dropdown;
_converse.templates.add_contact_form = tpl_add_contact_form;
_converse.templates.change_status_message = tpl_change_status_message;
_converse.templates.chat_status = tpl_chat_status;
_converse.templates.choose_status = tpl_choose_status;
_converse.templates.contacts_panel = tpl_contacts_panel;
_converse.templates.contacts_tab = tpl_contacts_tab;
_converse.templates.controlbox = tpl_controlbox;
_converse.templates.controlbox_toggle = tpl_controlbox_toggle;
_converse.templates.login_panel = tpl_login_panel;
_converse.templates.login_tab = tpl_login_tab;
_converse.templates.search_contact = tpl_search_contact;
_converse.templates.status_option = tpl_status_option;
this.updateSettings({ this.updateSettings({
allow_logout: true, allow_logout: true,
default_domain: undefined, default_domain: undefined,

View File

@ -171,7 +171,8 @@
// Translation machinery // Translation machinery
// --------------------- // ---------------------
var __ = utils.__.bind(this); var __ = _converse.__ = utils.__.bind(_converse);
_converse.___ = utils.___;
var DESC_GROUP_TOGGLE = __('Click to hide these contacts'); var DESC_GROUP_TOGGLE = __('Click to hide these contacts');
// Default configuration values // Default configuration values
@ -1133,7 +1134,7 @@
* Note: this method gets completely overridden by converse-vcard.js * Note: this method gets completely overridden by converse-vcard.js
*/ */
var bare_jid = Strophe.getBareJidFromJid(presence.getAttribute('from')); var bare_jid = Strophe.getBareJidFromJid(presence.getAttribute('from'));
var nick_el = presence.querySelector('nick[xmlns='+Strophe.NS.NICK+']'); var nick_el = presence.querySelector('nick[xmlns="'+Strophe.NS.NICK+'"]');
var user_data = { var user_data = {
jid: bare_jid, jid: bare_jid,
subscription: 'none', subscription: 'none',

View File

@ -8,20 +8,18 @@
(function (root, factory) { (function (root, factory) {
define("converse-dragresize", [ define("converse-dragresize", [
"converse-core",
"converse-api", "converse-api",
"tpl!dragresize", "tpl!dragresize",
"converse-chatview", "converse-chatview",
"converse-muc", // XXX: would like to remove this "converse-muc", // XXX: would like to remove this
"converse-controlbox" "converse-controlbox"
], factory); ], factory);
}(this, function (_converse, converse_api, tpl_dragresize) { }(this, function (converse, tpl_dragresize) {
"use strict"; "use strict";
var $ = converse_api.env.jQuery, var $ = converse.env.jQuery,
_ = converse_api.env._; _ = converse.env._;
_converse.templates.dragresize = tpl_dragresize;
converse_api.plugins.add('converse-dragresize', { converse.plugins.add('converse-dragresize', {
overrides: { overrides: {
// Overrides mentioned here will be picked up by converse.js's // Overrides mentioned here will be picked up by converse.js's
@ -31,38 +29,41 @@
// New functions which don't exist yet can also be added. // New functions which don't exist yet can also be added.
registerGlobalEventHandlers: function () { registerGlobalEventHandlers: function () {
var that = this;
$(document).on('mousemove', function (ev) { $(document).on('mousemove', function (ev) {
if (!this.resizing || !this.allow_dragresize) { return true; } if (!that.resizing || !that.allow_dragresize) { return true; }
ev.preventDefault(); ev.preventDefault();
this.resizing.chatbox.resizeChatBox(ev); that.resizing.chatbox.resizeChatBox(ev);
}.bind(this)); });
$(document).on('mouseup', function (ev) { $(document).on('mouseup', function (ev) {
if (!this.resizing || !this.allow_dragresize) { return true; } if (!that.resizing || !that.allow_dragresize) { return true; }
ev.preventDefault(); ev.preventDefault();
var height = this.applyDragResistance( var height = that.applyDragResistance(
this.resizing.chatbox.height, that.resizing.chatbox.height,
this.resizing.chatbox.model.get('default_height') that.resizing.chatbox.model.get('default_height')
); );
var width = this.applyDragResistance( var width = that.applyDragResistance(
this.resizing.chatbox.width, that.resizing.chatbox.width,
this.resizing.chatbox.model.get('default_width') that.resizing.chatbox.model.get('default_width')
); );
if (this.connection.connected) { if (that.connection.connected) {
this.resizing.chatbox.model.save({'height': height}); that.resizing.chatbox.model.save({'height': height});
this.resizing.chatbox.model.save({'width': width}); that.resizing.chatbox.model.save({'width': width});
} else { } else {
this.resizing.chatbox.model.set({'height': height}); that.resizing.chatbox.model.set({'height': height});
this.resizing.chatbox.model.set({'width': width}); that.resizing.chatbox.model.set({'width': width});
} }
this.resizing = null; that.resizing = null;
}.bind(this)); });
return this.__super__.registerGlobalEventHandlers.apply(this, arguments); return this.__super__.registerGlobalEventHandlers.apply(this, arguments);
}, },
ChatBox: { ChatBox: {
initialize: function () { initialize: function () {
var _converse = this.__super__._converse;
var result = this.__super__.initialize.apply(this, arguments), var result = this.__super__.initialize.apply(this, arguments),
height = this.get('height'), width = this.get('width'), height = this.get('height'), width = this.get('width'),
save = this.get('id') === 'controlbox' ? this.set.bind(this) : this.save.bind(this); save = this.get('id') === 'controlbox' ? this.set.bind(this) : this.save.bind(this);
@ -109,6 +110,7 @@
/* Determine and store the default box size. /* Determine and store the default box size.
* We need this information for the drag-resizing feature. * We need this information for the drag-resizing feature.
*/ */
var _converse = this.__super__._converse;
var $flyout = this.$el.find('.box-flyout'); var $flyout = this.$el.find('.box-flyout');
if (_.isUndefined(this.model.get('height'))) { if (_.isUndefined(this.model.get('height'))) {
var height = $flyout.height(); var height = $flyout.height();
@ -140,6 +142,7 @@
}, },
setChatBoxHeight: function (height) { setChatBoxHeight: function (height) {
var _converse = this.__super__._converse;
if (height) { if (height) {
height = _converse.applyDragResistance(height, this.model.get('default_height'))+'px'; height = _converse.applyDragResistance(height, this.model.get('default_height'))+'px';
} else { } else {
@ -149,6 +152,7 @@
}, },
setChatBoxWidth: function (width) { setChatBoxWidth: function (width) {
var _converse = this.__super__._converse;
if (width) { if (width) {
width = _converse.applyDragResistance(width, this.model.get('default_width'))+'px'; width = _converse.applyDragResistance(width, this.model.get('default_width'))+'px';
} else { } else {
@ -176,6 +180,7 @@
}, },
onStartVerticalResize: function (ev) { onStartVerticalResize: function (ev) {
var _converse = this.__super__._converse;
if (!_converse.allow_dragresize) { return true; } if (!_converse.allow_dragresize) { return true; }
// Record element attributes for mouseMove(). // Record element attributes for mouseMove().
this.height = this.$el.children('.box-flyout').height(); this.height = this.$el.children('.box-flyout').height();
@ -187,6 +192,7 @@
}, },
onStartHorizontalResize: function (ev) { onStartHorizontalResize: function (ev) {
var _converse = this.__super__._converse;
if (!_converse.allow_dragresize) { return true; } if (!_converse.allow_dragresize) { return true; }
this.width = this.$el.children('.box-flyout').width(); this.width = this.$el.children('.box-flyout').width();
_converse.resizing = { _converse.resizing = {
@ -197,6 +203,7 @@
}, },
onStartDiagonalResize: function (ev) { onStartDiagonalResize: function (ev) {
var _converse = this.__super__._converse;
this.onStartHorizontalResize(ev); this.onStartHorizontalResize(ev);
this.onStartVerticalResize(ev); this.onStartVerticalResize(ev);
_converse.resizing.direction = 'topleft'; _converse.resizing.direction = 'topleft';
@ -204,6 +211,7 @@
resizeChatBox: function (ev) { resizeChatBox: function (ev) {
var diff; var diff;
var _converse = this.__super__._converse;
if (_converse.resizing.direction.indexOf('top') === 0) { if (_converse.resizing.direction.indexOf('top') === 0) {
diff = ev.pageY - this.prev_pageY; diff = ev.pageY - this.prev_pageY;
if (diff) { if (diff) {
@ -286,6 +294,7 @@
}, },
renderDragResizeHandles: function () { renderDragResizeHandles: function () {
var _converse = this.__super__._converse;
var flyout = this.el.querySelector('.box-flyout'); var flyout = this.el.querySelector('.box-flyout');
var div = document.createElement('div'); var div = document.createElement('div');
div.innerHTML = _converse.templates.dragresize(); div.innerHTML = _converse.templates.dragresize();
@ -302,9 +311,14 @@
* loaded by converse.js's plugin machinery. * loaded by converse.js's plugin machinery.
*/ */
var _converse = this._converse; var _converse = this._converse;
// Add new HTML template
_converse.templates.dragresize = tpl_dragresize;
this.updateSettings({ this.updateSettings({
allow_dragresize: true, allow_dragresize: true,
}); });
_converse.applyDragResistance = function (value, default_value) { _converse.applyDragResistance = function (value, default_value) {
/* This method applies some resistance around the /* This method applies some resistance around the
* default_value. If value is close enough to * default_value. If value is close enough to

View File

@ -8,33 +8,15 @@
(function (root, factory) { (function (root, factory) {
define("converse-headline", [ define("converse-headline", [
"converse-core",
"converse-api", "converse-api",
"converse-chatview" "converse-chatview"
], factory); ], factory);
}(this, function (_converse, converse_api) { }(this, function (converse) {
"use strict"; "use strict";
var _ = converse_api.env._, var _ = converse.env._,
utils = converse_api.env.utils, utils = converse.env.utils;
__ = utils.__.bind(_converse);
var onHeadlineMessage = function (message) { converse.plugins.add('converse-headline', {
/* Handler method for all incoming messages of type "headline".
*/
var from_jid = message.getAttribute('from');
if (utils.isHeadlineMessage(message)) {
_converse.chatboxes.create({
'id': from_jid,
'jid': from_jid,
'fullname': from_jid,
'type': 'headline'
}).createMessage(message, undefined, message);
_converse.emit('message', message);
}
return true;
};
converse_api.plugins.add('converse-headline', {
overrides: { overrides: {
// Overrides mentioned here will be picked up by converse.js's // Overrides mentioned here will be picked up by converse.js's
@ -45,6 +27,7 @@
ChatBoxViews: { ChatBoxViews: {
onChatBoxAdded: function (item) { onChatBoxAdded: function (item) {
var _converse = this.__super__._converse;
var view = this.get(item.get('id')); var view = this.get(item.get('id'));
if (!view && item.get('type') === 'headline') { if (!view && item.get('type') === 'headline') {
view = new _converse.HeadlinesBoxView({model: item}); view = new _converse.HeadlinesBoxView({model: item});
@ -61,6 +44,9 @@
/* The initialize function gets called as soon as the plugin is /* The initialize function gets called as soon as the plugin is
* loaded by converse.js's plugin machinery. * loaded by converse.js's plugin machinery.
*/ */
var _converse = this._converse,
__ = _converse.__;
_converse.HeadlinesBoxView = _converse.ChatBoxView.extend({ _converse.HeadlinesBoxView = _converse.ChatBoxView.extend({
className: 'chatbox headlines', className: 'chatbox headlines',
@ -101,6 +87,22 @@
} }
}); });
var onHeadlineMessage = function (message) {
/* Handler method for all incoming messages of type "headline".
*/
var from_jid = message.getAttribute('from');
if (utils.isHeadlineMessage(message)) {
_converse.chatboxes.create({
'id': from_jid,
'jid': from_jid,
'fullname': from_jid,
'type': 'headline'
}).createMessage(message, undefined, message);
_converse.emit('message', message);
}
return true;
};
var registerHeadlineHandler = function () { var registerHeadlineHandler = function () {
_converse.connection.addHandler( _converse.connection.addHandler(
onHeadlineMessage, null, 'message'); onHeadlineMessage, null, 'message');

View File

@ -10,19 +10,18 @@
(function (root, factory) { (function (root, factory) {
define("converse-mam", [ define("converse-mam", [
"converse-core",
"converse-api", "converse-api",
"converse-chatview", // Could be made a soft dependency "converse-chatview", // Could be made a soft dependency
"converse-muc", // Could be made a soft dependency "converse-muc", // Could be made a soft dependency
"strophe.rsm" "strophe.rsm"
], factory); ], factory);
}(this, function (_converse, converse_api) { }(this, function (converse) {
"use strict"; "use strict";
var $ = converse_api.env.jQuery, var $ = converse.env.jQuery,
Strophe = converse_api.env.Strophe, Strophe = converse.env.Strophe,
$iq = converse_api.env.$iq, $iq = converse.env.$iq,
_ = converse_api.env._, _ = converse.env._,
moment = converse_api.env.moment; moment = converse.env.moment;
var RSM_ATTRIBUTES = ['max', 'first', 'last', 'after', 'before', 'index', 'count']; var RSM_ATTRIBUTES = ['max', 'first', 'last', 'after', 'before', 'index', 'count'];
// XEP-0313 Message Archive Management // XEP-0313 Message Archive Management
@ -32,7 +31,7 @@
Strophe.addNamespace('RSM', 'http://jabber.org/protocol/rsm'); Strophe.addNamespace('RSM', 'http://jabber.org/protocol/rsm');
converse_api.plugins.add('converse-mam', { converse.plugins.add('converse-mam', {
overrides: { overrides: {
// Overrides mentioned here will be picked up by converse.js's // Overrides mentioned here will be picked up by converse.js's
@ -43,6 +42,7 @@
Features: { Features: {
addClientFeatures: function () { addClientFeatures: function () {
var _converse = this.__super__._converse;
_converse.connection.disco.addFeature(Strophe.NS.MAM); _converse.connection.disco.addFeature(Strophe.NS.MAM);
return this.__super__.addClientFeatures.apply(this, arguments); return this.__super__.addClientFeatures.apply(this, arguments);
} }
@ -66,6 +66,7 @@
}, },
afterMessagesFetched: function () { afterMessagesFetched: function () {
var _converse = this.__super__._converse;
if (this.disable_mam || !_converse.features.findWhere({'var': Strophe.NS.MAM})) { if (this.disable_mam || !_converse.features.findWhere({'var': Strophe.NS.MAM})) {
return this.__super__.afterMessagesFetched.apply(this, arguments); return this.__super__.afterMessagesFetched.apply(this, arguments);
} }
@ -88,6 +89,7 @@
* Then, upon receiving them, call onMessage on the chat box, * Then, upon receiving them, call onMessage on the chat box,
* so that they are displayed inside it. * so that they are displayed inside it.
*/ */
var _converse = this.__super__._converse;
if (!_converse.features.findWhere({'var': Strophe.NS.MAM})) { if (!_converse.features.findWhere({'var': Strophe.NS.MAM})) {
_converse.log("Attempted to fetch archived messages but this user's server doesn't support XEP-0313"); _converse.log("Attempted to fetch archived messages but this user's server doesn't support XEP-0313");
return; return;
@ -110,6 +112,7 @@
}, },
onScroll: function (ev) { onScroll: function (ev) {
var _converse = this.__super__._converse;
if ($(ev.target).scrollTop() === 0 && this.model.messages.length) { if ($(ev.target).scrollTop() === 0 && this.model.messages.length) {
this.fetchArchivedMessages({ this.fetchArchivedMessages({
'before': this.model.messages.at(0).get('archive_id'), 'before': this.model.messages.at(0).get('archive_id'),
@ -138,6 +141,8 @@
/* The initialize function gets called as soon as the plugin is /* The initialize function gets called as soon as the plugin is
* loaded by Converse.js's plugin machinery. * loaded by Converse.js's plugin machinery.
*/ */
var _converse = this._converse;
this.updateSettings({ this.updateSettings({
archived_messages_page_size: '20', archived_messages_page_size: '20',
message_archiving: 'never', // Supported values are 'always', 'never', 'roster' (https://xmpp.org/extensions/xep-0313.html#prefs) message_archiving: 'never', // Supported values are 'always', 'never', 'roster' (https://xmpp.org/extensions/xep-0313.html#prefs)

View File

@ -8,7 +8,6 @@
(function (root, factory) { (function (root, factory) {
define("converse-minimize", [ define("converse-minimize", [
"converse-core",
"converse-api", "converse-api",
"tpl!chatbox_minimize", "tpl!chatbox_minimize",
"tpl!toggle_chats", "tpl!toggle_chats",
@ -19,27 +18,19 @@
"converse-muc" "converse-muc"
], factory); ], factory);
}(this, function ( }(this, function (
_converse, converse,
converse_api,
tpl_chatbox_minimize, tpl_chatbox_minimize,
tpl_toggle_chats, tpl_toggle_chats,
tpl_trimmed_chat, tpl_trimmed_chat,
tpl_chats_panel tpl_chats_panel
) { ) {
"use strict"; "use strict";
_converse.templates.chatbox_minimize = tpl_chatbox_minimize; var $ = converse.env.jQuery,
_converse.templates.toggle_chats = tpl_toggle_chats; _ = converse.env._,
_converse.templates.trimmed_chat = tpl_trimmed_chat; b64_sha1 = converse.env.b64_sha1,
_converse.templates.chats_panel = tpl_chats_panel; moment = converse.env.moment;
var $ = converse_api.env.jQuery, converse.plugins.add('converse-minimize', {
_ = converse_api.env._,
b64_sha1 = converse_api.env.b64_sha1,
moment = converse_api.env.moment,
utils = converse_api.env.utils,
__ = utils.__.bind(_converse);
converse_api.plugins.add('converse-minimize', {
overrides: { overrides: {
// Overrides mentioned here will be picked up by converse.js's // Overrides mentioned here will be picked up by converse.js's
@ -49,6 +40,7 @@
// New functions which don't exist yet can also be added. // New functions which don't exist yet can also be added.
initChatBoxes: function () { initChatBoxes: function () {
var _converse = this.__super__._converse;
var result = this.__super__.initChatBoxes.apply(this, arguments); var result = this.__super__.initChatBoxes.apply(this, arguments);
_converse.minimized_chats = new _converse.MinimizedChats({ _converse.minimized_chats = new _converse.MinimizedChats({
model: _converse.chatboxes model: _converse.chatboxes
@ -57,6 +49,7 @@
}, },
registerGlobalEventHandlers: function () { registerGlobalEventHandlers: function () {
var _converse = this.__super__._converse;
$(window).on("resize", _.debounce(function (ev) { $(window).on("resize", _.debounce(function (ev) {
if (_converse.connection.connected) { if (_converse.connection.connected) {
_converse.chatboxviews.trimChats(); _converse.chatboxviews.trimChats();
@ -114,6 +107,7 @@
}, },
_show: function () { _show: function () {
var _converse = this.__super__._converse;
this.__super__._show.apply(this, arguments); this.__super__._show.apply(this, arguments);
if (!this.model.get('minimized')) { if (!this.model.get('minimized')) {
_converse.chatboxviews.trimChats(this); _converse.chatboxviews.trimChats(this);
@ -147,6 +141,7 @@
maximize: function () { maximize: function () {
// Restores a minimized chat box // Restores a minimized chat box
var _converse = this.__super__._converse;
this.$el.insertAfter(_converse.chatboxviews.get("controlbox").$el); this.$el.insertAfter(_converse.chatboxviews.get("controlbox").$el);
this.show(); this.show();
_converse.emit('chatBoxMaximized', this); _converse.emit('chatBoxMaximized', this);
@ -154,6 +149,7 @@
}, },
minimize: function (ev) { minimize: function (ev) {
var _converse = this.__super__._converse;
if (ev && ev.preventDefault) { ev.preventDefault(); } if (ev && ev.preventDefault) { ev.preventDefault(); }
// save the scroll position to restore it on maximize // save the scroll position to restore it on maximize
this.model.save({'scroll': this.$content.scrollTop()}); this.model.save({'scroll': this.$content.scrollTop()});
@ -184,6 +180,8 @@
}, },
generateHeadingHTML: function () { generateHeadingHTML: function () {
var _converse = this.__super__._converse,
__ = _converse.__;
var html = this.__super__.generateHeadingHTML.apply(this, arguments); var html = this.__super__.generateHeadingHTML.apply(this, arguments);
var div = document.createElement('div'); var div = document.createElement('div');
div.innerHTML = html; div.innerHTML = html;
@ -243,6 +241,7 @@
* another chat box. Otherwise it minimizes the oldest chat box * another chat box. Otherwise it minimizes the oldest chat box
* to create space. * to create space.
*/ */
var _converse = this.__super__._converse;
var shown_chats = this.getShownChats(); var shown_chats = this.getShownChats();
if (_converse.no_trimming || shown_chats.length <= 1) { if (_converse.no_trimming || shown_chats.length <= 1) {
return; return;
@ -301,6 +300,15 @@
/* The initialize function gets called as soon as the plugin is /* The initialize function gets called as soon as the plugin is
* loaded by Converse.js's plugin machinery. * loaded by Converse.js's plugin machinery.
*/ */
var _converse = this._converse,
__ = _converse.__;
// Add new HTML templates.
_converse.templates.chatbox_minimize = tpl_chatbox_minimize;
_converse.templates.toggle_chats = tpl_toggle_chats;
_converse.templates.trimmed_chat = tpl_trimmed_chat;
_converse.templates.chats_panel = tpl_chats_panel;
this.updateSettings({ this.updateSettings({
no_trimming: false, // Set to true for phantomjs tests (where browser apparently has no width) no_trimming: false, // Set to true for phantomjs tests (where browser apparently has no width)
}); });

View File

@ -32,7 +32,7 @@
], factory); ], factory);
}(this, function ( }(this, function (
_converse, _converse,
converse_api, converse,
tpl_chatarea, tpl_chatarea,
tpl_chatroom, tpl_chatroom,
tpl_chatroom_form, tpl_chatroom_form,
@ -66,17 +66,17 @@
var ROOMS_PANEL_ID = 'chatrooms'; var ROOMS_PANEL_ID = 'chatrooms';
// Strophe methods for building stanzas // Strophe methods for building stanzas
var Strophe = converse_api.env.Strophe, var Strophe = converse.env.Strophe,
$iq = converse_api.env.$iq, $iq = converse.env.$iq,
$build = converse_api.env.$build, $build = converse.env.$build,
$msg = converse_api.env.$msg, $msg = converse.env.$msg,
$pres = converse_api.env.$pres, $pres = converse.env.$pres,
b64_sha1 = converse_api.env.b64_sha1, b64_sha1 = converse.env.b64_sha1,
utils = converse_api.env.utils; utils = converse.env.utils;
// Other necessary globals // Other necessary globals
var $ = converse_api.env.jQuery, var $ = converse.env.jQuery,
_ = converse_api.env._, _ = converse.env._,
moment = converse_api.env.moment; moment = converse.env.moment;
// For translations // For translations
var __ = utils.__.bind(_converse); var __ = utils.__.bind(_converse);
@ -89,7 +89,7 @@
Strophe.addNamespace('MUC_ROOMCONF', Strophe.NS.MUC + "#roomconfig"); Strophe.addNamespace('MUC_ROOMCONF', Strophe.NS.MUC + "#roomconfig");
Strophe.addNamespace('MUC_USER', Strophe.NS.MUC + "#user"); Strophe.addNamespace('MUC_USER', Strophe.NS.MUC + "#user");
converse_api.plugins.add('converse-muc', { converse.plugins.add('converse-muc', {
/* Optional dependencies are other plugins which might be /* Optional dependencies are other plugins which might be
* overridden or relied upon, if they exist, otherwise they're ignored. * overridden or relied upon, if they exist, otherwise they're ignored.
* *

View File

@ -7,25 +7,26 @@
/*global define */ /*global define */
(function (root, factory) { (function (root, factory) {
define("converse-notification", ["converse-core", "converse-api"], factory); define("converse-notification", ["converse-api"], factory);
}(this, function (_converse, converse_api) { }(this, function (converse) {
"use strict"; "use strict";
var $ = converse_api.env.jQuery, var $ = converse.env.jQuery,
utils = converse_api.env.utils, utils = converse.env.utils,
Strophe = converse_api.env.Strophe, Strophe = converse.env.Strophe,
_ = converse_api.env._; _ = converse.env._;
// For translations
var __ = utils.__.bind(_converse);
var ___ = utils.___;
converse.plugins.add('converse-notification', {
converse_api.plugins.add('converse-notification', {
initialize: function () { initialize: function () {
/* The initialize function gets called as soon as the plugin is /* The initialize function gets called as soon as the plugin is
* loaded by converse.js's plugin machinery. * loaded by converse.js's plugin machinery.
*/ */
var _converse = this._converse; var _converse = this._converse;
// For translations
var __ = _converse.__;
var ___ = _converse.___;
_converse.supports_html5_notification = "Notification" in window; _converse.supports_html5_notification = "Notification" in window;
this.updateSettings({ this.updateSettings({

View File

@ -12,23 +12,18 @@
(function (root, factory) { (function (root, factory) {
define("converse-otr", [ define("converse-otr", [
"otr", "otr",
"converse-core",
"converse-api", "converse-api",
"tpl!toolbar_otr" "tpl!toolbar_otr"
], factory); ], factory);
}(this, function (otr, _converse, converse_api, tpl_toolbar_otr) { }(this, function (otr, converse, tpl_toolbar_otr) {
"use strict"; "use strict";
_converse.templates.toolbar_otr = tpl_toolbar_otr;
// Strophe methods for building stanzas // Strophe methods for building stanzas
var Strophe = converse_api.env.Strophe, var Strophe = converse.env.Strophe,
utils = converse_api.env.utils, utils = converse.env.utils,
b64_sha1 = converse_api.env.b64_sha1; b64_sha1 = converse.env.b64_sha1;
// Other necessary globals // Other necessary globals
var $ = converse_api.env.jQuery, var $ = converse.env.jQuery,
_ = converse_api.env._; _ = converse.env._;
// For translations
var __ = utils.__.bind(_converse);
var HAS_CSPRNG = ((!_.isUndefined(crypto)) && var HAS_CSPRNG = ((!_.isUndefined(crypto)) &&
((_.isFunction(crypto.randomBytes)) || (_.isFunction(crypto.getRandomValues)) ((_.isFunction(crypto.randomBytes)) || (_.isFunction(crypto.getRandomValues))
@ -51,7 +46,7 @@
OTR_CLASS_MAPPING[VERIFIED] = 'verified'; OTR_CLASS_MAPPING[VERIFIED] = 'verified';
OTR_CLASS_MAPPING[FINISHED] = 'finished'; OTR_CLASS_MAPPING[FINISHED] = 'finished';
converse_api.plugins.add('converse-otr', { converse.plugins.add('converse-otr', {
overrides: { overrides: {
// Overrides mentioned here will be picked up by converse.js's // Overrides mentioned here will be picked up by converse.js's
@ -135,7 +130,8 @@
}, },
getSession: function (callback) { getSession: function (callback) {
var _converse = this.__super__._converse; var _converse = this.__super__._converse,
__ = _converse.__;
var cipher = CryptoJS.lib.PasswordBasedCipher; var cipher = CryptoJS.lib.PasswordBasedCipher;
var pass, instance_tag, saved_key, pass_check; var pass, instance_tag, saved_key, pass_check;
if (_converse.cache_otr_key) { if (_converse.cache_otr_key) {
@ -195,6 +191,8 @@
onSMP: function (type, data) { onSMP: function (type, data) {
// Event handler for SMP (Socialist's Millionaire Protocol) // Event handler for SMP (Socialist's Millionaire Protocol)
// used by OTR (off-the-record). // used by OTR (off-the-record).
var _converse = this.__super__._converse,
__ = _converse.__;
switch (type) { switch (type) {
case 'question': case 'question':
this.otr.smpSecret(prompt(__( this.otr.smpSecret(prompt(__(
@ -224,6 +222,8 @@
// If 'query_msg' is passed in, it means there is an alread incoming // If 'query_msg' is passed in, it means there is an alread incoming
// 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.
var _converse = this.__super__._converse,
__ = _converse.__;
this.save({'otr_status': UNENCRYPTED}); this.save({'otr_status': UNENCRYPTED});
this.getSession(function (session) { this.getSession(function (session) {
var _converse = this.__super__._converse; var _converse = this.__super__._converse;
@ -331,8 +331,10 @@
}, },
informOTRChange: function () { informOTRChange: function () {
var data = this.model.toJSON(); var _converse = this.__super__._converse,
var msgs = []; __ = _converse.__,
data = this.model.toJSON(),
msgs = [];
if (data.otr_status === UNENCRYPTED) { if (data.otr_status === UNENCRYPTED) {
msgs.push(__("Your messages are not encrypted anymore")); msgs.push(__("Your messages are not encrypted anymore"));
} else if (data.otr_status === UNVERIFIED) { } else if (data.otr_status === UNVERIFIED) {
@ -346,7 +348,8 @@
}, },
showOTRError: function (msg) { showOTRError: function (msg) {
var _converse = this.__super__._converse; var _converse = this.__super__._converse,
__ = _converse.__;
if (msg === 'Message cannot be sent at this time.') { if (msg === 'Message cannot be sent at this time.') {
this.showHelpMessages( this.showHelpMessages(
[__('Your message could not be sent')], 'error'); [__('Your message could not be sent')], 'error');
@ -378,9 +381,10 @@
}, },
authOTR: function (ev) { authOTR: function (ev) {
var _converse = this.__super__._converse; var _converse = this.__super__._converse,
var scheme = $(ev.target).data().scheme; __ = _converse.__,
var result, question, answer; scheme = $(ev.target).data().scheme,
result, question, answer;
if (scheme === 'fingerprint') { if (scheme === 'fingerprint') {
result = confirm(__('Here are the fingerprints, please confirm them with %1$s, outside of this chat.\n\nFingerprint for you, %2$s: %3$s\n\nFingerprint for %1$s: %4$s\n\nIf you have confirmed that the fingerprints match, click OK, otherwise click Cancel.', [ result = confirm(__('Here are the fingerprints, please confirm them with %1$s, outside of this chat.\n\nFingerprint for you, %2$s: %3$s\n\nFingerprint for %1$s: %4$s\n\nIf you have confirmed that the fingerprints match, click OK, otherwise click Cancel.', [
this.model.get('fullname'), this.model.get('fullname'),
@ -412,7 +416,9 @@
}, },
getOTRTooltip: function () { getOTRTooltip: function () {
var data = this.model.toJSON(); var _converse = this.__super__._converse,
__ = _converse.__,
data = this.model.toJSON();
if (data.otr_status === UNENCRYPTED) { if (data.otr_status === UNENCRYPTED) {
return __('Your messages are not encrypted. Click here to enable OTR encryption.'); return __('Your messages are not encrypted. Click here to enable OTR encryption.');
} else if (data.otr_status === UNVERIFIED) { } else if (data.otr_status === UNVERIFIED) {
@ -425,7 +431,8 @@
}, },
renderToolbar: function (toolbar, options) { renderToolbar: function (toolbar, options) {
var _converse = this.__super__._converse; var _converse = this.__super__._converse,
__ = _converse.__;
if (!_converse.show_toolbar) { if (!_converse.show_toolbar) {
return; return;
} }
@ -461,7 +468,12 @@
/* The initialize function gets called as soon as the plugin is /* The initialize function gets called as soon as the plugin is
* loaded by converse.js's plugin machinery. * loaded by converse.js's plugin machinery.
*/ */
var _converse = this._converse; var _converse = this._converse,
__ = _converse.__;
// Add new HTML template
_converse.templates.toolbar_otr = tpl_toolbar_otr;
// Translation aware constants // Translation aware constants
// --------------------------- // ---------------------------
// We can only call the __ translation method *after* converse.js // We can only call the __ translation method *after* converse.js

View File

@ -11,16 +11,15 @@
*/ */
(function (root, factory) { (function (root, factory) {
define("converse-ping", [ define("converse-ping", [
"converse-core",
"converse-api", "converse-api",
"strophe.ping" "strophe.ping"
], factory); ], factory);
}(this, function (_converse, converse_api) { }(this, function (converse) {
"use strict"; "use strict";
// Strophe methods for building stanzas // Strophe methods for building stanzas
var Strophe = converse_api.env.Strophe; var Strophe = converse.env.Strophe;
converse_api.plugins.add('converse-ping', { converse.plugins.add('converse-ping', {
initialize: function () { initialize: function () {
/* The initialize function gets called as soon as the plugin is /* The initialize function gets called as soon as the plugin is

View File

@ -11,7 +11,6 @@
*/ */
(function (root, factory) { (function (root, factory) {
define("converse-register", [ define("converse-register", [
"converse-core",
"converse-api", "converse-api",
"tpl!form_username", "tpl!form_username",
"tpl!register_panel", "tpl!register_panel",
@ -21,8 +20,7 @@
"converse-controlbox" "converse-controlbox"
], factory); ], factory);
}(this, function ( }(this, function (
_converse, converse,
converse_api,
tpl_form_username, tpl_form_username,
tpl_register_panel, tpl_register_panel,
tpl_register_tab, tpl_register_tab,
@ -30,21 +28,14 @@
tpl_registration_request) { tpl_registration_request) {
"use strict"; "use strict";
_converse.templates.form_username = tpl_form_username;
_converse.templates.register_panel = tpl_register_panel;
_converse.templates.register_tab = tpl_register_tab;
_converse.templates.registration_form = tpl_registration_form;
_converse.templates.registration_request = tpl_registration_request;
// Strophe methods for building stanzas // Strophe methods for building stanzas
var Strophe = converse_api.env.Strophe, var Strophe = converse.env.Strophe,
utils = converse_api.env.utils, utils = converse.env.utils,
$iq = converse_api.env.$iq; $iq = converse.env.$iq;
// Other necessary globals // Other necessary globals
var $ = converse_api.env.jQuery, var $ = converse.env.jQuery,
_ = converse_api.env._; _ = converse.env._;
// For translations
var __ = utils.__.bind(_converse);
// Add Strophe Namespaces // Add Strophe Namespaces
Strophe.addNamespace('REGISTER', 'jabber:iq:register'); Strophe.addNamespace('REGISTER', 'jabber:iq:register');
@ -59,7 +50,7 @@
Strophe.Status.CONFLICT = i + 3; Strophe.Status.CONFLICT = i + 3;
Strophe.Status.NOTACCEPTABLE = i + 5; Strophe.Status.NOTACCEPTABLE = i + 5;
converse_api.plugins.add('converse-register', { converse.plugins.add('converse-register', {
overrides: { overrides: {
// Overrides mentioned here will be picked up by converse.js's // Overrides mentioned here will be picked up by converse.js's
@ -92,7 +83,15 @@
/* The initialize function gets called as soon as the plugin is /* The initialize function gets called as soon as the plugin is
* loaded by converse.js's plugin machinery. * loaded by converse.js's plugin machinery.
*/ */
var _converse = this._converse; var _converse = this._converse,
__ = _converse.__;
// Add new templates
_converse.templates.form_username = tpl_form_username;
_converse.templates.register_panel = tpl_register_panel;
_converse.templates.register_tab = tpl_register_tab;
_converse.templates.registration_form = tpl_registration_form;
_converse.templates.registration_request = tpl_registration_request;
this.updateSettings({ this.updateSettings({
allow_registration: true, allow_registration: true,
@ -100,7 +99,6 @@
providers_link: 'https://xmpp.net/directory.php', // Link to XMPP providers shown on registration page providers_link: 'https://xmpp.net/directory.php', // Link to XMPP providers shown on registration page
}); });
_converse.RegisterPanel = Backbone.View.extend({ _converse.RegisterPanel = Backbone.View.extend({
tagName: 'div', tagName: 'div',
id: "register", id: "register",

View File

@ -8,7 +8,6 @@
(function (root, factory) { (function (root, factory) {
define("converse-rosterview", [ define("converse-rosterview", [
"converse-core",
"converse-api", "converse-api",
"tpl!group_header", "tpl!group_header",
"tpl!pending_contact", "tpl!pending_contact",
@ -17,29 +16,21 @@
"tpl!roster_item" "tpl!roster_item"
], factory); ], factory);
}(this, function ( }(this, function (
_converse, converse,
converse_api,
tpl_group_header, tpl_group_header,
tpl_pending_contact, tpl_pending_contact,
tpl_requesting_contact, tpl_requesting_contact,
tpl_roster, tpl_roster,
tpl_roster_item) { tpl_roster_item) {
"use strict"; "use strict";
_converse.templates.group_header = tpl_group_header; var $ = converse.env.jQuery,
_converse.templates.pending_contact = tpl_pending_contact; utils = converse.env.utils,
_converse.templates.requesting_contact = tpl_requesting_contact; Strophe = converse.env.Strophe,
_converse.templates.roster = tpl_roster; $iq = converse.env.$iq,
_converse.templates.roster_item = tpl_roster_item; b64_sha1 = converse.env.b64_sha1,
_ = converse.env._;
var $ = converse_api.env.jQuery, converse.plugins.add('rosterview', {
utils = converse_api.env.utils,
Strophe = converse_api.env.Strophe,
$iq = converse_api.env.$iq,
b64_sha1 = converse_api.env.b64_sha1,
_ = converse_api.env._,
__ = utils.__.bind(_converse);
converse_api.plugins.add('rosterview', {
overrides: { overrides: {
// Overrides mentioned here will be picked up by converse.js's // Overrides mentioned here will be picked up by converse.js's
@ -66,6 +57,7 @@
comparator: function () { comparator: function () {
// RosterGroupsComparator only gets set later (once i18n is // RosterGroupsComparator only gets set later (once i18n is
// set up), so we need to wrap it in this nameless function. // set up), so we need to wrap it in this nameless function.
var _converse = this.__super__._converse;
return _converse.RosterGroupsComparator.apply(this, arguments); return _converse.RosterGroupsComparator.apply(this, arguments);
} }
} }
@ -76,6 +68,16 @@
/* The initialize function gets called as soon as the plugin is /* The initialize function gets called as soon as the plugin is
* loaded by converse.js's plugin machinery. * loaded by converse.js's plugin machinery.
*/ */
var _converse = this._converse,
__ = _converse.__;
// Add new HTML templates
_converse.templates.group_header = tpl_group_header;
_converse.templates.pending_contact = tpl_pending_contact;
_converse.templates.requesting_contact = tpl_requesting_contact;
_converse.templates.roster = tpl_roster;
_converse.templates.roster_item = tpl_roster_item;
this.updateSettings({ this.updateSettings({
allow_chat_pending_contacts: true, allow_chat_pending_contacts: true,
allow_contact_removal: true, allow_contact_removal: true,

View File

@ -8,18 +8,17 @@
(function (root, factory) { (function (root, factory) {
define("converse-vcard", [ define("converse-vcard", [
"converse-core",
"converse-api", "converse-api",
"strophe.vcard", "strophe.vcard",
], factory); ], factory);
}(this, function (_converse, converse_api) { }(this, function (converse) {
"use strict"; "use strict";
var Strophe = converse_api.env.Strophe, var Strophe = converse.env.Strophe,
$ = converse_api.env.jQuery, $ = converse.env.jQuery,
_ = converse_api.env._, _ = converse.env._,
moment = converse_api.env.moment; moment = converse.env.moment;
converse_api.plugins.add('converse-vcard', { converse.plugins.add('converse-vcard', {
overrides: { overrides: {
// Overrides mentioned here will be picked up by converse.js's // Overrides mentioned here will be picked up by converse.js's
@ -30,6 +29,7 @@
Features: { Features: {
addClientFeatures: function () { addClientFeatures: function () {
var _converse = this.__super__._converse;
this.__super__.addClientFeatures.apply(this, arguments); this.__super__.addClientFeatures.apply(this, arguments);
if (_converse.use_vcards) { if (_converse.use_vcards) {
_converse.connection.disco.addFeature(Strophe.NS.VCARD); _converse.connection.disco.addFeature(Strophe.NS.VCARD);
@ -39,6 +39,7 @@
RosterContacts: { RosterContacts: {
createRequestingContact: function (presence) { createRequestingContact: function (presence) {
var _converse = this.__super__._converse;
var bare_jid = Strophe.getBareJidFromJid(presence.getAttribute('from')); var bare_jid = Strophe.getBareJidFromJid(presence.getAttribute('from'));
_converse.getVCard( _converse.getVCard(
bare_jid, bare_jid,
@ -57,6 +58,7 @@
/* The initialize function gets called as soon as the plugin is /* The initialize function gets called as soon as the plugin is
* loaded by converse.js's plugin machinery. * loaded by converse.js's plugin machinery.
*/ */
var _converse = this._converse;
this.updateSettings({ this.updateSettings({
use_vcards: true, use_vcards: true,
}); });

View File

@ -34,9 +34,9 @@ if (typeof define !== 'undefined') {
"converse-headline", // Support for headline messages "converse-headline", // Support for headline messages
/* END: Removable components */ /* END: Removable components */
], function(converse_api) { ], function(converse) {
converse_api.env.jQuery(window).trigger('converse-loaded', converse_api); converse.env.jQuery(window).trigger('converse-loaded', converse);
window.converse = converse_api; window.converse = converse;
return converse_api; return converse;
}); });
} }