forked from fecgov/regulations-site
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdrawer-view.js
66 lines (51 loc) · 2 KB
/
drawer-view.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import storage from '../../redux/storage';
import { activePane } from '../../redux/reducers';
const $ = require('jquery');
const Backbone = require('backbone');
const TOCView = require('./toc-view');
const HistoryView = require('./history-view');
const SearchView = require('./search-view');
const DrawerTabs = require('./drawer-tabs-view');
Backbone.$ = $;
const DrawerView = Backbone.View.extend({
el: '#menu',
initialize: function initialize(options) {
storage().subscribe(this.handleReduxUpdate.bind(this));
this.$label = $('.toc-type');
this.$children = $('.toc-container');
this.childViews = {};
this.childViews['table-of-contents'] = new TOCView();
this.childViews.timeline = new HistoryView();
this.childViews.search = new SearchView();
this.childViews['drawer-tabs'] = new DrawerTabs({ forceOpen: options.forceOpen });
const $tocSecondary = $('#table-of-contents-secondary');
if ($tocSecondary.length) {
this.childViews['table-of-contents-secondary'] = new TOCView({ el: $tocSecondary });
}
this.setActivePane('table-of-contents');
},
// page types are more diverse and are named differently for
// semantic reasons, so we need to associate page types
// with the drawer panes they should be associated with
pageTypeMap: {
diff: 'timeline',
'reg-section': 'table-of-contents',
error: 'table-of-contents',
'search-results': 'search',
},
handleReduxUpdate: function handleReduxUpdate() {
this.setActivePane(activePane(storage()));
},
// selectedId = page type or child view type
setActivePane: function setActivePane(selectedId) {
let activeId = selectedId;
if (typeof this.childViews[activeId] === 'undefined') {
activeId = this.pageTypeMap[activeId];
}
// hide the content of all drawer sections
this.$children.addClass('hidden');
// remove the 'hidden' class from the active drawer section
this.childViews[activeId].$el.removeClass('hidden');
},
});
module.exports = DrawerView;