3 var appEvents = require('../../utils/appevents');
4 var ChatInputView = require('../chat/chatInputView');
5 var cocktail = require('backbone.cocktail');
6 var KeyboardEventsMixin = require('../keyboard-events-mixin');
7 var unreadItemsClient = require('../../components/unread-items-client');
8 var UnreadBannerView = require('../app/unreadBannerView');
10 var context = require('gitter-web-client-context');
11 var JoinRoomView = require('../chat/join-room-view');
13 //var ChatToolbarLayout = require('./chat-toolbar');
14 var ChatLayout = require('./chat');
16 require('../behaviors/isomorphic');
18 var EmbedLayout = ChatLayout.extend({
19 monitorUnreadItems: true,
21 backspace: 'onKeyBackspace',
26 'change:roomMember': '_roomMemberChanged'
29 _roomMemberChanged: function() {
30 var inputRegion = this.regionManager.get('input');
32 if (this.model.get('roomMember')) {
35 model: context.troupe(),
36 collection: this.options.chatCollection
40 inputRegion.show(new JoinRoomView({}));
47 el: '#content-wrapper',
48 init: 'initChatRegion' // Declared in super
53 init: 'initInputRegion'
56 // TODO Move to chat-toolbar layout and
57 // decide how are they gonna look like in mobile
60 init: 'initBannerTopRegion'
65 el: '#bottom-unread-banner',
66 init: 'initBannerBottomRegion'
71 initInputRegion: function(optionsForRegion) {
72 if (this.model.get('roomMember')) {
73 return new ChatInputView(
76 model: context.troupe(),
77 collection: this.options.chatCollection
83 return new JoinRoomView(optionsForRegion({}, { rerender: true }));
87 initBannerTopRegion: function(optionsForRegion) {
88 return new UnreadBannerView.Top(
90 model: unreadItemsClient.acrossTheFold()
95 initBannerBottomRegion: function(optionsForRegion) {
96 return new UnreadBannerView.Bottom(
98 model: unreadItemsClient.acrossTheFold()
103 onKeyBackspace: function(e) {
108 onKeyQuote: function(e) {
114 getSelectionText: function() {
116 if (window.getSelection) {
117 text = window.getSelection().toString();
118 } else if (document.selection && document.selection.type != 'Control') {
119 text = document.selection.createRange().text;
124 quoteText: function() {
125 var selectedText = this.getSelectionText();
126 if (selectedText.length > 0) {
127 appEvents.trigger('input.append', '> ' + selectedText, { newLine: true });
132 cocktail.mixin(EmbedLayout, KeyboardEventsMixin);
134 module.exports = EmbedLayout;