UNPKG

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