2 var $ = require('jquery');
3 const Backbone = require('backbone');
4 var context = require('gitter-web-client-context');
5 var clientEnv = require('gitter-client-env');
6 var onready = require('./utils/onready');
7 const ArchiveLayout = require('./views/layouts/archive');
8 const ChatModel = require('./collections/chat.js').ChatModel;
9 const appEvents = require('./utils/appevents');
10 const generatePermalink = require('gitter-web-shared/chat/generate-permalink');
11 const moment = require('moment');
12 const pushState = require('./utils/browser/pushState');
14 /* Set the timezone cookie */
15 require('./components/timezone-cookie');
17 require('./views/widgets/preload');
18 require('./components/dozy');
19 require('./template/helpers/all');
20 require('./components/bug-reporting');
21 require('./utils/tracking');
22 require('./components/ping');
25 require('./views/widgets/avatar');
27 require('@gitterhq/styleguide/css/components/buttons.css');
30 $(document).on('click', 'a', function(e) {
32 var href = $(this).attr('href');
33 if (href.indexOf('#') === 0) {
35 window.location = href;
41 // When a user clicks an internal link, prevent it from opening in a new window
42 $(document).on('click', 'a.link', function(e) {
43 var basePath = clientEnv['basePath'];
44 var href = e.target.getAttribute('href');
45 if (!href || href.indexOf(basePath) !== 0) {
50 window.parent.location.href = href;
53 appEvents.on('permalink.requested', function(type, chatItem) {
54 const troupeUrl = context.troupe().get('url');
55 const id = chatItem.id;
56 const sent = moment(chatItem.get('sent'), moment.defaultFormat);
57 const url = generatePermalink(troupeUrl, id, sent, true);
58 pushState(url, troupeUrl);
61 const ArchiveChatCollection = Backbone.Collection.extend({
64 // When on the archive view, we only show the messages for the given day (no infinite scroll)
65 // so we want to avoid loading any more and pass a noop function here
66 fetchMoreBefore: () => 'noop',
67 fetchMoreAfter: () => 'noop',
68 ensureLoaded: function(id, callback = () => 'noop') {
69 callback(null, this.get(id));
73 const appView = new ArchiveLayout({
74 model: context.troupe(),
77 chatCollection: new ArchiveChatCollection(context().archive.messages)