3 var $ = require('jquery');
4 var Marionette = require('backbone.marionette');
5 var moment = require('moment');
6 var context = require('gitter-web-client-context');
7 var template = require('./tmpl/archive-navigation-view.hbs');
8 var heatmapUtils = require('../../components/archive-heatmap-utils');
10 module.exports = (function() {
11 var language = context.lang();
13 return Marionette.ItemView.extend({
15 navigation: '#archive-navigation'
18 serializeData: function() {
19 var uri = context.troupe().get('uri');
20 const { archiveContext } = this.options;
22 const p = archiveContext.previousDate && moment(archiveContext.previousDate).utc();
23 const n = archiveContext.nextDate && moment(archiveContext.nextDate).utc();
25 const archiveDate = moment(archiveContext.startDate)
29 var ordinalDate = archiveDate.format('Do');
30 var numericDate = archiveDate.format('D');
33 if (ordinalDate.indexOf('' + numericDate) === 0) {
34 ordinalPart = ordinalDate.substring(('' + numericDate).length);
38 var monthYearFormatted = archiveDate.format('MMMM YYYY');
41 previousDate: p && p.locale(language).format('Do MMM YYYY'),
43 dayOrdinal: ordinalPart,
44 previousDateLink: p && '/' + uri + '/archives/' + p.format('YYYY/MM/DD'),
45 nextDate: n && n.locale(language).format('Do MMM YYYY'),
46 nextDateLink: n && '/' + uri + '/archives/' + n.format('YYYY/MM/DD'),
47 monthYearFormatted: monthYearFormatted
51 onRender: function() {
52 const archiveDate = this.options.archiveContext && this.options.archiveContext.startDate;
53 const a = moment(archiveDate).utc();
56 // if the first day of the next month is in the future, subtract one from range
57 var next = moment(new Date(a.year(), a.month(), 1)).add(1, 'months');
58 if (next > moment()) {
62 // start and end is only for elasticsearch, so fine if it is outside of
63 // the range we're going to display. In fact we deliberately add a day on
64 // each end just in case for timezones
65 var start = moment(a).subtract(32, 'days');
67 heatmapUtils.createResponsiveHeatMap(this.ui.navigation[0], {
68 start: start.toDate(),
72 // See `./archive-heatmap-utils.js->breakpointList` and `trp3Vars.less->@archive-mid`
73 if ($(window).width() < 960) {
74 $('.js-archive-navigation-wrapper').hide();
76 $('.js-toggle-archive-navigation').on('click', function() {
77 $('.js-archive-navigation-wrapper').slideToggle();