3 var $ = require('jquery');
4 var Marionette = require('backbone.marionette');
5 var context = require('gitter-web-client-context');
6 var clientEnv = require('gitter-client-env');
7 var apiClient = require('../../components/api-client');
8 var social = require('../../utils/social');
9 var ModalView = require('./modal');
10 var cdn = require('gitter-web-cdn');
11 var template = require('./tmpl/share-view.hbs');
12 var ZeroClipboard = require('zeroclipboard'); // eslint-disable-line node/no-missing-require
13 var backendUtils = require('gitter-web-shared/backend-utils');
15 require('@gitterhq/styleguide/css/components/buttons.css');
17 ZeroClipboard.config({ swfPath: cdn('repo/zeroclipboard/ZeroClipboard.swf') });
19 var View = Marionette.ItemView.extend({
21 className: 'share-view',
23 initialize: function() {
24 this.listenTo(this, 'menuItemClicked', this.menuItemClicked);
28 'click .js-badge': 'sendBadgePullRequest'
31 menuItemClicked: function(button) {
35 window.location.hash = '#add';
44 getShareUrl: function() {
46 clientEnv['basePath'] +
48 context.getTroupe().uri +
49 '?utm_source=share-link&utm_medium=link&utm_campaign=share-link'
53 getBadgeUrl: function() {
54 return clientEnv['badgeBaseUrl'] + '/' + context.getTroupe().uri + '.svg';
57 getBadgeMD: function() {
59 clientEnv['basePath'] +
61 context.getTroupe().uri +
62 '?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge';
63 return '[![Gitter](' + this.getBadgeUrl() + ')](' + linkUrl + ')';
66 detectFlash: function() {
67 if (navigator.plugins && navigator.plugins['Shockwave Flash']) {
71 if (~navigator.appVersion.indexOf('MSIE') && !~navigator.userAgent.indexOf('Opera')) {
73 new window.ActiveXObject('ShockwaveFlash.ShockwaveFlash');
83 serializeData: function() {
84 var room = context.getTroupe();
85 var isAdmin = context.isTroupeAdmin();
87 var isRepo = !!backendUtils.getLinkPathCond('GH_REPO', room);
91 isPublic: room.public,
92 allowBadgePR: room.public && isAdmin,
93 hasFlash: this.detectFlash(),
94 // FIXME: This used to be named `url` but we ran into https://github.com/altano/handlebars-loader/issues/75
95 stub: this.getShareUrl(),
96 badgeUrl: this.getBadgeUrl(),
97 badgeMD: this.getBadgeMD(),
98 twitterUrl: social.generateTwitterShareUrl(room.uri),
99 facebookUrl: social.generateFacebookShareUrl(room.uri),
100 linkedinLink: social.generateLinkedinShareUrl(room.uri),
101 googlePlusLink: social.generateGooglePlusShareUrl(room.uri)
105 onRender: function() {
106 // ZeroClipboard instances are left hanging around
107 // even after this view is closed.
108 // 500pts will be awarded if you can fix this.
109 var clipboard = new ZeroClipboard(this.$el.find('.js-copy'));
110 clipboard.on('aftercopy', function(e) {
111 $(e.target).text('Copied!');
115 sendBadgePullRequest: function(e) {
118 $btn.text('Sending...');
122 .post('/create-badge', { uri: context.troupe().get('uri') }, { global: false })
124 $btn.text('Pull Request sent!');
127 $btn.text('Failed. Try again?');
128 btn.disabled = false;
133 var Modal = ModalView.extend({
134 initialize: function(options) {
135 options = options || {};
136 options.title = options.title || 'Share this chat room';
138 ModalView.prototype.initialize.call(this, options);
139 this.view = new View(options);
142 { action: 'add', pull: 'right', text: 'Add people', className: 'modal--default__footer__link' }