// Licensed under the Mozilla Public License (MPLv2)
//
/*global define, escape, Jed */
(function (root, factory) {
define('form-utils',["sizzle", "lodash.noconflict", "utils", "tpl!field", "tpl!select_option", "tpl!form_select", "tpl!form_textarea", "tpl!form_checkbox", "tpl!form_username", "tpl!form_input", "tpl!form_captcha", "tpl!form_url"], factory);
})(this, function (sizzle, _, u, tpl_field, tpl_select_option, tpl_form_select, tpl_form_textarea, tpl_form_checkbox, tpl_form_username, tpl_form_input, tpl_form_captcha, tpl_form_url) {
"use strict";
var XFORM_TYPE_MAP = {
'text-private': 'password',
'text-single': 'text',
'fixed': 'label',
'boolean': 'checkbox',
'hidden': 'hidden',
'jid-multi': 'textarea',
'list-single': 'dropdown',
'list-multi': 'dropdown'
};
u.webForm2xForm = function (field) {
/* Takes an HTML DOM and turns it into an XForm field.
*
* Parameters:
* (DOMElement) field - the field to convert
*/
var value;
if (field.getAttribute('type') === 'checkbox') {
value = field.checked && 1 || 0;
} else if (field.tagName == "textarea") {
value = _.filter(field.value.split('\n'), _.trim);
} else {
value = field.value;
}
return u.stringToNode(tpl_field({
name: field.getAttribute('name'),
value: value
}));
};
u.xForm2webForm = function (field, stanza, domain) {
/* Takes a field in XMPP XForm (XEP-004: Data Forms) format
* and turns it into an HTML field.
*
* Returns either text or a DOM element (which is not ideal, but fine
* for now).
*
* Parameters:
* (XMLElement) field - the field to convert
*/
if (field.getAttribute('type')) {
if (field.getAttribute('type') === 'list-single' || field.getAttribute('type') === 'list-multi') {
var values = _.map(u.queryChildren(field, 'value'), _.partial(_.get, _, 'textContent'));
var options = _.map(u.queryChildren(field, 'option'), function (option) {
var value = _.get(option.querySelector('value'), 'textContent');
return tpl_select_option({
'value': value,
'label': option.getAttribute('label'),
'selected': _.startsWith(values, value),
'required': !_.isNil(field.querySelector('required'))
});
});
return tpl_form_select({
'name': field.getAttribute('var'),
'label': field.getAttribute('label'),
'options': options.join(''),
'multiple': field.getAttribute('type') === 'list-multi',
'required': !_.isNil(field.querySelector('required'))
});
} else if (field.getAttribute('type') === 'fixed') {
var text = _.get(field.querySelector('value'), 'textContent');
return '' + text + '
';
} else if (field.getAttribute('type') === 'jid-multi') {
return tpl_form_textarea({
'name': field.getAttribute('var'),
'label': field.getAttribute('label') || '',
'value': _.get(field.querySelector('value'), 'textContent'),
'required': !_.isNil(field.querySelector('required'))
});
} else if (field.getAttribute('type') === 'boolean') {
return tpl_form_checkbox({
'name': field.getAttribute('var'),
'type': XFORM_TYPE_MAP[field.getAttribute('type')],
'label': field.getAttribute('label') || '',
'checked': _.get(field.querySelector('value'), 'textContent') === "1" && 'checked="1"' || '',
'required': !_.isNil(field.querySelector('required'))
});
} else if (field.getAttribute('var') === 'url') {
return tpl_form_url({
'label': field.getAttribute('label') || '',
'value': _.get(field.querySelector('value'), 'textContent')
});
} else if (field.getAttribute('var') === 'username') {
return tpl_form_username({
'domain': ' @' + domain,
'name': field.getAttribute('var'),
'type': XFORM_TYPE_MAP[field.getAttribute('type')],
'label': field.getAttribute('label') || '',
'value': _.get(field.querySelector('value'), 'textContent'),
'required': !_.isNil(field.querySelector('required'))
});
} else {
return tpl_form_input({
'label': field.getAttribute('label') || '',
'name': field.getAttribute('var'),
'placeholder': null,
'required': !_.isNil(field.querySelector('required')),
'type': XFORM_TYPE_MAP[field.getAttribute('type')],
'value': _.get(field.querySelector('value'), 'textContent')
});
}
} else {
if (field.getAttribute('var') === 'ocr') {
// Captcha
var uri = field.querySelector('uri');
var el = sizzle('data[cid="' + uri.textContent.replace(/^cid:/, '') + '"]', stanza)[0];
return tpl_form_captcha({
'label': field.getAttribute('label'),
'name': field.getAttribute('var'),
'data': _.get(el, 'textContent'),
'type': uri.getAttribute('type'),
'required': !_.isNil(field.querySelector('required'))
});
}
}
};
return u;
});
//# sourceMappingURL=form-utils.js.map;
define('tpl!chatarea', ['lodash'], function(_) {return function(o) {
var __t, __p = '', __e = _.escape, __j = Array.prototype.join;
function print() { __p += __j.call(arguments, '') }
__p += '\n
\n
▼ ' +
__e( o.unread_msgs ) +
' ▼
\n
\n
\n';
return __p
};});
define('tpl!chatroom', ['lodash'], function(_) {return function(o) {
var __t, __p = '';
__p += '\n';
return __p
};});
define('tpl!chatroom_disconnect', ['lodash'], function(_) {return function(o) {
var __t, __p = '', __e = _.escape;
__p += '' +
__e(o.disconnect_message) +
'
\n';
return __p
};});
define('tpl!chatroom_features', ['lodash'], function(_) {return function(o) {
var __t, __p = '', __e = _.escape, __j = Array.prototype.join;
function print() { __p += __j.call(arguments, '') }
if (o.has_features) { ;
__p += '\n' +
__e(o.label_features) +
'
\n';
} ;
__p += '\n\n';
if (o.passwordprotected) { ;
__p += '\n- ' +
__e( o.label_passwordprotected ) +
'
\n';
} ;
__p += '\n';
if (o.unsecured) { ;
__p += '\n- ' +
__e( o.label_unsecured ) +
'
\n';
} ;
__p += '\n';
if (o.hidden) { ;
__p += '\n- ' +
__e( o.label_hidden ) +
'
\n';
} ;
__p += '\n';
if (o.public_room) { ;
__p += '\n- ' +
__e( o.label_public ) +
'
\n';
} ;
__p += '\n';
if (o.membersonly) { ;
__p += '\n- ' +
__e( o.label_membersonly ) +
'
\n';
} ;
__p += '\n';
if (o.open) { ;
__p += '\n- ' +
__e( o.label_open ) +
'
\n';
} ;
__p += '\n';
if (o.persistent) { ;
__p += '\n- ' +
__e( o.label_persistent ) +
'
\n';
} ;
__p += '\n';
if (o.temporary) { ;
__p += '\n- ' +
__e( o.label_temporary ) +
'
\n';
} ;
__p += '\n';
if (o.nonanonymous) { ;
__p += '\n- ' +
__e( o.label_nonanonymous ) +
'
\n';
} ;
__p += '\n';
if (o.semianonymous) { ;
__p += '\n- ' +
__e( o.label_semianonymous ) +
'
\n';
} ;
__p += '\n';
if (o.moderated) { ;
__p += '\n- ' +
__e( o.label_moderated ) +
'
\n';
} ;
__p += '\n';
if (o.unmoderated) { ;
__p += '\n- ' +
__e( o.label_unmoderated ) +
'
\n';
} ;
__p += '\n';
if (o.mam_enabled) { ;
__p += '\n- ' +
__e( o.label_mam_enabled ) +
'
\n';
} ;
__p += '\n
\n';
return __p
};});
define('tpl!chatroom_form', ['lodash'], function(_) {return function(o) {
var __t, __p = '';
__p += '\n
\n\n';
return __p
};});
define('tpl!chatroom_head', ['lodash'], function(_) {return function(o) {
var __t, __p = '', __e = _.escape, __j = Array.prototype.join;
function print() { __p += __j.call(arguments, '') }
__p += '\n';
if (o.affiliation == 'owner') { ;
__p += '\n \n';
} ;
__p += '\n\n ';
if (o.name && o.name !== o.Strophe.getNodeFromJid(o.jid)) { ;
__p += '\n
' +
__e( o.name ) +
'\n ';
} else { ;
__p += '\n
' +
__e( o.Strophe.getNodeFromJid(o.jid) ) +
'@' +
__e( o.Strophe.getDomainFromJid(o.jid) ) +
'\n ';
} ;
__p += '\n
' +
__e( o.description ) +
'
\n
\n';
return __p
};});
define('tpl!chatroom_invite', ['lodash'], function(_) {return function(o) {
var __t, __p = '', __e = _.escape, __j = Array.prototype.join;
function print() { __p += __j.call(arguments, '') }
__p += '\n';
return __p
};});
define('tpl!chatroom_join_form', ['lodash'], function(_) {return function(o) {
var __t, __p = '', __e = _.escape, __j = Array.prototype.join;
function print() { __p += __j.call(arguments, '') }
__p += '\n';
return __p
};});
define('tpl!chatroom_nickname_form', ['lodash'], function(_) {return function(o) {
var __t, __p = '', __e = _.escape;
__p += '\n';
return __p
};});
define('tpl!chatroom_password_form', ['lodash'], function(_) {return function(o) {
var __t, __p = '', __e = _.escape;
__p += '\n
\n\n';
return __p
};});
define('tpl!chatroom_sidebar', ['lodash'], function(_) {return function(o) {
var __t, __p = '', __e = _.escape;
__p += '\n' +
__e(o.label_occupants) +
'
\n\n\n\n';
return __p
};});
define('tpl!chatroom_toolbar', ['lodash'], function(_) {return function(o) {
var __t, __p = '', __e = _.escape, __j = Array.prototype.join;
function print() { __p += __j.call(arguments, '') }
if (o.use_emoji) { ;
__p += '\n\n';
} ;
__p += '\n';
if (o.show_call_button) { ;
__p += '\n\n';
} ;
__p += '\n';
if (o.show_occupants_toggle) { ;
__p += '\n\n';
} ;
__p += '\n';
if (o.show_clear_button) { ;
__p += '\n\n';
} ;
__p += '\n\n';
return __p
};});
define('tpl!chatrooms_tab', ['lodash'], function(_) {return function(o) {
var __t, __p = '', __e = _.escape, __j = Array.prototype.join;
function print() { __p += __j.call(arguments, '') }
__p += '\n ' +
__e(o.label_rooms) +
'\n ';
if (o.num_unread) { ;
__p += '\n ' +
__e(o. num_unread ) +
'\n ';
} ;
__p += '\n\n';
return __p
};});
define('tpl!occupant', ['lodash'], function(_) {return function(o) {
var __t, __p = '', __e = _.escape, __j = Array.prototype.join;
function print() { __p += __j.call(arguments, '') }
__p += '' +
__e(o.nick) +
'\n';
return __p
};});
define('tpl!room_description', ['lodash'], function(_) {return function(o) {
var __t, __p = '', __e = _.escape, __j = Array.prototype.join;
function print() { __p += __j.call(arguments, '') }
__p += '\n\n
' +
__e(o.label_jid) +
' ' +
__e(o.jid) +
'
\n
' +
__e(o.label_desc) +
' ' +
__e(o.desc) +
'
\n
' +
__e(o.label_occ) +
' ' +
__e(o.occ) +
'
\n
' +
__e(o.label_features) +
'\n
\n ';
if (o.passwordprotected) { ;
__p += '\n - ' +
__e(o.label_requires_auth) +
'
\n ';
} ;
__p += '\n ';
if (o.hidden) { ;
__p += '\n - ' +
__e(o.label_hidden) +
'
\n ';
} ;
__p += '\n ';
if (o.membersonly) { ;
__p += '\n - ' +
__e(o.label_requires_invite) +
'
\n ';
} ;
__p += '\n ';
if (o.moderated) { ;
__p += '\n - ' +
__e(o.label_moderated) +
'
\n ';
} ;
__p += '\n ';
if (o.nonanonymous) { ;
__p += '\n - ' +
__e(o.label_non_anon) +
'
\n ';
} ;
__p += '\n ';
if (o.open) { ;
__p += '\n - ' +
__e(o.label_open_room) +
'
\n ';
} ;
__p += '\n ';
if (o.persistent) { ;
__p += '\n - ' +
__e(o.label_permanent_room) +
'
\n ';
} ;
__p += '\n ';
if (o.publicroom) { ;
__p += '\n - ' +
__e(o.label_public) +
'
\n ';
} ;
__p += '\n ';
if (o.semianonymous) { ;
__p += '\n - ' +
__e(o.label_semi_anon) +
'
\n ';
} ;
__p += '\n ';
if (o.temporary) { ;
__p += '\n - ' +
__e(o.label_temp_room) +
'
\n ';
} ;
__p += '\n ';
if (o.unmoderated) { ;
__p += '\n - ' +
__e(o.label_unmoderated) +
'
\n ';
} ;
__p += '\n
\n\n
\n';
return __p
};});
define('tpl!room_item', ['lodash'], function(_) {return function(o) {
var __t, __p = '', __e = _.escape;
__p += '\n' +
__e(o.name) +
'\n \n\n';
return __p
};});
define('tpl!room_panel', ['lodash'], function(_) {return function(o) {
var __t, __p = '';
__p += '\n\n';
return __p
};});
define('tpl!rooms_results', ['lodash'], function(_) {return function(o) {
var __t, __p = '', __e = _.escape;
__p += '' +
__e( o.feedback_text ) +
'\n';
return __p
};});
// Converse.js (A browser based XMPP chat client)
// http://conversejs.org
//
// Copyright (c) 2012-2017, Jan-Carel Brand
// Licensed under the Mozilla Public License (MPLv2)
//
/* This is a Converse.js plugin which add support for XEP-0030: Service Discovery */
/*global Backbone, define, window */
(function (root, factory) {
define('converse-disco',["converse-core", "sizzle", "strophe.disco"], factory);
})(this, function (converse, sizzle) {
var _converse$env = converse.env,
Backbone = _converse$env.Backbone,
Promise = _converse$env.Promise,
Strophe = _converse$env.Strophe,
b64_sha1 = _converse$env.b64_sha1,
utils = _converse$env.utils,
_ = _converse$env._;
converse.plugins.add('converse-disco', {
initialize: function initialize() {
/* The initialize function gets called as soon as the plugin is
* loaded by converse.js's plugin machinery.
*/
var _converse = this._converse;
function onDiscoItems(stanza) {
_.each(stanza.querySelectorAll('query item'), function (item) {
if (item.getAttribute("node")) {
// XXX: ignore nodes for now.
// See: https://xmpp.org/extensions/xep-0030.html#items-nodes
return;
}
var jid = item.getAttribute('jid');
var entities = _converse.disco_entities;
if (_.isUndefined(entities.get(jid))) {
entities.create({
'jid': jid
});
}
});
} // Promises exposed by this plugin
_converse.api.promises.add('discoInitialized');
_converse.DiscoEntity = Backbone.Model.extend({
/* A Disco Entity is a JID addressable entity that can be queried
* for features.
*
* See XEP-0030: https://xmpp.org/extensions/xep-0030.html
*/
idAttribute: 'jid',
initialize: function initialize() {
this.waitUntilFeaturesDiscovered = utils.getResolveablePromise();
this.features = new Backbone.Collection();
this.features.browserStorage = new Backbone.BrowserStorage[_converse.storage](b64_sha1("converse.features-".concat(this.get('jid'))));
this.features.on('add', this.onFeatureAdded, this);
this.identities = new Backbone.Collection();
this.identities.browserStorage = new Backbone.BrowserStorage[_converse.storage](b64_sha1("converse.identities-".concat(this.get('jid'))));
this.fetchFeatures();
},
getIdentity: function getIdentity(category, type) {
/* Returns a Promise which resolves with a map indicating
* whether a given identity is provided.
*
* Parameters:
* (String) category - The identity category
* (String) type - The identity type
*/
var entity = this;
return new Promise(function (resolve, reject) {
function fulfillPromise() {
var model = entity.identities.findWhere({
'category': category,
'type': type
});
resolve(model);
}
entity.waitUntilFeaturesDiscovered.then(fulfillPromise).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
});
},
hasFeature: function hasFeature(feature) {
/* Returns a Promise which resolves with a map indicating
* whether a given feature is supported.
*
* Parameters:
* (String) feature - The feature that might be supported.
*/
var entity = this;
return new Promise(function (resolve, reject) {
function fulfillPromise() {
var model = entity.features.findWhere({
'var': feature
});
if (model) {
resolve({
'supported': true,
'feature': model
});
} else {
resolve({
'supported': false,
'feature': null
});
}
}
entity.waitUntilFeaturesDiscovered.then(fulfillPromise).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
});
},
onFeatureAdded: function onFeatureAdded(feature) {
feature.entity = this;
_converse.emit('serviceDiscovered', feature);
},
fetchFeatures: function fetchFeatures() {
var _this = this;
if (this.features.browserStorage.records.length === 0) {
this.queryInfo();
} else {
this.features.fetch({
add: true,
success: function success() {
_this.waitUntilFeaturesDiscovered.resolve();
_this.trigger('featuresDiscovered');
}
});
this.identities.fetch({
add: true
});
}
},
queryInfo: function queryInfo() {
_converse.connection.disco.info(this.get('jid'), null, this.onInfo.bind(this));
},
queryForItems: function queryForItems() {
if (_.isEmpty(this.identities.where({
'category': 'server'
}))) {
// Don't fetch features and items if this is not a
// server or a conference component.
return;
}
_converse.connection.disco.items(this.get('jid'), null, onDiscoItems);
},
onInfo: function onInfo(stanza) {
var _this2 = this;
_.forEach(stanza.querySelectorAll('identity'), function (identity) {
_this2.identities.create({
'category': identity.getAttribute('category'),
'type': identity.getAttribute('type'),
'name': identity.getAttribute('name')
});
});
if (stanza.querySelector('feature[var="' + Strophe.NS.DISCO_ITEMS + '"]')) {
this.queryForItems();
}
_.forEach(stanza.querySelectorAll('feature'), function (feature) {
_this2.features.create({
'var': feature.getAttribute('var'),
'from': stanza.getAttribute('from')
});
});
this.waitUntilFeaturesDiscovered.resolve();
this.trigger('featuresDiscovered');
}
});
_converse.DiscoEntities = Backbone.Collection.extend({
model: _converse.DiscoEntity,
initialize: function initialize() {
this.browserStorage = new Backbone.BrowserStorage[_converse.storage](b64_sha1("converse.disco-entities-".concat(_converse.bare_jid)));
this.fetchEntities().then(_.partial(_converse.emit, 'discoInitialized'), _.partial(_converse.emit, 'discoInitialized')).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
},
fetchEntities: function fetchEntities() {
var _this3 = this;
return new Promise(function (resolve, reject) {
_this3.fetch({
add: true,
success: function (collection) {
if (collection.length === 0 || !collection.get(_converse.domain)) {
this.create({
'jid': _converse.domain
});
}
resolve();
}.bind(_this3),
error: function error() {
reject(new Error("Could not fetch disco entities"));
}
});
});
}
});
function addClientFeatures() {
/* The strophe.disco.js plugin keeps a list of features which
* it will advertise to any #info queries made to it.
*
* See: http://xmpp.org/extensions/xep-0030.html#info
*/
// See http://xmpp.org/registrar/disco-categories.html
_converse.connection.disco.addIdentity('client', 'web', 'Converse.js');
_converse.connection.disco.addFeature(Strophe.NS.BOSH);
_converse.connection.disco.addFeature(Strophe.NS.CHATSTATES);
_converse.connection.disco.addFeature(Strophe.NS.DISCO_INFO);
_converse.connection.disco.addFeature(Strophe.NS.ROSTERX); // Limited support
if (_converse.message_carbons) {
_converse.connection.disco.addFeature(Strophe.NS.CARBONS);
}
_converse.emit('addClientFeatures');
return this;
}
function initializeDisco() {
addClientFeatures();
_converse.disco_entities = new _converse.DiscoEntities();
}
_converse.api.listen.on('reconnected', initializeDisco);
_converse.api.listen.on('connected', initializeDisco);
_converse.api.listen.on('beforeTearDown', function () {
if (_converse.disco_entities) {
_converse.disco_entities.each(function (entity) {
entity.features.reset();
entity.features.browserStorage._clear();
});
_converse.disco_entities.reset();
_converse.disco_entities.browserStorage._clear();
}
});
/* We extend the default converse.js API to add methods specific to service discovery */
_.extend(_converse.api, {
'disco': {
'entities': {
'get': function get(entity_jid) {
var create = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
var entity = _converse.disco_entities.get(entity_jid);
if (entity || !create) {
return entity;
}
return _converse.disco_entities.create({
'jid': entity_jid
});
}
},
'supports': function supports(feature, entity_jid) {
/* Returns a Promise which resolves with a map indicating
* whether a given feature is supported.
*
* Parameters:
* (String) feature - The feature that might be
* supported. In the XML stanza, this is the `var`
* attribute of the `` element. For
* example: 'http://jabber.org/protocol/muc'
* (String) entity_jid - The JID of the entity which might support the feature.
*/
return _converse.api.waitUntil('discoInitialized').then(function () {
var entity = _converse.api.disco.entities.get(entity_jid, true);
return entity.hasFeature(feature);
}).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
},
'getIdentity': function getIdentity(category, type, entity_jid) {
/* Returns a Promise which resolves with a map indicating
* whether an identity with a given type is provided by
* the entity.
*
* Parameters:
* (String) category - The identity category.
* In the XML stanza, this is the `category`
* attribute of the `` element.
* For example: 'pubsub'
* (String) type - The identity type.
* In the XML stanza, this is the `type`
* attribute of the `` element.
* For example: 'pep'
*/
return _converse.api.waitUntil('discoInitialized').then(function () {
var entity = _converse.api.disco.entities.get(entity_jid, true);
return entity.getIdentity(category, type);
}).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
}
}
});
}
});
});
//# sourceMappingURL=converse-disco.js.map;
/*!
* Backbone.OrderedListView
*
* Copyright (c) 2017, JC Brand
* Licensed under the Mozilla Public License (MPL)
*/
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
define('backbone.orderedlistview',["underscore", "backbone", "backbone.overview"], factory);
} else {
// RequireJS isn't being used.
// Assume underscore and backbone are loaded in