@companieshouse/ch-node-utils 1.3.3 → 1.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +24 -0
- package/package.json +1 -1
- package/templates/locales-banner.njk +37 -15
package/README.md
CHANGED
|
@@ -76,3 +76,27 @@ Available as a normal npm dependency([here on npmjs](https://www.npmjs.com/packa
|
|
|
76
76
|
| ------- | ----------- |
|
|
77
77
|
|`CH_NODE_UTILS_DROP_LANG_QUERY_PARAM`| It could be set to [drop the lang="xx" query param](https://github.com/companieshouse/ch-node-utils/blob/f9e5c47a86206f0b12e4e536c4c459db16747631/src/middleware/manageLocales.middleware.ts#L25) from the current URL ([see Example](https://github.com/companieshouse/docker-chs-development/blob/842c61245adcbba02a6316847fc4f9d94c52410d/services/modules/dissolution/dissolution-web.docker-compose.yaml#L50)) |
|
|
78
78
|
|`CH_NODE_UTILS_LOG_LVL`| It could be set to ["TRACE" or "DEBUG" (case insensitive)](https://github.com/companieshouse/ch-node-utils/blob/24bc717477d21082439d1b460108cb0d60465f0f/src/utils/log.ts#L2) to dump internal info while inside ch-node-utils ([see Example](https://github.com/companieshouse/docker-chs-development/blob/842c61245adcbba02a6316847fc4f9d94c52410d/services/modules/dissolution/dissolution-web.docker-compose.yaml#L49))|
|
|
79
|
+
|
|
80
|
+
### Menu navigation bar
|
|
81
|
+
A menu navigation bar component has been added to make it easier to add links pointing to new services when needed. There are two Nunjucks macros: one that adds a menu navigation bar with the provided items and another that adds a menu navigation bar with predefined items. The latter internally uses the former and at the moment contains links to the following service:
|
|
82
|
+
|
|
83
|
+
- Authorised agent
|
|
84
|
+
- Your companies
|
|
85
|
+
- Your filings
|
|
86
|
+
- Companies you follow
|
|
87
|
+
- Basket
|
|
88
|
+
- Manage account
|
|
89
|
+
- Sign out
|
|
90
|
+
|
|
91
|
+
The "Authorised agent" menu item appears conditionally if the logged user has ACSP membership.
|
|
92
|
+
|
|
93
|
+
The navbar requires importing language files from the `locales` folder in ch-node-utils and making them available to all Nunjuck templates using the [`addGlobal()` function](https://mozilla.github.io/nunjucks/api.html#addglobal) in `app.ts`. At the moment only English and Welsh language versions are supported. It also requires a flag `displayAuthorisedAgent` set the same way for displaying the "Authorised agent" menu item. If the logged user has ACSP membership, this flag should be set to `'yes'`.
|
|
94
|
+
|
|
95
|
+
The navbar also requires the use of styles provided in the [ch.gov.uk.css](https://github.com/companieshouse/cdn.ch.gov.uk/blob/master/app/assets/stylesheets/ch.gov.uk.css) stylesheet (you can either add the provided link to the head section or include specific styles in your own stylesheet)
|
|
96
|
+
|
|
97
|
+
`<link href="{{ cdnHost }}/stylesheets/ch.gov.uk.css" rel="stylesheet"/>`
|
|
98
|
+
|
|
99
|
+
It also requires the [navbar.js](https://github.com/companieshouse/cdn.ch.gov.uk/blob/master/app/assets/javascripts/lib/navbar.js) script to be added to the footer to make the navbar work in mobile mode
|
|
100
|
+
|
|
101
|
+
`<script src="{{ cdnHost }}/javascripts/lib/navbar.js"></script>`
|
|
102
|
+
|
package/package.json
CHANGED
|
@@ -3,29 +3,51 @@ template to be reused in all the services to display the locales menu/banner.
|
|
|
3
3
|
It receives:
|
|
4
4
|
- languageEnabled: to keep all hidden if feature-flag is off
|
|
5
5
|
- languages: array of pairs {.Name (i.e. 'English') .IsoCode (i.e. 'en') }
|
|
6
|
-
- currentUrl: self-url. It's used to resend to the backend the same request
|
|
6
|
+
- currentUrl: self-url. It's used to resend to the backend the same request with the proper
|
|
7
7
|
query parameter ("lang=..") set
|
|
8
8
|
(i.e. https://.....<self>....../?lang=cy)
|
|
9
9
|
#}
|
|
10
10
|
|
|
11
|
-
<div class="govuk-width-container
|
|
11
|
+
<div class="govuk-width-container">
|
|
12
12
|
<div class="govuk-grid-column-full no-padd">
|
|
13
13
|
<nav class="govuk-language-select" aria-label="Language switcher">
|
|
14
14
|
<ul class="govuk-language-select__list">
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
15
|
+
{% if languageEnabled %}
|
|
16
|
+
{% for l in languages %}
|
|
17
|
+
<li class="govuk-language-select__list-item">
|
|
18
|
+
{% if lang and lang == l.IsoCode %}
|
|
19
|
+
<span class="govuk-body-s govuk-!-margin-2">{{ l.Name }}</span>
|
|
20
|
+
{% else %}
|
|
21
|
+
<a href="{{ lang2url.addLangToUrl(currentUrl, l.IsoCode, true) }}" lang="{{ l.IsoCode }}" rel="alternate" class="govuk-link govuk-!-margin-2 language-link">
|
|
22
|
+
<span>{{ l.Name }}</span>
|
|
23
|
+
</a>
|
|
24
|
+
{% endif %}
|
|
25
|
+
</li>
|
|
26
|
+
{% endfor %}
|
|
27
|
+
{% endif %}
|
|
28
28
|
</ul>
|
|
29
29
|
</nav>
|
|
30
30
|
</div>
|
|
31
31
|
</div>
|
|
32
|
+
|
|
33
|
+
<script>
|
|
34
|
+
document.addEventListener('DOMContentLoaded', function() {
|
|
35
|
+
const languageLinks = document.querySelectorAll('.language-link');
|
|
36
|
+
|
|
37
|
+
languageLinks.forEach(link => {
|
|
38
|
+
link.addEventListener('click', function(event) {
|
|
39
|
+
const language = this.getAttribute('lang');
|
|
40
|
+
trackLanguageChange(language);
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
function trackLanguageChange(language) {
|
|
46
|
+
const pageTitle = document.title;
|
|
47
|
+
if (typeof _paq !== 'undefined') {
|
|
48
|
+
_paq.push(['trackEvent', pageTitle, 'Language Change', language]);
|
|
49
|
+
} else {
|
|
50
|
+
console.log('Matomo not enabled, language change: ' + language);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
</script>
|