Commit 8f601e8c authored by JC Brand's avatar JC Brand

Found more stuff in core that should go to converse-minimize

parent ed4b9a85
...@@ -64,7 +64,6 @@ ...@@ -64,7 +64,6 @@
events: { events: {
'click .close-chatbox-button': 'close', 'click .close-chatbox-button': 'close',
'click .toggle-chatbox-button': 'minimize',
'keypress textarea.chat-textarea': 'keyPressed', 'keypress textarea.chat-textarea': 'keyPressed',
'click .toggle-smiley': 'toggleEmoticonMenu', 'click .toggle-smiley': 'toggleEmoticonMenu',
'click .toggle-smiley ul li': 'insertEmoticon', 'click .toggle-smiley ul li': 'insertEmoticon',
...@@ -84,7 +83,6 @@ ...@@ -84,7 +83,6 @@
this.model.on('change:chat_state', this.sendChatState, this); this.model.on('change:chat_state', this.sendChatState, this);
this.model.on('change:chat_status', this.onChatStatusChanged, this); this.model.on('change:chat_status', this.onChatStatusChanged, this);
this.model.on('change:image', this.renderAvatar, this); this.model.on('change:image', this.renderAvatar, this);
this.model.on('change:minimized', this.onMinimizedChanged, this);
this.model.on('change:status', this.onStatusChanged, this); this.model.on('change:status', this.onStatusChanged, this);
this.model.on('showHelpMessages', this.showHelpMessages, this); this.model.on('showHelpMessages', this.showHelpMessages, this);
this.model.on('sendMessage', this.sendMessage, this); this.model.on('sendMessage', this.sendMessage, this);
...@@ -100,6 +98,7 @@ ...@@ -100,6 +98,7 @@
show_textarea: true, show_textarea: true,
title: this.model.get('fullname'), title: this.model.get('fullname'),
info_close: __('Close this chat box'), info_close: __('Close this chat box'),
// FIXME: leaky-abstraction from converse-minimize
info_minimize: __('Minimize this chat box'), info_minimize: __('Minimize this chat box'),
label_personal_message: __('Personal message') label_personal_message: __('Personal message')
} }
...@@ -450,12 +449,16 @@ ...@@ -450,12 +449,16 @@
} }
}, },
shouldShowOnTextMessage: function () {
return !this.$el.is(':visible');
},
handleTextMessage: function (message) { handleTextMessage: function (message) {
this.showMessage(_.clone(message.attributes)); this.showMessage(_.clone(message.attributes));
if ((message.get('sender') !== 'me') && (converse.windowState === 'blur')) { if ((message.get('sender') !== 'me') && (converse.windowState === 'blur')) {
converse.incrementMsgCounter(); converse.incrementMsgCounter();
} }
if (!this.model.get('minimized') && !this.$el.is(':visible')) { if (this.shouldShowOnTextMessage()) {
this.show(); this.show();
} }
}, },
...@@ -642,26 +645,22 @@ ...@@ -642,26 +645,22 @@
}, },
setChatBoxHeight: function (height) { setChatBoxHeight: function (height) {
if (!this.model.get('minimized')) { if (height) {
if (height) { height = converse.applyDragResistance(height, this.model.get('default_height'))+'px';
height = converse.applyDragResistance(height, this.model.get('default_height'))+'px'; } else {
} else { height = "";
height = "";
}
this.$el.children('.box-flyout')[0].style.height = height;
} }
this.$el.children('.box-flyout')[0].style.height = height;
}, },
setChatBoxWidth: function (width) { setChatBoxWidth: function (width) {
if (!this.model.get('minimized')) { if (width) {
if (width) { width = converse.applyDragResistance(width, this.model.get('default_width'))+'px';
width = converse.applyDragResistance(width, this.model.get('default_width'))+'px'; } else {
} else { width = "";
width = "";
}
this.$el[0].style.width = width;
this.$el.children('.box-flyout')[0].style.width = width;
} }
this.$el[0].style.width = width;
this.$el.children('.box-flyout')[0].style.width = width;
}, },
resizeChatBox: function (ev) { resizeChatBox: function (ev) {
...@@ -746,14 +745,6 @@ ...@@ -746,14 +745,6 @@
}); });
}, },
onMinimizedChanged: function (item) {
if (item.get('minimized')) {
this.minimize();
} else {
this.maximize();
}
},
showStatusMessage: function (msg) { showStatusMessage: function (msg) {
msg = msg || this.model.get('status'); msg = msg || this.model.get('status');
if (typeof msg === "string") { if (typeof msg === "string") {
...@@ -777,34 +768,6 @@ ...@@ -777,34 +768,6 @@
return this; return this;
}, },
onMaximized: function () {
converse.chatboxviews.trimChats(this);
utils.refreshWebkit();
this.$content.scrollTop(this.model.get('scroll'));
this.setChatState(converse.ACTIVE).focus();
converse.emit('chatBoxMaximized', this);
},
onMinimized: function () {
utils.refreshWebkit();
converse.emit('chatBoxMinimized', this);
},
maximize: function () {
// Restore a minimized chat box
$('#conversejs').prepend(this.$el);
this.$el.show('fast', this.onMaximized.bind(this));
return this;
},
minimize: function (ev) {
if (ev && ev.preventDefault) { ev.preventDefault(); }
// save the scroll position to restore it on maximize
this.model.save({'scroll': this.$content.scrollTop()});
this.setChatState(converse.INACTIVE).model.minimize();
this.$el.hide('fast', this.onMinimized.bind(this));
},
renderToolbar: function (options) { renderToolbar: function (options) {
if (!converse.show_toolbar) { if (!converse.show_toolbar) {
return; return;
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
define("converse-minimize", [ define("converse-minimize", [
"converse-core", "converse-core",
"converse-api", "converse-api",
"converse-chatview"
], factory); ], factory);
}(this, function (converse, converse_api) { }(this, function (converse, converse_api) {
"use strict"; "use strict";
...@@ -93,15 +94,79 @@ ...@@ -93,15 +94,79 @@
}, },
}, },
ChatBoxView: {
events: {
'click .toggle-chatbox-button': 'minimize',
},
initialize: function () {
this.model.on('change:minimized', this.onMinimizedChanged, this);
return this._super.initialize.apply(this, arguments);
},
shouldShowOnTextMessage: function () {
return !this.model.get('minimized') &&
this._super.shouldShowOnTextMessage.apply(this, arguments);
},
setChatBoxHeight: function (height) {
if (!this.model.get('minimized')) {
return this._super.setChatBoxHeight.apply(this, arguments);
}
},
setChatBoxWidth: function (width) {
if (!this.model.get('minimized')) {
return this._super.setChatBoxWidth.apply(this, arguments);
}
},
onMinimizedChanged: function (item) {
if (item.get('minimized')) {
this.minimize();
} else {
this.maximize();
}
},
onMaximized: function () {
converse.chatboxviews.trimChats(this);
utils.refreshWebkit();
this.$content.scrollTop(this.model.get('scroll'));
this.setChatState(converse.ACTIVE).focus();
converse.emit('chatBoxMaximized', this);
},
onMinimized: function () {
utils.refreshWebkit();
converse.emit('chatBoxMinimized', this);
},
maximize: function () {
// Restore a minimized chat box
$('#conversejs').prepend(this.$el);
this.$el.show('fast', this.onMaximized.bind(this));
return this;
},
minimize: function (ev) {
if (ev && ev.preventDefault) { ev.preventDefault(); }
// save the scroll position to restore it on maximize
this.model.save({'scroll': this.$content.scrollTop()});
this.setChatState(converse.INACTIVE).model.minimize();
this.$el.hide('fast', this.onMinimized.bind(this));
},
},
ChatBoxes: { ChatBoxes: {
chatBoxShouldBeShown: function (chatbox) { chatBoxShouldBeShown: function (chatbox) {
return this._super.chatBoxShouldBeShown.apply(this, arguments) && return this._super.chatBoxShouldBeShown.apply(this, arguments) &&
!chatbox.get('minimized'); !chatbox.get('minimized');
}, },
}, },
ChatBoxViews: { ChatBoxViews: {
showChat: function (attrs) { showChat: function (attrs) {
/* Find the chat box and show it. If it doesn't exist, create it. /* Find the chat box and show it. If it doesn't exist, create it.
*/ */
......
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