Commit 9817aede authored by JC Brand's avatar JC Brand

No need to set templates on the _converse object.

If it's needed in another plugin, it can simply be `require`'d.
parent 054cba65
......@@ -70,7 +70,7 @@
if (_converse.allow_bookmarks) {
var div = document.createElement('div');
div.innerHTML = html;
var bookmark_button = _converse.templates.chatroom_bookmark_toggle(
var bookmark_button = tpl_chatroom_bookmark_toggle(
_.assignIn(
this.model.toJSON(),
{
......@@ -132,7 +132,7 @@
// Remove any existing forms
$body.find('form.chatroom-form').remove();
$body.append(
_converse.templates.chatroom_bookmark_form({
tpl_chatroom_bookmark_form({
heading: __('Bookmark this room'),
label_name: __('The name for this bookmark:'),
label_autojoin: __('Would you like this room to be automatically joined upon startup?'),
......@@ -189,12 +189,6 @@
__ = _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
// ====================================
// Refer to docs/source/configuration.rst for explanations of these
......@@ -378,7 +372,7 @@
},
render: function () {
this.$el.html(_converse.templates.bookmarks_list({
this.$el.html(tpl_bookmarks_list({
'toggle_state': this.list_model.get('toggle-state'),
'desc_bookmarks': __('Click to toggle the bookmarks list'),
'label_bookmarks': __('Bookmarked Rooms')
......@@ -404,7 +398,7 @@
},
renderBookmarkListElement: function (item) {
var $bookmark = $(_converse.templates.bookmark({
var $bookmark = $(tpl_bookmark({
'name': item.get('name'),
'jid': item.get('jid'),
'open_title': __('Click to open this room'),
......
......@@ -71,14 +71,6 @@
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({
show_toolbar: true,
chatview_avatar_width: 32,
......@@ -129,7 +121,7 @@
render: function () {
this.$el.attr('id', this.model.get('box_id'))
.html(_converse.templates.chatbox(
.html(tpl_chatbox(
_.extend(this.model.toJSON(), {
show_toolbar: _converse.show_toolbar,
show_textarea: true,
......@@ -207,7 +199,7 @@
*/
var day_date = moment(date).startOf('day');
var insert = prepend ? this.$content.prepend: this.$content.append;
insert.call(this.$content, _converse.templates.new_day({
insert.call(this.$content, tpl_new_day({
isodate: day_date.format(),
datestring: day_date.format("dddd MMM Do YYYY")
}));
......@@ -324,7 +316,7 @@
if ((match) && (match[1] === 'me')) {
text = text.replace(/^\/me/, '');
template = _converse.templates.action;
template = tpl_action;
if (attrs.sender === 'me') {
fullname = _converse.xmppstatus.get('fullname');
username = _.isNil(fullname)? _converse.bare_jid: fullname;
......@@ -332,7 +324,7 @@
username = attrs.fullname;
}
} else {
template = _converse.templates.message;
template = tpl_message;
username = attrs.sender === 'me' && __('me') || fullname;
}
this.$content.find('div.chat-event').remove();
......@@ -691,7 +683,7 @@
renderToolbar: function (toolbar, options) {
if (!_converse.show_toolbar) { return; }
toolbar = toolbar || _converse.templates.toolbar;
toolbar = toolbar || tpl_toolbar;
options = _.extend(
this.model.toJSON(),
this.getToolbarOptions(options || {})
......@@ -707,7 +699,7 @@
var width = _converse.chatview_avatar_width;
var height = _converse.chatview_avatar_height;
var img_src = 'data:'+this.model.get('image_type')+';base64,'+this.model.get('image'),
canvas = $(_converse.templates.avatar({
canvas = $(tpl_avatar({
'width': width,
'height': height
})).get(0);
......
......@@ -7,8 +7,7 @@
/*global define, Backbone */
(function (root, factory) {
define([
"converse-core",
define(["converse-core",
"tpl!add_contact_dropdown",
"tpl!add_contact_form",
"tpl!change_status_message",
......@@ -192,21 +191,6 @@
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({
allow_logout: true,
default_domain: undefined,
......@@ -259,7 +243,7 @@
} else {
this.hide();
}
this.$el.html(_converse.templates.controlbox(
this.$el.html(tpl_controlbox(
_.extend(this.model.toJSON(), {
sticky_controlbox: _converse.sticky_controlbox
}))
......@@ -392,7 +376,7 @@
initialize: function (cfg) {
cfg.$parent.html(this.$el.html(
_converse.templates.login_panel({
tpl_login_panel({
'ANONYMOUS': _converse.ANONYMOUS,
'EXTERNAL': _converse.EXTERNAL,
'LOGIN': _converse.LOGIN,
......@@ -411,7 +395,7 @@
},
render: function () {
this.$tabs.append(_converse.templates.login_tab({label_sign_in: __('Sign in')}));
this.$tabs.append(tpl_login_tab({label_sign_in: __('Sign in')}));
this.$el.find('input#jid').focus();
if (!this.$el.is(':visible')) {
this.$el.show();
......@@ -496,9 +480,9 @@
options = $('option', $select),
$options_target,
options_list = [];
this.$el.html(_converse.templates.choose_status());
this.$el.html(tpl_choose_status());
this.$el.find('#fancy-xmpp-status-select')
.html(_converse.templates.chat_status({
.html(tpl_chat_status({
'status_message': this.model.get('status_message') || __("I am %1$s", this.getPrettyStatus(chat_status)),
'chat_status': chat_status,
'desc_custom_status': __('Click here to write a custom status message'),
......@@ -506,7 +490,7 @@
}));
// iterate through all the <option> elements and add option values
options.each(function () {
options_list.push(_converse.templates.status_option({
options_list.push(tpl_status_option({
'value': $(this).val(),
'text': this.text
}));
......@@ -525,7 +509,7 @@
renderStatusChangeForm: function (ev) {
ev.preventDefault();
var status_message = _converse.xmppstatus.get('status_message') || '';
var input = _converse.templates.change_status_message({
var input = tpl_change_status_message({
'status_message': status_message,
'label_custom_status': __('Custom status'),
'label_save': __('Save')
......@@ -576,7 +560,7 @@
// Example, I am online
var status_message = model.get('status_message') || __("I am %1$s", this.getPrettyStatus(stat));
this.$el.find('#fancy-xmpp-status-select').removeClass('no-border').html(
_converse.templates.chat_status({
tpl_chat_status({
'chat_status': stat,
'status_message': status_message,
'desc_custom_status': __('Click here to write a custom status message'),
......@@ -604,7 +588,7 @@
render: function () {
var markup;
var widgets = _converse.templates.contacts_panel({
var widgets = tpl_contacts_panel({
label_online: __('Online'),
label_busy: __('Busy'),
label_away: __('Away'),
......@@ -614,23 +598,23 @@
allow_logout: _converse.allow_logout
});
var controlbox = _converse.chatboxes.get('controlbox');
this.$tabs.append(_converse.templates.contacts_tab({
this.$tabs.append(tpl_contacts_tab({
'label_contacts': LABEL_CONTACTS,
'is_current': controlbox.get('active-panel') === USERS_PANEL_ID
}));
if (_converse.xhr_user_search) {
markup = _converse.templates.search_contact({
markup = tpl_search_contact({
label_contact_name: __('Contact name'),
label_search: __('Search')
});
} else {
markup = _converse.templates.add_contact_form({
markup = tpl_add_contact_form({
label_contact_username: __('e.g. user@example.org'),
label_add: __('Add')
});
}
if (_converse.allow_contact_requests) {
widgets += _converse.templates.add_contact_dropdown({
widgets += tpl_add_contact_dropdown({
label_click_to_chat: __('Click to add new chat contacts'),
label_add_contact: __('Add a contact')
});
......@@ -728,7 +712,7 @@
// artifacts (i.e. on page load the toggle is shown only to then
// seconds later be hidden in favor of the control box).
return this.$el.html(
_converse.templates.controlbox_toggle({
tpl_controlbox_toggle({
'label_toggle': __('Toggle chat')
})
);
......
......@@ -297,7 +297,7 @@
var _converse = this.__super__._converse;
var flyout = this.el.querySelector('.box-flyout');
var div = document.createElement('div');
div.innerHTML = _converse.templates.dragresize();
div.innerHTML = tpl_dragresize();
flyout.insertBefore(
div,
flyout.firstChild
......@@ -311,8 +311,6 @@
* loaded by converse.js's plugin machinery.
*/
var _converse = this._converse;
// Add new HTML template
_converse.templates.dragresize = tpl_dragresize;
this.updateSettings({
allow_dragresize: true,
......
......@@ -9,9 +9,10 @@
(function (root, factory) {
define([
"converse-core",
"converse-chatview"
"tpl!chatbox",
"converse-chatview",
], factory);
}(this, function (converse) {
}(this, function (converse, tpl_chatbox) {
"use strict";
var _ = converse.env._,
utils = converse.env.utils;
......@@ -86,7 +87,7 @@
render: function () {
this.$el.attr('id', this.model.get('box_id'))
.html(_converse.templates.chatbox(
.html(tpl_chatbox(
_.extend(this.model.toJSON(), {
show_toolbar: _converse.show_toolbar,
show_textarea: false,
......
......@@ -7,8 +7,7 @@
/*global Backbone, define, window */
(function (root, factory) {
define([
"converse-core",
define(["converse-core",
"tpl!chatbox_minimize",
"tpl!toggle_chats",
"tpl!trimmed_chat",
......@@ -173,7 +172,7 @@
var html = this.__super__.generateHeadingHTML.apply(this, arguments);
var div = document.createElement('div');
div.innerHTML = html;
var el = _converse.templates.chatbox_minimize(
var el = tpl_chatbox_minimize(
{info_minimize: __('Minimize this chat box')}
);
var button = div.querySelector('.close-chatbox-button');
......@@ -333,7 +332,7 @@
data.title = this.model.get('fullname');
this.$el.addClass('chat-head-chatbox');
}
return this.$el.html(_converse.templates.trimmed_chat(data));
return this.$el.html(tpl_trimmed_chat(data));
},
clearUnreadMessagesCounter: function () {
......@@ -407,7 +406,7 @@
render: function () {
if (!this.el.parentElement) {
this.el.innerHTML = _converse.templates.chats_panel();
this.el.innerHTML = tpl_chats_panel();
_converse.chatboxviews.el.appendChild(this.el);
}
if (this.keys().length === 0) {
......@@ -487,7 +486,7 @@
},
render: function () {
this.$el.html(_converse.templates.toggle_chats(
this.$el.html(tpl_toggle_chats(
_.extend(this.model.toJSON(), {
'Minimized': __('Minimized')
})
......@@ -504,7 +503,7 @@
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(
var $new_el = tpl_chatbox_minimize(
{info_minimize: __('Minimize this chat box')}
);
if ($el.length) {
......
......@@ -182,25 +182,10 @@
var _converse = this._converse,
__ = _converse.__,
___ = _converse.___;
_converse.templates.chatarea = tpl_chatarea;
_converse.templates.chatroom = tpl_chatroom;
_converse.templates.chatroom_form = tpl_chatroom_form;
_converse.templates.chatroom_nickname_form = tpl_chatroom_nickname_form;
_converse.templates.chatroom_password_form = tpl_chatroom_password_form;
_converse.templates.chatroom_sidebar = tpl_chatroom_sidebar;
_converse.templates.chatroom_head = tpl_chatroom_head;
_converse.templates.chatrooms_tab = tpl_chatrooms_tab;
_converse.templates.info = tpl_info;
_converse.templates.occupant = tpl_occupant;
_converse.templates.room_description = tpl_room_description;
_converse.templates.room_item = tpl_room_item;
_converse.templates.room_panel = tpl_room_panel;
// XXX: Inside plugins, all calls to the translation machinery
// (e.g. utils.__) should only be done in the initialize function.
// If called before, we won't know what language the user wants,
// and it'll fallback to English.
// and it'll fall back to English.
/* http://xmpp.org/extensions/xep-0045.html
* ----------------------------------------
......@@ -377,7 +362,7 @@
render: function () {
this.$el.attr('id', this.model.get('box_id'))
.html(_converse.templates.chatroom());
.html(tpl_chatroom());
this.renderHeading();
this.renderChatArea();
utils.refreshWebkit();
......@@ -395,8 +380,7 @@
*/
if (!this.$('.chat-area').length) {
this.$('.chatroom-body').empty()
.append(
_converse.templates.chatarea({
.append(tpl_chatarea({
'unread_msgs': __('You have unread messages'),
'show_toolbar': _converse.show_toolbar,
'label_message': __('Message')
......@@ -437,7 +421,7 @@
generateHeadingHTML: function () {
/* Returns the heading HTML to be rendered.
*/
return _converse.templates.chatroom_head(
return tpl_chatroom_head(
_.extend(this.model.toJSON(), {
info_close: __('Close and leave this room'),
info_configure: __('Configure this room'),
......@@ -1189,7 +1173,7 @@
$body.children().addClass('hidden');
// Remove any existing forms
$body.find('form.chatroom-form').remove();
$body.append(_converse.templates.chatroom_form());
$body.append(tpl_chatroom_form());
var $form = $body.find('form.chatroom-form'),
$fieldset = $form.children('fieldset:first'),
......@@ -1542,7 +1526,7 @@
message = '';
}
this.$('.chatroom-body').append(
_converse.templates.chatroom_nickname_form({
tpl_chatroom_nickname_form({
heading: __('Please choose your nickname'),
label_nickname: __('Nickname'),
label_join: __('Enter room'),
......@@ -1562,7 +1546,7 @@
this.$('.chatroom-body').children().addClass('hidden');
this.$('span.centered.spinner').remove();
this.$('.chatroom-body').append(
_converse.templates.chatroom_password_form({
tpl_chatroom_password_form({
heading: __('This chatroom requires a password'),
label_password: __('Password: '),
label_submit: __('Submit')
......@@ -1693,7 +1677,7 @@
return;
}
_.each(notification.messages, function (message) {
that.$content.append(_converse.templates.info({'message': message}));
that.$content.append(tpl_info({'message': message}));
});
if (notification.reason) {
this.showStatusNotification(__('The reason given is: "'+notification.reason+'"'), true);
......@@ -1829,8 +1813,8 @@
// The features for this room weren't fetched yet, perhaps
// because it's a new room without locking (in which
// case Prosody doesn't send a 201 status).
// This is the first presence received for the room, so
// a good time to fetch the features.
// This is the first presence received for the room,
// so a good time to fetch the features.
this.getRoomFeatures();
}
if (show_status_messages) {
......@@ -1844,12 +1828,11 @@
},
setChatRoomSubject: function (sender, subject) {
// For translators: the %1$s and %2$s parts will get replaced by the user and topic text respectively
// For translators: the %1$s and %2$s parts will get
// replaced by the user and topic text respectively
// Example: Topic set by JC Brand to: Hello World!
this.$content.append(
_converse.templates.info({
'message': __('Topic set by %1$s to: %2$s', sender, subject)
}));
tpl_info({'message': __('Topic set by %1$s to: %2$s', sender, subject)}));
this.scrollDown();
},
......@@ -1939,7 +1922,7 @@
},
render: function () {
var new_el = _converse.templates.occupant(
var new_el = tpl_occupant(
_.extend(
{ 'jid': '',
'hint_occupant': __('Click to mention this user in your message.'),
......@@ -1995,7 +1978,7 @@
render: function () {
this.$el.html(
_converse.templates.chatroom_sidebar(
tpl_chatroom_sidebar(
_.extend(this.chatroomview.model.toJSON(), {
'allow_muc_invitations': _converse.allow_muc_invitations,
'label_features': __('Features'),
......@@ -2197,7 +2180,7 @@
render: function () {
this.$parent.append(
this.$el.html(
_converse.templates.room_panel({
tpl_room_panel({
'server_input_type': _converse.hide_muc_server && 'hidden' || 'text',
'server_label_global_attr': _converse.hide_muc_server && ' hidden' || '',
'label_room_name': __('Room name'),
......@@ -2210,7 +2193,7 @@
this.$tabs = this.$parent.parent().find('#controlbox-tabs');
var controlbox = _converse.chatboxes.get('controlbox');
this.$tabs.append(_converse.templates.chatrooms_tab({
this.$tabs.append(tpl_chatrooms_tab({
'label_rooms': __('Rooms'),
'is_current': controlbox.get('active-panel') === ROOMS_PANEL_ID
}));
......@@ -2256,7 +2239,7 @@
name = Strophe.unescapeNode($(this.rooms[i]).attr('name')||$(this.rooms[i]).attr('jid'));
jid = $(this.rooms[i]).attr('jid');
fragment.appendChild($(
_converse.templates.room_item({
tpl_room_item({
'name':name,
'jid':jid,
'open_title': __('Click to open this room'),
......@@ -2314,7 +2297,7 @@
var $stanza = $(stanza);
// All MUC features found here: http://xmpp.org/registrar/disco-features.html
$(el).find('span.spinner').replaceWith(
_converse.templates.room_description({
tpl_room_description({
'desc': $stanza.find('field[var="muc#roominfo_description"] value').text(),
'occ': $stanza.find('field[var="muc#roominfo_occupants"] value').text(),
'hidden': $stanza.find('feature[var="muc_hidden"]').length,
......
......@@ -444,7 +444,7 @@
});
this.__super__.renderToolbar.apply(this, arguments);
this.$el.find('.chat-toolbar').append(
_converse.templates.toolbar_otr(
tpl_toolbar_otr(
_.extend(this.model.toJSON(), options || {})
));
return this;
......@@ -465,9 +465,6 @@
use_otr_by_default: false
});
// Add new HTML template
_converse.templates.toolbar_otr = tpl_toolbar_otr;
// Translation aware constants
// ---------------------------
// We can only call the __ translation method *after* converse.js
......
......@@ -115,7 +115,7 @@
render: function () {
this.$parent.append(this.$el.html(
_converse.templates.register_panel({
tpl_register_panel({
'label_domain': __("Your XMPP provider's domain name:"),
'label_register': __('Fetch registration form'),
'help_providers': __('Tip: A list of public XMPP providers is available'),
......@@ -124,7 +124,7 @@
'domain_placeholder': _converse.domain_placeholder
})
));
this.$tabs.append(_converse.templates.register_tab({label_register: __('Register')}));
this.$tabs.append(tpl_register_tab({label_register: __('Register')}));
return this;
},
......@@ -228,7 +228,7 @@
return;
}
$form.find('input[type=submit]').hide()
.after(_converse.templates.registration_request({
.after(tpl_registration_request({
cancel: __('Cancel'),
info_message: __('Requesting a registration form from the XMPP server')
}));
......@@ -304,7 +304,7 @@
var $form= this.$('form'),
$stanza = $(stanza),
$fields, $input;
$form.empty().append(_converse.templates.registration_form({
$form.empty().append(tpl_registration_form({
'domain': this.domain,
'title': this.title,
'instructions': this.instructions
......@@ -318,7 +318,7 @@
// Show fields
_.each(_.keys(this.fields), function (key) {
if (key === "username") {
$input = _converse.templates.form_username({
$input = tpl_form_username({
domain: ' @'+this.domain,
name: key,
type: "text",
......
......@@ -70,13 +70,6 @@
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({
allow_chat_pending_contacts: true,
allow_contact_removal: true,
......@@ -152,7 +145,7 @@
},
render: function () {
this.$el.html(_converse.templates.roster(
this.$el.html(tpl_roster(
_.extend(this.model.toJSON(), {
placeholder: __('Filter'),
label_contacts: LABEL_CONTACTS,
......@@ -601,7 +594,7 @@
* So in both cases the user is a "pending" contact.
*/
this.$el.addClass('pending-xmpp-contact');
this.$el.html(_converse.templates.pending_contact(
this.$el.html(tpl_pending_contact(
_.extend(item.toJSON(), {
'desc_remove': __('Click to remove this contact'),
'allow_chat_pending_contacts': _converse.allow_chat_pending_contacts
......@@ -609,7 +602,7 @@
));
} else if (requesting === true) {
this.$el.addClass('requesting-xmpp-contact');
this.$el.html(_converse.templates.requesting_contact(
this.$el.html(tpl_requesting_contact(
_.extend(item.toJSON(), {
'desc_accept': __("Click to accept this contact request"),
'desc_decline': __("Click to decline this contact request"),
......@@ -619,7 +612,7 @@
} else if (subscription === 'both' || subscription === 'to') {
this.$el.addClass('current-xmpp-contact');
this.$el.removeClass(_.without(['both', 'to'], subscription)[0]).addClass(subscription);
this.$el.html(_converse.templates.roster_item(
this.$el.html(tpl_roster_item(
_.extend(item.toJSON(), {
'desc_status': STATUSES[chat_status||'offline'],
'desc_chat': __('Click to chat with this contact'),
......@@ -743,7 +736,7 @@
render: function () {
this.$el.attr('data-group', this.model.get('name'));
this.$el.html(
$(_converse.templates.group_header({
$(tpl_group_header({
label_group: this.model.get('name'),
desc_group_toggle: this.model.get('description'),
toggle_state: this.model.get('state')
......
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