|
@@ -668,14 +668,16 @@
|
|
*/
|
|
*/
|
|
var attrs;
|
|
var attrs;
|
|
// Handle both `"key", value` and `{key: value}` -style arguments.
|
|
// Handle both `"key", value` and `{key: value}` -style arguments.
|
|
- if (key == null || typeof key === 'object') {
|
|
|
|
|
|
+ if (key === null || typeof key === 'object') {
|
|
attrs = key;
|
|
attrs = key;
|
|
options = val;
|
|
options = val;
|
|
} else {
|
|
} else {
|
|
(attrs = {})[key] = val;
|
|
(attrs = {})[key] = val;
|
|
}
|
|
}
|
|
- if (typeof attrs === 'object' && attrs.trimmed) {
|
|
|
|
- delete attrs.trimmed;
|
|
|
|
|
|
+ if (typeof attrs === 'object' && attrs !== null) {
|
|
|
|
+ if (attrs.trimmed) {
|
|
|
|
+ delete attrs.trimmed;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
Backbone.Model.prototype.save.call(this, attrs, options);
|
|
Backbone.Model.prototype.save.call(this, attrs, options);
|
|
},
|
|
},
|
|
@@ -881,7 +883,7 @@
|
|
is_chatroom: false, // This is not a multi-user chatroom
|
|
is_chatroom: false, // This is not a multi-user chatroom
|
|
|
|
|
|
events: {
|
|
events: {
|
|
- 'click .close-chatbox-button': 'closeChat',
|
|
|
|
|
|
+ 'click .close-chatbox-button': 'close',
|
|
'click .toggle-chatbox-button': 'toggleChatBox',
|
|
'click .toggle-chatbox-button': 'toggleChatBox',
|
|
'keypress textarea.chat-textarea': 'keyPressed',
|
|
'keypress textarea.chat-textarea': 'keyPressed',
|
|
'click .toggle-smiley': 'toggleEmoticonMenu',
|
|
'click .toggle-smiley': 'toggleEmoticonMenu',
|
|
@@ -1303,6 +1305,9 @@
|
|
if (_.has(item.changed, 'otr_status')) {
|
|
if (_.has(item.changed, 'otr_status')) {
|
|
this.renderToolbar().informOTRChange();
|
|
this.renderToolbar().informOTRChange();
|
|
}
|
|
}
|
|
|
|
+ if (_.has(item.changed, 'trimmed')) {
|
|
|
|
+ this.trim();
|
|
|
|
+ }
|
|
// TODO check for changed fullname as well
|
|
// TODO check for changed fullname as well
|
|
},
|
|
},
|
|
|
|
|
|
@@ -1310,7 +1315,7 @@
|
|
this.$el.find('p.user-custom-message').text(msg).attr('title', msg);
|
|
this.$el.find('p.user-custom-message').text(msg).attr('title', msg);
|
|
},
|
|
},
|
|
|
|
|
|
- closeChat: function () {
|
|
|
|
|
|
+ close: function () {
|
|
if (converse.connection) {
|
|
if (converse.connection) {
|
|
this.model.destroy();
|
|
this.model.destroy();
|
|
} else {
|
|
} else {
|
|
@@ -1319,12 +1324,8 @@
|
|
return this;
|
|
return this;
|
|
},
|
|
},
|
|
|
|
|
|
- trimChat: function () {
|
|
|
|
- // TODO: Instead of closing the chat, we should add it to
|
|
|
|
- // div#offscreen-chatboxes
|
|
|
|
- this.model.set('trimmed', true);
|
|
|
|
- this.$el.hide(); // Hide it immediately to avoid flashes on the screen
|
|
|
|
- this.closeChat();
|
|
|
|
|
|
+ trim: function () {
|
|
|
|
+ this.$el.hide();
|
|
},
|
|
},
|
|
|
|
|
|
saveToggleState: function () {
|
|
saveToggleState: function () {
|
|
@@ -1786,7 +1787,7 @@
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (!nick) { return; }
|
|
if (!nick) { return; }
|
|
- chatroom = converse.chatboxviews.showChatBox({
|
|
|
|
|
|
+ chatroom = converse.chatboxviews.showChat({
|
|
'id': jid,
|
|
'id': jid,
|
|
'jid': jid,
|
|
'jid': jid,
|
|
'name': Strophe.unescapeNode(Strophe.getNodeFromJid(jid)),
|
|
'name': Strophe.unescapeNode(Strophe.getNodeFromJid(jid)),
|
|
@@ -1805,7 +1806,7 @@
|
|
className: 'chatbox',
|
|
className: 'chatbox',
|
|
id: 'controlbox',
|
|
id: 'controlbox',
|
|
events: {
|
|
events: {
|
|
- 'click a.close-chatbox-button': 'closeChat',
|
|
|
|
|
|
+ 'click a.close-chatbox-button': 'close',
|
|
'click ul#controlbox-tabs li a': 'switchTab',
|
|
'click ul#controlbox-tabs li a': 'switchTab',
|
|
'mousedown .dragresize-tm': 'onDragResizeStart'
|
|
'mousedown .dragresize-tm': 'onDragResizeStart'
|
|
},
|
|
},
|
|
@@ -1909,7 +1910,7 @@
|
|
tagName: 'div',
|
|
tagName: 'div',
|
|
className: 'chatroom',
|
|
className: 'chatroom',
|
|
events: {
|
|
events: {
|
|
- 'click .close-chatbox-button': 'closeChat',
|
|
|
|
|
|
+ 'click .close-chatbox-button': 'close',
|
|
'click .toggle-chatbox-button': 'toggleChatBox',
|
|
'click .toggle-chatbox-button': 'toggleChatBox',
|
|
'click .configure-chatroom-button': 'configureChatRoom',
|
|
'click .configure-chatroom-button': 'configureChatRoom',
|
|
'click .toggle-smiley': 'toggleEmoticonMenu',
|
|
'click .toggle-smiley': 'toggleEmoticonMenu',
|
|
@@ -2406,7 +2407,7 @@
|
|
|
|
|
|
this.ChatBoxes = Backbone.Collection.extend({
|
|
this.ChatBoxes = Backbone.Collection.extend({
|
|
model: converse.ChatBox,
|
|
model: converse.ChatBox,
|
|
- comparator : 'time_opened',
|
|
|
|
|
|
+ comparator: 'time_opened',
|
|
|
|
|
|
registerMessageHandler: function () {
|
|
registerMessageHandler: function () {
|
|
converse.connection.addHandler(
|
|
converse.connection.addHandler(
|
|
@@ -2525,7 +2526,7 @@
|
|
view.model = item;
|
|
view.model = item;
|
|
view.initialize();
|
|
view.initialize();
|
|
}
|
|
}
|
|
- this.trimOpenChats(view);
|
|
|
|
|
|
+ this.trimChats(view);
|
|
}, this);
|
|
}, this);
|
|
},
|
|
},
|
|
|
|
|
|
@@ -2549,13 +2550,14 @@
|
|
}
|
|
}
|
|
},
|
|
},
|
|
|
|
|
|
- trimOpenChats: function (view) {
|
|
|
|
|
|
+ trimChats: function (view) {
|
|
/* This method is called before a new chat box will be opened.
|
|
/* This method is called before a new chat box will be opened.
|
|
*
|
|
*
|
|
* Check whether there is enough space in the page to show
|
|
* Check whether there is enough space in the page to show
|
|
* another chat box. Otherwise, close the oldest chat box.
|
|
* another chat box. Otherwise, close the oldest chat box.
|
|
*/
|
|
*/
|
|
var toggle_width = 0,
|
|
var toggle_width = 0,
|
|
|
|
+ trimmed_chats_width,
|
|
boxes_width = view.$el.outerWidth(true),
|
|
boxes_width = view.$el.outerWidth(true),
|
|
controlbox = this.get('controlbox');
|
|
controlbox = this.get('controlbox');
|
|
if (!controlbox || !controlbox.$el.is(':visible')) {
|
|
if (!controlbox || !controlbox.$el.is(':visible')) {
|
|
@@ -2570,13 +2572,24 @@
|
|
if (this.model.length <= 1) {
|
|
if (this.model.length <= 1) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
- if ((boxes_width + toggle_width) > this.$el.width()) {
|
|
|
|
- // trim oldest view (which is not controlbox)
|
|
|
|
- this.get(this.model.at(1).get('id')).trimChat();
|
|
|
|
|
|
+ trimmed_chats_width = this.trimmed_chatboxes_view.$('.box-flyout').outerWidth(true) || 0;
|
|
|
|
+ if ((trimmed_chats_width + boxes_width + toggle_width) > this.$el.width()) {
|
|
|
|
+ this.getOldestNonTrimmedChat().set('trimmed', true);
|
|
}
|
|
}
|
|
},
|
|
},
|
|
|
|
|
|
- showChatBox: function (attrs) {
|
|
|
|
|
|
+ getOldestNonTrimmedChat: function () {
|
|
|
|
+ // Get oldest view (which is not controlbox)
|
|
|
|
+ var i = 0;
|
|
|
|
+ var model = this.model.at(i);
|
|
|
|
+ while (model.get('id') === 'controlbox' || model.get('trimmed') === true) {
|
|
|
|
+ i++;
|
|
|
|
+ model = this.model.at(i);
|
|
|
|
+ }
|
|
|
|
+ return model;
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ showChat: function (attrs) {
|
|
var chatbox = this.model.get(attrs.jid);
|
|
var chatbox = this.model.get(attrs.jid);
|
|
if (chatbox) {
|
|
if (chatbox) {
|
|
chatbox.trigger('show');
|
|
chatbox.trigger('show');
|
|
@@ -2592,22 +2605,32 @@
|
|
});
|
|
});
|
|
|
|
|
|
this.TrimmedChatBoxView = Backbone.View.extend({
|
|
this.TrimmedChatBoxView = Backbone.View.extend({
|
|
|
|
+ tagName: 'div',
|
|
|
|
+ className: 'chat-head',
|
|
|
|
+
|
|
|
|
+ events: {
|
|
|
|
+ 'click .close-chatbox-button': 'close',
|
|
|
|
+ 'click .restore-chat': 'restore'
|
|
|
|
+ },
|
|
|
|
+
|
|
render: function () {
|
|
render: function () {
|
|
- return this.$el;
|
|
|
|
|
|
+ return this.$el.addClass('chat-head-chatbox').html(
|
|
|
|
+ converse.templates.trimmed_chat(this.model.toJSON()));
|
|
},
|
|
},
|
|
|
|
|
|
- _ensureElement: function() {
|
|
|
|
- /* Override method from backbone.js
|
|
|
|
- * Make sure that the el and $el attributes point to a DOM snippet
|
|
|
|
- * from src/templates/trimmed_chat.html
|
|
|
|
- */
|
|
|
|
- if (!this.el) {
|
|
|
|
- var $el = $(converse.templates.trimmed_chat());
|
|
|
|
- this.setElement($el, false);
|
|
|
|
- } else {
|
|
|
|
- this.setElement(_.result(this, 'el'), false);
|
|
|
|
- }
|
|
|
|
|
|
+ close: function (ev) {
|
|
|
|
+ ev.preventDefault();
|
|
|
|
+ this.$el.remove();
|
|
|
|
+ this.model.destroy();
|
|
|
|
+ return this;
|
|
},
|
|
},
|
|
|
|
+
|
|
|
|
+ restore: function (ev) {
|
|
|
|
+ ev.preventDefault();
|
|
|
|
+ this.model.set('trimmed', false);
|
|
|
|
+ this.$el.remove();
|
|
|
|
+ return this;
|
|
|
|
+ }
|
|
});
|
|
});
|
|
|
|
|
|
this.TrimmedChatBoxesView = Backbone.View.extend({
|
|
this.TrimmedChatBoxesView = Backbone.View.extend({
|
|
@@ -2628,7 +2651,7 @@
|
|
var view;
|
|
var view;
|
|
if (item.get('trimmed')) {
|
|
if (item.get('trimmed')) {
|
|
view = new converse.TrimmedChatBoxView({model: item});
|
|
view = new converse.TrimmedChatBoxView({model: item});
|
|
- this.$el.append(view.render());
|
|
|
|
|
|
+ this.$('.box-flyout').append(view.render());
|
|
views[item.get('id')] = view;
|
|
views[item.get('id')] = view;
|
|
} else {
|
|
} else {
|
|
this.remove(item.get('id'));
|
|
this.remove(item.get('id'));
|
|
@@ -2684,7 +2707,7 @@
|
|
|
|
|
|
openChat: function (ev) {
|
|
openChat: function (ev) {
|
|
ev.preventDefault();
|
|
ev.preventDefault();
|
|
- return converse.chatboxviews.showChatBox({
|
|
|
|
|
|
+ return converse.chatboxviews.showChat({
|
|
'id': this.model.get('jid'),
|
|
'id': this.model.get('jid'),
|
|
'jid': this.model.get('jid'),
|
|
'jid': this.model.get('jid'),
|
|
'fullname': this.model.get('fullname'),
|
|
'fullname': this.model.get('fullname'),
|