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