Try to fix some corner cases resulting from narrow window widths.

This commit is contained in:
JC Brand 2014-06-14 18:21:52 +02:00
parent 190142a0b0
commit d45ba9e57e

View File

@ -2549,7 +2549,8 @@
if (converse.no_trimming || (this.model.length <= 1)) { if (converse.no_trimming || (this.model.length <= 1)) {
return; return;
} }
var controlbox_width = 0, var oldest_chat,
controlbox_width = 0,
$minimized = converse.minimized_chats.$el, $minimized = converse.minimized_chats.$el,
minimized_width = _.contains(this.model.pluck('minimized'), true) ? $minimized.outerWidth(true) : 0, minimized_width = _.contains(this.model.pluck('minimized'), true) ? $minimized.outerWidth(true) : 0,
boxes_width = newchat ? newchat.$el.outerWidth(true) : 0, boxes_width = newchat ? newchat.$el.outerWidth(true) : 0,
@ -2570,7 +2571,10 @@
}); });
if ((minimized_width + boxes_width + controlbox_width) > this.$el.outerWidth(true)) { if ((minimized_width + boxes_width + controlbox_width) > this.$el.outerWidth(true)) {
this.getOldestMaximizedChat().minimize(); oldest_chat = this.getOldestMaximizedChat();
if (oldest_chat) {
oldest_chat.minimize();
}
} }
}, },
@ -2578,12 +2582,12 @@
// Get oldest view (which is not controlbox) // Get oldest view (which is not controlbox)
var i = 0; var i = 0;
var model = this.model.sort().at(i); var model = this.model.sort().at(i);
console.log(this.model.pluck('time_opened'));
console.log(this.model.pluck('id'));
console.log(this.model.pluck('minimized'));
while (model.get('id') === 'controlbox' || model.get('minimized') === true) { while (model.get('id') === 'controlbox' || model.get('minimized') === true) {
i++; i++;
model = this.model.at(i); model = this.model.at(i);
if (!model) {
return null;
}
} }
return model; return model;
}, },
@ -2673,9 +2677,8 @@
if (ev && ev.preventDefault) { if (ev && ev.preventDefault) {
ev.preventDefault(); ev.preventDefault();
} }
this.$el.remove(); this.remove();
this.model.maximize(); this.model.maximize();
return this;
}, 200) }, 200)
}); });
@ -2696,8 +2699,7 @@
} }
}, this); }, this);
this.model.on("destroy", function (item) { this.model.on("destroy", function (item) {
this.remove(item.get('id')); this.removeChat(item);
this.render();
}, this); }, this);
this.model.on("change:minimized", function (item) { this.model.on("change:minimized", function (item) {
this.onChanged(item); this.onChanged(item);
@ -2727,7 +2729,8 @@
}, },
addChat: function (item) { addChat: function (item) {
if (this.get(item.get('id'))) { var existing = this.get(item.get('id'));
if (existing && existing.$el.parent().length !== 0) {
return; return;
} }
var view = new converse.MinimizedChatBoxView({model: item}); var view = new converse.MinimizedChatBoxView({model: item});