@@ -22,6 +22,13 @@ export default class ExternalLinks {
22
22
const domain = window . location . hostname ;
23
23
const icon = Common . makeIcon ( 'external' , 'icon--medium ml-1' ) ;
24
24
25
+ // Translations are defined in models/strings.php,
26
+ // and loaded to windows.s in lib/Assets.php.
27
+ const translations = window . s . common || {
28
+ target_blank : 'Opens in a new window' ,
29
+ external_link : 'The link takes you to an external website' ,
30
+ } ;
31
+
25
32
// Links in regular context
26
33
$ ( '#main-content a[href*="//"]:not(.button, .logo-wall__link, .link-list a, [href*="' + domain + '"])' ) . append ( icon ) ; // eslint-disable-line
27
34
@@ -46,13 +53,17 @@ export default class ExternalLinks {
46
53
$ ( this ) . children ( '.icon' ) . attr ( 'aria-hidden' , 'true' ) ;
47
54
} ) ;
48
55
49
- // Translations are defined in models/strings.php,
50
- // and loaded to windows.s in lib/Assets.php.
51
- const translations = window . s . common || {
52
- target_blank : 'Opens in a new window' ,
53
- } ;
56
+ // Add screen reader text that informs if the link is an external website
57
+ $ ( '#main-content a[href*="//"]:not([href*="' + domain + '"])' ) . append ( `<span class="is-sr-only external-info">(${ translations . external_link } )</span>` ) ; // eslint-disable-line
54
58
55
59
// Add instructional text for screen readers on links which open a new window/tab
56
- $ ( 'a[target="_blank"]' ) . append ( `<span class="is-sr-only">(${ translations . target_blank } )</span>` ) ;
60
+ if ( $ ( 'a[target="_blank"]' ) . children ( '.external-info' ) . length > 0 ) {
61
+ // Append the info with external link info
62
+ $ ( 'a[target="_blank"] .external-info' ) . append ( `(${ translations . target_blank } )</span>` ) ;
63
+ }
64
+ else {
65
+ // Append info to the link as its own element
66
+ $ ( 'a[target="_blank"]' ) . append ( `<span class="is-sr-only">(${ translations . target_blank } )</span>` ) ;
67
+ }
57
68
}
58
69
}
0 commit comments