3 var Marionette = require('backbone.marionette');
4 var template = require('./tmpl/chat-input-buttons.hbs');
5 var platformKeys = require('../../utils/platform-keys');
6 var cocktail = require('backbone.cocktail');
7 var KeyboardEventsMixin = require('../keyboard-events-mixin');
8 var isMobile = require('../../utils/is-mobile');
9 require('../behaviors/tooltip');
11 var ChatInputButtons = Marionette.ItemView.extend({
16 '.js-toggle-compose-mode': {
17 titleFn: 'getComposeModeTitle',
19 customUpdateEvent: 'updateComposeTooltipText'
21 '.js-markdown-help': { titleFn: 'getShowMarkdownTitle', placement: 'left' }
26 composeToggle: '.js-toggle-compose-mode'
30 'click .js-toggle-compose-mode': 'toggleComposeMode'
34 'change:isComposeModeEnabled': 'composeModeChanged'
38 'chat.toggle': 'toggleComposeMode'
41 getComposeModeTitle: function() {
42 var mode = this.model.get('isComposeModeEnabled') ? 'chat' : 'compose';
43 return 'Switch to ' + mode + ' mode (' + platformKeys.cmd + ' + /)';
46 getShowMarkdownTitle: function() {
47 return 'Markdown help (' + platformKeys.cmd + ' + ' + platformKeys.gitter + ' + m)';
50 toggleComposeMode: function() {
51 // compose mode is always off for mobile
52 if (isMobile()) return;
54 this.model.set('isComposeModeEnabled', !this.model.get('isComposeModeEnabled'));
57 composeModeChanged: function() {
58 this.ui.composeToggle[0].setAttribute(
60 this.model.get('isComposeModeEnabled')
62 this.ui.composeToggle[0].setAttribute('aria-label', this.getComposeModeTitle());
63 this.trigger('updateComposeTooltipText');
66 serializeData: function() {
67 var data = this.model.toJSON();
69 data.composeModeMessage = this.getComposeModeTitle();
70 data.markdownHelpMessage = this.getShowMarkdownTitle();
76 cocktail.mixin(ChatInputButtons, KeyboardEventsMixin);
78 module.exports = ChatInputButtons;