Skip to content

Commit e49bf9d

Browse files
committed
fix: Change how _localizeMarker() is called; updated README (#4) (#1)
1 parent a7c17f4 commit e49bf9d

5 files changed

Lines changed: 26 additions & 24 deletions

File tree

‎Leaflet.a11y.js‎

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
let mapElem;
2222
let _initialized = false;
2323

24+
// Dummy/placeholder "translation" function.
25+
L._ = L._ || ((str) => str);
26+
2427
function onLoad (ev) {
2528
console.assert(ev && ev.type && ev.target && ev.target.on);
2629
let layer = 0;
@@ -51,12 +54,6 @@
5154
_fixMapContainer();
5255
_managePopupFocus(MAP);
5356

54-
setTimeout(() => {
55-
// After all layers created, translate.
56-
_localizeMarkers(MAP);
57-
// _fixMarkers(MAP);
58-
}, 500);
59-
6057
console.debug('a11y.initialize:', mapElem, [mapElem], MAP.getPanes(), MAP);
6158
}
6259

@@ -74,17 +71,17 @@
7471

7572
/** Only translate the default marker ALT text, for now.
7673
*/
77-
function _localizeMarkers (MAP) {
78-
const MARKER_PANE = MAP.getPane('markerPane'); // Was: MAP_EL.querySelector('.leaflet-marker-pane');
74+
function _localizeMarker (PIN_EL) {
75+
// const MARKER_PANE = MAP.getPane('markerPane'); // Was: MAP_EL.querySelector('.leaflet-marker-pane');
7976

80-
[...MARKER_PANE.children].forEach(PIN_EL => {
81-
if (PIN_EL.alt === 'Marker') {
82-
PIN_EL.alt = L._('Marker');
83-
PIN_EL.title = L._('Marker');
84-
}
85-
});
77+
// [...MARKER_PANE.children].forEach(PIN_EL => {
78+
if (PIN_EL.alt === 'Marker') {
79+
PIN_EL.alt = L._('Marker');
80+
PIN_EL.title = L._('Marker');
81+
}
82+
// });
8683

87-
console.debug('localizeMarkers:', MARKER_PANE.children);
84+
// console.debug('localizeMarkers:', MARKER_PANE.children);
8885
}
8986

9087
function _localizePopups (MAP) {
@@ -123,6 +120,9 @@
123120
markerEl.role = '';
124121
markerEl.classList.add('x-static-marker');
125122
}
123+
if (markerEl) {
124+
_localizeMarker(markerEl);
125+
}
126126
console.debug('a11y.layeradd', layerIdx, isInteractive, markerEl, ev);
127127
layerIdx++;
128128
});

‎README.md‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ Uses the [Leaflet.i18n][] internationalisation plugin.
88

99
This plugin does _NOT_ replace [accessibility][] efforts in [core Leaflet][bugs]. It is a means to provide interim fixes, and test potential fixes.
1010

11-
The plugin currently does 3 things:
11+
The plugin currently does the following:
1212

13-
1. Sets a `role` and `aria-label` on the Leaflet map container element (see [L-7193][]).
14-
2. Manages keyboard focus when popups are opened and closed (see [L-8115][]).
15-
3. Translates map controls (Zoom in, Zoom out, Close popup, ...) into a language that has been set with `setLocale` ([Leaflet.i18n][]). Mostly relevant for accessibility, as most text is hidden from visual users.
13+
1. Set a `role` and `aria-label` on the Leaflet map container element (see [L-7193][]).
14+
2. Manage keyboard focus when popups are opened and closed (see [L-8115][]).
15+
3. Fix so non-interactive markers are correctly identified ([L-8116][])
16+
4. Translate map controls (Zoom in, Zoom out, Close popup, ...) into a language that has been set with `setLocale` ([Leaflet.i18n][]). Mostly relevant for accessibility, as most text is hidden from visual users.
1617

1718
More to follow!
1819

@@ -28,7 +29,7 @@ Include or `import` core Leaflet and the plugins:
2829
<script src="path/to/Leaflet.a11y.js"></script>
2930
```
3031

31-
Then, call initialize the accessibility plugin with `L.a11y.onLoad` before calling `setView`:
32+
Then, initialize the accessibility plugin with `L.a11y.onLoad` before calling `setView`:
3233

3334
```js
3435
const MAP = L.map('map')
@@ -55,5 +56,7 @@ License: [MIT][].
5556
"Make the leaflet-container a programmatically determinable element"
5657
[L-8115]: https://github.com/Leaflet/Leaflet/issues/8115
5758
"Focus management between markers and popups"
59+
[L-8116]: https://github.com/Leaflet/Leaflet/issues/8116
60+
"Discern interactive markers from non-interactive markers"
5861
[Maps WCAG eval]: https://github.com/Malvoz/web-maps-wcag-evaluation
5962
"Web map tools WCAG 2.1 evaluation - A manual accessibility evaluation of popular web map tools."

‎example/app.js‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ async function importAndSetLocale (location, L) {
4949
const FILE = MATCH ? MATCH[1] : null;
5050

5151
if (FILE) {
52-
const { LOCALE } = await import(`./locale/${FILE}.js`);
53-
const CODE = FILE.replace(/-TEST/, '');
52+
const { LOCALE, CODE } = await import(`./locale/${FILE}.js`);
5453

5554
L.registerLocale(CODE, LOCALE);
5655
L.setLocale(CODE);

‎locale/en-TEST.js‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
* @summary Test English locale - Add [Z] to the end of each string, for demo/debugging.
44
*/
55

6+
export const CODE = 'en';
67
export const LOCALE = {
7-
// The actual language code.
8-
// _locale: 'en',
98
// Attribution - Leaflet, OpenStreetMap, ...
109
'A JavaScript library for interactive maps': 'A JavaScript library for interactive maps [Z]',
1110
'© OpenStreetMap': '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> [Z]',

‎locale/fr.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* @see https://translate.google.com/?sl=auto&tl=fr&text=A%20JavaScript%20library%20for%20interactive%20maps%0AClose%0Amap%0AMarker%0AMap%20marker%0AZoom%20in%0AZoom%20out%0AHello%20world!%0AHello!%20I%E2%80%99m%20a%20translation%20test.&op=translate
55
*/
66

7+
export const CODE = 'fr';
78
export const LOCALE = {
89
// Attribution - Leaflet, OpenStreetMap, ...
910
'A JavaScript library for interactive maps': 'Une bibliothèque JavaScript pour cartes interactives',

0 commit comments

Comments
 (0)