From 22c72430439f6df25592775a1c82ecd6656e658c Mon Sep 17 00:00:00 2001 From: JC Brand Date: Fri, 25 Apr 2014 21:48:56 +0200 Subject: [PATCH] Initial work on managing the number of open chat boxes --- converse.js | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/converse.js b/converse.js index 3c4a4e5ce..eed4c34d4 100644 --- a/converse.js +++ b/converse.js @@ -942,6 +942,7 @@ }, render: function () { + converse.emit('beforeChatBoxOpens', this); this.$el.attr('id', this.model.get('box_id')) .html(converse.templates.chatbox( _.extend(this.model.toJSON(), { @@ -1492,7 +1493,6 @@ // localstorage this.model.save(); } - converse.emit('onChatBoxOpened', this); return this; }, @@ -2540,6 +2540,25 @@ view.initialize(); } }, this); + + converse.on('beforeChatBoxOpens', function (ev, view) { + var total_width = this.$el.width(); + var box_width = view.$el.outerWidth(); + var num_views = _.keys(views).length; + var toggle_width = 0; // TODO + var num_visible_views = 1; // Include view about to be opened + _.each(views, function (v) { + if (v.$el.is(':visible')) { + num_visible_views += 1; + } + }); + if (num_visible_views === 1) { + return; + } + if ((num_visible_views*box_width + toggle_width) > total_width) { + // TODO: close the oldest checkbox + } + }.bind(this)); }, showChatBox: function (attrs) {