1 | 'use strict'
|
2 |
|
3 | const loaddata = require('./data.js')
|
4 |
|
5 | const menu = require('./menu.js')
|
6 | const alert = require('./alert.js')
|
7 | const graph = require('./graph.js')
|
8 | const recommendation = require('./recommendation.js')
|
9 | const askBehaviours = require('@nearform/clinic-common/behaviours/ask')
|
10 |
|
11 |
|
12 | askBehaviours()
|
13 |
|
14 | menu.on('toggle-theme', function () {
|
15 | document.documentElement.classList.toggle('light-theme')
|
16 | })
|
17 |
|
18 | menu.on('toggle-grid', function () {
|
19 | document.documentElement.classList.toggle('grid-layout')
|
20 | graph.draw()
|
21 | })
|
22 |
|
23 | alert.on('open', () => alert.open())
|
24 | alert.on('close', () => alert.close())
|
25 | alert.on('click', function (graphId) {
|
26 | document.getElementById(graphId).scrollIntoView({
|
27 | block: 'start',
|
28 | inline: 'nearest',
|
29 | behavior: 'smooth'
|
30 | })
|
31 | })
|
32 | alert.on('hover-in', function (graphId) {
|
33 | document.getElementById(graphId).classList.add('highlight')
|
34 | })
|
35 | alert.on('hover-out', function (graphId) {
|
36 | document.getElementById(graphId).classList.remove('highlight')
|
37 | })
|
38 |
|
39 | graph.on('hover-show', () => graph.hoverShow())
|
40 | graph.on('hover-hide', () => graph.hoverHide())
|
41 | graph.on('hover-update', (unitX) => graph.hoverUpdate(unitX))
|
42 |
|
43 | graph.on('alert-click', function () {
|
44 | document.documentElement.classList.add('recommendation-open')
|
45 | recommendation.openPanel()
|
46 | recommendation.draw()
|
47 | })
|
48 |
|
49 | recommendation.on('open-panel', function () {
|
50 | document.documentElement.classList.add('recommendation-open')
|
51 | recommendation.openPanel()
|
52 | recommendation.draw()
|
53 | })
|
54 | recommendation.on('close-panel', function () {
|
55 | document.documentElement.classList.remove('recommendation-open')
|
56 | recommendation.closePanel()
|
57 | recommendation.draw()
|
58 | })
|
59 |
|
60 | recommendation.on('menu-click', function (category) {
|
61 | recommendation.setPage(category)
|
62 | recommendation.draw()
|
63 | })
|
64 |
|
65 | recommendation.on('open-read-more', function () {
|
66 | document.documentElement.classList.add('recommendation-read-more-open')
|
67 | recommendation.openReadMore()
|
68 | recommendation.draw()
|
69 | recommendation.setPage(recommendation.selectedCategory)
|
70 | })
|
71 | recommendation.on('close-read-more', function () {
|
72 | document.documentElement.classList.remove('recommendation-read-more-open')
|
73 | recommendation.closeReadMore()
|
74 | recommendation.draw()
|
75 | })
|
76 |
|
77 | recommendation.on('open-undetected', function () {
|
78 | recommendation.openUndetected()
|
79 | recommendation.draw()
|
80 | })
|
81 | recommendation.on('close-undetected', function () {
|
82 | recommendation.closeUndetected()
|
83 | recommendation.setPage(recommendation.defaultCategory)
|
84 | recommendation.draw()
|
85 | })
|
86 |
|
87 | loaddata(function maybeDone (err, data) {
|
88 | if (err) throw err
|
89 |
|
90 | alert.setData(data)
|
91 | alert.draw()
|
92 |
|
93 | graph.setData(data)
|
94 | graph.draw()
|
95 |
|
96 | recommendation.setData(data)
|
97 | recommendation.draw()
|
98 |
|
99 | window.addEventListener('resize', function () {
|
100 | alert.draw()
|
101 | graph.draw()
|
102 | })
|
103 | })
|