PageSourceSearch

https://www.letstalkaboutit.nhs.uk/application/blocks/autonav/temp…=a480c6318633b8c44dbd58e8c4819835ece0f771

js letstalkaboutit.nhs.uk collected 2026-10-02 12:25:14 UTC 14,114 bytes, 335 lines download raw bytes

1$(document).ready(function () {
2    // Maximum browser width to show mobile navigation
3    var mobileNav = 991;
4    var navWrapper = $('.header .navigation ul.nav.mega');
5
6    if (mobileNav > window.innerWidth) {
7        // If on mobile
8        $('#skiplink-desktop-nav').parent().remove();
9
10        // Ensure that you can't tab to or read the navigation while it's not open
11        $('#nav').attr('aria-hidden', 'true').find('li.level-1 a').attr('aria-hidden', 'true');
12
13        $('nav ul.nav.mega li.level-1 .sub-button').removeAttr('aria-expanded').attr('tabindex', '-1');
14        $('nav ul.nav.mega .item-wrapper a').attr('aria-hidden', 'true').attr('tabindex', '-1');
15
16    } else {
17        // If on desktop
18        $('#skiplink-mobile-nav').parent().remove();
19    }
20
21    // Mobile navigation
22
23    var search_elements = $('.header .header-mobile-tool .search-form-wrapper input[type="text"], .header .header-mobile-tool .search-form-wrapper button, .header .header-mobile-tool button.close');
24
25    // Toggle mobile nav
26    $('.header .mobile-buttons #nav-toggle').on('click', function () {
27        if ($(this).attr('aria-expanded') === 'false') {
28            $(this).attr('aria-expanded', 'true');
29            $('.ccm-page').addClass('nav-open');
30
31            // Reveal mobile navigation to assistive technologies
32            $('#nav').attr('aria-hidden', 'false')
33            
34            navWrapper.find('a.level-1, a.level-1 + button').attr('tabindex', '0').attr('aria-hidden', 'false').first().focus();
35
36            // Close all mobile toolbars
37            $('.header .mobile-buttons .header-tool-button').attr('aria-expanded', 'false');
38            $('.header .header-mobile-tool').removeClass('active');
39            search_elements.attr('tabindex', '-1').attr('aria-hidden', 'true');
40
41        } else if ($(this).attr('aria-expanded') === 'true') {
42            closeMobileNav(this);
43        }
44    });
45
46    // Nagivation through mobile nav
47    navWrapper.on('click', 'li.nav-dropdown button.sub-button', function () {
48        if (mobileNav > window.innerWidth) {
49            var subMenu = $(this).next('.sub-menu-container');
50            var level = subMenu.find('> ul').data('level');
51            if (subMenu.length) {
52                subMenu.show().attr('aria-hidden', 'false').find('a.level-' + level + ', button.level-' + level).attr('tabindex', '0').attr('aria-hidden', 'false');
53                
54                subMenu.find('.nav-title').first().attr('tabindex', '0').attr('aria-hidden', 'false');
55                navWrapper.animate({
56                    'margin-left': '-=100%'     
57                }, 300);
58                setTimeout(function () {
59                    subMenu.find('.back-button').first().attr('tabindex', '0').attr('aria-hidden', 'false').focus();
60                }, 300)
61
62            }
63        }
64    });
65
66    navWrapper.on('click', 'li.nav-dropdown button.back-button', function () {
67        if (mobileNav > window.innerWidth) {
68            var subMenu = closeSubMenu(this)
69            setTimeout(function(){
70                var level = subMenu.find('> ul').data('level') - 1;
71                subMenu.closest('li').find('a.level-'+ level).focus();
72            })
73        }
74    });
75
76    // Mega navigation
77    // Reset nav on window resize
78    window.addEventListener('resize', function(event) {
79        if(window.innerWidth > mobileNav) {
80            // Ensure that you can tab to or read the navigation on desktop
81            $('#nav').attr('aria-hidden', 'false').find('li.level-1 > .item-wrapper > a').attr('aria-hidden', 'false').attr('tabindex', '0');
82            $('#nav ul.nav.mega li.level-1 > .item-wrapper > .sub-button').attr('aria-hidden', 'false').attr('tabindex', '0');
83
84            if($('.ccm-page').hasClass('nav-open')) {
85                navWrapper.css('margin-left', '0');
86                navWrapper.find('ul.sub-menu').parent().hide();
87                $('.header .mobile-buttons .nav-toggle').removeClass('active').attr('aria-expanded', 'false');
88                $('.ccm-page').removeClass('nav-open');
89            }
90        } else {
91            // Ensure that you can't tab to or read the navigation while it's not open
92            $('#nav').attr('aria-hidden', 'true').find('li.level-1 a').attr('aria-hidden', 'true').attr('tabindex', '-1');
93            $('#nav ul.nav.mega li.level-1 .sub-button').attr('aria-hidden', 'true').attr('tabindex', '-1');
94        }
95    });
96
97    // Show nav on focus - for browsers that dont support :focus-within
98    $('nav ul.nav.mega li.level-1 a').on({
99        'focus': function () {
100            if (window.innerWidth > mobileNav) {
101                $(this).closest('li.nav-dropdown.level-1').addClass('open');
102            }
103        },
104
105        'blur': function () {
106            if (window.innerWidth > mobileNav) {
107                $(this).closest('li.nav-dropdown.level-1').removeClass('open');
108            }
109        }
110    });
111
112    $('nav ul.nav.mega li.level-1 button').on({
113        'focus': function () {
114            if (window.innerWidth > mobileNav) {
115                $(this).closest('li.level-1').addClass('open');
116            }
117        },
118        'blur': function () {
119            if (window.innerWidth > mobileNav) {
120                $(this).closest('li.level-1').removeClass('open');
121            }
122        }
123    });
124
125    $('nav ul.nav.mega li.level-1 .sub-button').on({
126        'click': function () {
127            if (window.innerWidth > mobileNav && $(this).attr('aria-expanded') === 'false') {
128                $(this).closest('li.level-1').addClass('open-nav');
129                $(this).attr('aria-expanded', 'true');
130                $(this).next('ul.level-2').attr('aria-hidden', 'false').find('ul.level-3').attr('aria-hidden', 'false');
131                $(this).next('ul.level-2').find('a.nav-item').attr('tabindex', '0').attr('aria-hidden', 'false');
132
133            } else if (window.innerWidth > mobileNav && $(this).attr('aria-expanded') === 'true') {
134                $(this).closest('li.level-1').removeClass('open-nav');
135                $(this).attr('aria-expanded', 'false');
136
137                /// These 2 aren't happening
138                $(this).next('ul.level-2').attr('aria-hidden', 'true').find('ul.level-3').attr('aria-hidden', 'true');
139                $(this).next('ul.level-2').find('a.nav-item').attr('tabindex', '-1').attr('aria-hidden', 'true');
140            }
141        }
142    });
143
144    $('nav ul.nav.mega li.level-1 ul.sub-menu.level-2').parent().each(function () {
145        if (window.innerWidth > mobileNav) {
146            $(this).find('a.nav-item').last().on({
147                'blur': function () {
148                    var list_element = $(this).closest('li.level-1');
149                    list_element.removeClass('open-nav');
150                    list_element.find('.sub-button').attr('aria-expanded', 'false');
151                    $(this).closest('ul.level-2').attr('aria-hidden', 'true').find('ul.level-3').attr('aria-hidden', 'true');
152                    $(this).closest('ul.level-2').find('a.nav-item').attr('tabindex', '-1').attr('aria-hidden', 'true');
153                }
154            });
155
156            $(this).find('a.nav-item').keyup(function (e) {
157                if (e.keyCode == '27') {
158                    var list_element = $(this).closest('li.level-1');
159                    list_element.removeClass('open-nav');
160                    list_element.find('.sub-button').attr('aria-expanded', 'false').focus();
161                    $(this).closest('ul.level-2').attr('aria-hidden', 'true').find('ul.level-3').attr('aria-hidden', 'true');
162                    $(this).closest('ul.level-2').find('a.nav-item').attr('tabindex', '-1').attr('aria-hidden', 'true');
163                }
164            });
165        }
166    });
167
168    if(window.innerWidth > mobileNav) {
169        list_elements = $('li.level-1');
170        list_elements.hover(function(){
171            $(this).addClass('show-nav');
172            
173        }, function () {
174            $(this).removeClass('show-nav');
175        });
176
177        $(this).keyup(function(e) {
178            if(e.keyCode == '27') {
179                list_elements.each(function() {
180                    if($(this).hasClass('show-nav')) {
181                        $(this).removeClass('show-nav').removeClass('open-nav');
182                        $(this).find('ul.level-2').attr('aria-hidden', 'true').find('ul.level-3').attr('aria-hidden', 'true');
183                        $(this).find('ul.level-2').find('a.nav-item').attr('tabindex', '-1').attr('aria-hidden', 'true');
184                    }
185                });
186            } 
187        });
188    }
189
190    // Nav touch support
191    $('nav ul.nav.mega').on('touchstart', 'a.nav-item.level-1.nav-dropdown', function (e) {
192        if (window.innerWidth > mobileNav) {
193            e.preventDefault();
194            var btn = $(this).next('button');
195            if (btn.length) {
196                if (btn.attr('aria-expanded') === 'false') {
197                    $('nav ul.nav.mega li.level-1.open-nav').removeClass('open-nav');
198                    btn.closest('li.level-1').addClass('open-nav');
199                    btn.attr('aria-expanded', 'true');
200                    btn.next('ul.level-2').attr('aria-hidden', 'false').find('ul.level-3').attr('aria-hidden', 'false');
201                    btn.next('ul.level-2').find('a.nav-item').next().attr('tabindex', '0').attr('aria-hidden', 'false');
202                } else if (btn.attr('aria-expanded') === 'true') {
203                    btn.closest('li.level-1').removeClass('open-nav');
204                    btn.attr('aria-expanded', 'false');
205
206                    /// These 2 aren't happening
207                    btn.next('ul.level-2').attr('aria-hidden', 'true').find('ul.level-3').attr('aria-hidden', 'true');
208                    btn.next('ul.level-2').find('a.nav-item').attr('tabindex', '-1').attr('aria-hidden', 'true');
209                }
210            }
211        }
212    });
213    $("#nav-toggle").keydown(function (e) {
214        if ($('#site').hasClass('nav-open')) {
215
216            if (e.keyCode == 9) {
217                if (!e.shiftKey) {
218                    navWrapper.find('a.nav-first.level-1').focus();
219                    return false;
220                } else {
221                    closeMobileNav(this);
222                }
223            }
224        }
225
226
227        //Do other stuff when not TAB
228    });
229    navWrapper.find('a.nav-first.level-1').keydown(function (e) {
230        if (window.innerWidth < mobileNav) {
231            if ($('#site').hasClass('nav-open')) {
232
233                if (e.keyCode == 9) {
234                    if (e.shiftKey) {
235                        $('.nav-toggle').focus();
236                        return false;
237                    }
238                } else {
239                   navWrapper.find('a.nav-last[tabindex="0"]').focus();
240                    return false;
241                }
242            }
243        }
244
245
246        //Do other stuff when not TAB
247    });
248
249    navWrapper.find("a.nav-last:last-child, a.nav-last + button").keydown(function (e) {
250        if (window.innerWidth < mobileNav) {
251            if ($('#site').hasClass('nav-open')) {
252                if (!e.shiftKey) {
253                    if (e.keyCode == 9) {
254                        var thisDiv = $(this);
255                        var nextLink = [];
256                        var level = 10;
257                        while ( thisDiv.closest('li').length > 0 && nextLink.length == 0) {
258
259                            
260                            thisDiv = closeSubMenu(thisDiv);
261                            level = thisDiv.data('level') - 1;
262                            var thisDiv = thisDiv.closest('li')
263                            var nextListItem = thisDiv.next();
264                            var nextLink = nextListItem.find('a.level-' + level);
265                            
266
267                        }
268                            
269
270                        if (nextLink.length == 0) {
271                            var thisDiv = this;
272                            var count = 0;
273                            
274                            $(this).closest('ul.mega.nav').each(function () {
275                                $(this).removeAttr('style');
276                                this.scrollTop = 0;
277                                this.scrollLeft = 0;
278                            })
279                            $(".nav-toggle").focus();
280
281                            return false
282
283                        }
284                    }
285                }
286                //Do other stuff when not TAB
287            }
288        }
289    });
290
291    navWrapper.on('keydown', 'li.nav-dropdown .nav-dropdown-title > .item-wrapper > button:first-child', function (e) {
292        if (window.innerWidth < mobileNav) {
293            if ($('#site').hasClass('nav-open')) {
294                if (e.shiftKey) {
295                    if (e.keyCode == 9) {
296                        var subMenu = closeSubMenu(this);
297                        var level = subMenu.find('> ul').data('level');
298                        setTimeout(function(){
299                            subMenu.closest('li').find('a.level-' + level).focus();
300                        },300)
301                    }
302                }
303            }
304        }
305    });
306
307    var closeSubMenu = function (thisBackButton) {
308        var subMenu = $(thisBackButton).closest('.sub-menu-container');
309
310        if (subMenu.length) {
311            navWrapper.animate({
312                'margin-left': '+=100%'
313
314            }, 300, function () {
315                subMenu.hide().attr('aria-hidden', 'true').find('a.nav-item').attr('tabindex', '-1').attr('aria-hidden', 'false');
316            });
317        }
318        return subMenu;
319    }
320
321    var closeMobileNav = function (navButton) {
322        $(navButton).attr('aria-expanded', 'false');
323        $('.ccm-page').removeClass('nav-open');
324
325        // Hide mobile navigation from assistive technologies
326        $('#nav').attr('aria-hidden', 'true').find('li.level-1 a, li.level-1 button').attr('tabindex', '-1').attr('aria-hidden', 'true');
327        $('ul.mega.nav').each(function () {
328            $(this).removeAttr('style');
329            this.scrollTop = 0;
330            this.scrollLeft = 0;
331        })
332    }
333
334
335});

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.