PageSourceSearch

https://www.um.si/wp-content/themes/um_si/assets/js/accessibility.js?x17571&ver=6.9.0

js um.si collected 2026-09-24 08:44:50 UTC 9,983 bytes, 278 lines download raw bytes

1$(function() {
2
3    let $header = $('.header'), $body = $('body');
4
5    // Dropdown menu
6    $('.dropdown__trigger > button[aria-expanded]').on('click', function(e){
7        e.preventDefault();        
8        let $el = $(this), $parent = $el.closest('.dropdown'), is_dense = $parent.hasClass('dropdown--hmiDesktop'), $container = $el.closest('.dropdownWrapper'), $menu = $parent.find('.dropdown__content'), is_visible = $el.attr('aria-expanded') === 'true';
9
10        //if(!is_visible) close_dropdown();
11
12        $parent.toggleClass('dropdown--active');
13        $container.toggleClass('dropdown--active-parent');
14
15        if(is_dense) {
16            let $el_child = $el.closest('.dropdown').find('.dropdown__content .dropdown__trigger button[aria-expanded]');
17            $el_child.focus();
18            toggle_aria_expanded($el_child, !is_visible);
19        }
20
21        toggle_aria_expanded($el, !is_visible);
22    });
23
24    // Main nav
25    $('.mainNav > ul > li > button[aria-expanded]').on('click', function(e){
26        e.preventDefault();
27
28        let $el = $(this), $menu = $el.parent().find('.mainNav__subMenu'), is_visible = $el.attr('aria-expanded') === 'true';
29        
30        if(!is_visible) close_mega_menus();
31
32        toggle_aria_expanded($el, !is_visible);
33        toggle_aria_hidden($menu, is_visible);
34    });
35
36    // Mobile nav
37    $('.navToggle').on('click', function(e){
38        e.preventDefault();
39
40        let $el = $(this);
41        
42        toggle_aria_expanded($el, !$header.hasClass('header--navVisible'));
43
44        $header.toggleClass('header--navVisible');
45        $body.toggleClass('overflow--hidden');
46    });
47
48    // Subpage nav
49    $('.cNav button[aria-expanded], .sideNav button[aria-expanded]').on('click', function(e){
50        e.preventDefault();
51
52        let $el = $(this), $menu = $el.parent().find('> ul.children'), is_visible = $el.attr('aria-expanded') === 'true';
53
54        //close_ribbon_nav();
55
56        toggle_aria_expanded($el, !is_visible);
57        toggle_aria_hidden($menu, is_visible);
58    });
59
60    // Sogo toggle
61    let $accessibility_btn = $('#open_sogoacc'), $accessibility_container = $('#sogoacc');
62    if ($accessibility_btn.length && $accessibility_container.length) {
63        $('.triggerAccessibilityControls').on('click', function(e) {
64            e.preventDefault();
65            $accessibility_btn.trigger('click');
66        });
67    }
68
69    // Skip to content
70    $('.skip-to-content-btn').on('click', function(e) {
71        e.preventDefault();
72        get_first_focusable_element($('main'), '.section--banner, .section--banner *').focus();
73    });     
74
75    // Skip segment
76    $('.skip-section-btn').on('click', function(e) {
77        e.preventDefault();
78        let $parent = $(this).closest('section');
79        get_first_focusable_element($parent.nextAll()).focus();
80    });        
81
82    // Search
83    $('.searchToggle').on('click keydown', function(e){        
84        
85        if (e.type === 'keydown' && e.keyCode === 9) return;
86        e.preventDefault();
87        if (e.type === 'keydown' && (e.keyCode !== 32 && e.keyCode !== 13)) return;
88
89        let $el = $(this), $container = $('.header__search'), is_visible = $el.attr('aria-expanded') === 'true';
90
91        $('.header').toggleClass('header--searchVisible');
92
93        if(!is_visible) {
94            $el.addClass('is-clicked');
95            $container.find('input:not(:checked):first').focus();
96            setTimeout(() => { $el.removeClass('is-clicked') },50)
97        }
98        
99        toggle_aria_expanded($el, !is_visible);
100        toggle_aria_hidden($container, is_visible);
101    });
102
103    // TAB / TRAP FOCUS
104    $(document).on('focusout', '.dropdown__content', function(e) {
105        let $el = $(this);
106        if (!$el.is(':focus-within')) $el.find('.dropdown__trigger > button[aria-expanded]').focus();
107        setTimeout(() => { if (!$('.dropdown').has(document.activeElement).length) $('.dropdown--active .dropdown__trigger .button').focus() }, 0); 
108    });
109
110    $(document).on('focusout', '.mainNav__subMenu', function(e) {
111        if (!$(this).is(':focus-within')) $(this).parent().find('button[aria-expanded]').focus();
112    });
113
114    $(document).on('focusout', '.searchToggle:not(.is-clicked)', function(e) {
115        console.log(e);
116        if (!$(this).is(':focus-within') && $('.header--searchVisible').length) $('.header__search').find('input:not(:checked):first').focus();
117    });
118
119    $(document).on('focusout', '.header__search', function(e) {
120        if (!$(this).is(':focus-within')) $('.searchToggle').focus();
121    });
122
123    $(document).on('focusout', '#sogoacc', function(e) {
124        if (!$(this).is(':focus-within')) $('#sogoacc').hide();
125    }); 
126    
127    $(document).on('focusout', '.header__mobileNav', function(e) {
128        if (!$(this).is(':focus-within')) $('.navToggle').focus();
129    });      
130    
131    $(document).on('focusout', '.popup', function(e) {
132        if (!$(this).is(':focus-within')) get_first_focusable_element($(this)).focus();
133    });
134
135    $(document).on('focusout', '.cDiagramPopup.is-visible', function(e) {
136        if (!$(this).is(':focus-within')) get_first_focusable_element($(this)).focus();
137    });    
138
139    $(document).on('focusout', '.cNav', function(e) {
140        if (!$(this).is(':focus-within')) close_ribbon_nav();
141    });      
142  
143    $(document).on('keydown', '.search-form', function (e) {
144        if (e.keyCode === 13 && !$(e.target).is("input[type='search'], button")) {
145            e.preventDefault();
146        }
147    });    
148
149    // Slider focus
150    let $slider_active_thumb_focus = null;
151
152    $('.cSlider').on('focusout', function() {
153        if (!$(this).is(':focus-within')) $slider_active_thumb_focus = null;
154    });
155
156    $(document).on('focusin', '.ctB ', function() {
157        $(this).data('isFocused', true);
158    }).on('focusout', '.ctB ', function() {
159        $(this).removeClass('focused-click').removeData('isFocused');
160    }).on('click', '.ctB ', function() {
161        if ($(this).data('isFocused')) {
162            $(this).addClass('focused-click');
163        }
164    });
165    
166    $(document).on('focusout', '.ctB.focused-click', function(e) {
167        let $el = $(this);
168        if (!$el.is(':focus-within')) {
169            let $parent = $el.closest('.cSlider');
170            $parent.find('.owl-item.active a:first').focus();
171            $slider_active_thumb_focus = $el;
172        }
173    })
174
175    $(document).on('focusout', '.cSlider .buttonContainer', function(e) {
176        let $el = $(this), $parent = $el.closest('.cSlider');
177
178        if(!$slider_active_thumb_focus) return;
179
180        if (!$el.is(':focus-within')) {     
181            if($slider_active_thumb_focus && $slider_active_thumb_focus.length) {                
182                if($slider_active_thumb_focus.next().length) {
183                    $slider_active_thumb_focus.next().focus();                    
184                }
185                else {
186                     if(!$el.closest('section').nextAll().length) $('.footer').find('a:first').focus();
187                    else $el.closest('section').nextAll().find('a, button, input, select, textarea, [tabindex]:not([tabindex="-1"])').filter(':visible').not('[tabindex="-1"]').first().focus();
188                    $parent.trigger('focusout');
189                }
190            }
191            else {
192                if($parent.find('.ctB.is--active').length && !$parent.find('.ctB.is--active').is(':last-child')) $parent.find('.ctB.is--active').next().focus();
193            }
194            $slider_active_thumb_focus = null;
195        }
196    });
197
198    // ON OUTSIDE CLICK
199    $(document).on('click', function (e) {
200        let $target = $(e.target);
201
202        if (!$target.closest('.mainNav').length) close_mega_menus();
203        if (!$target.closest('.dropdown').length) close_dropdown();
204        if (!$target.closest('.cNav').length) close_ribbon_nav();
205        if (!$target.closest('.header__search, .searchToggle').length) close_search();
206    });
207
208    // ON ESC
209    $(document).on('keydown', function(event) {
210        if (event.key === "Escape" || event.keyCode === 27) {
211            $('#popupContainer').html('');
212            close_ribbon_nav();
213            close_dropdown();
214            close_mega_menus();
215            close_search();
216            cDiagramClosePopup();
217        }
218    });
219    
220
221});
222
223function close_search() {
224    toggle_aria_expanded($('.searchToggle'), false);
225    toggle_aria_hidden($('.header__search'), true);
226    $('.header').removeClass('header--searchVisible');
227}
228
229function close_ribbon_nav() {
230    $('.cNav button[aria-expanded="true"]').attr('aria-expanded', 'false');
231    $('.cNav ul[aria-hidden="false"]').attr('aria-hidden', 'true');
232}
233
234function close_dropdown() {
235    toggle_aria_expanded($('.dropdown__trigger .button[aria-expanded]'), false);
236    $('.dropdown--active').removeClass('dropdown--active');
237    $('.dropdown--active-parent').removeClass('dropdown--active-parent');
238}
239
240function close_mega_menus() {
241    toggle_aria_expanded($('.mainNav > ul > li > button[aria-expanded]'), false);
242    toggle_aria_hidden($('.mainNav__subMenu'), true);
243}
244
245function toggle_aria_expanded(trigger, is_expanded) {
246    $(trigger).attr('aria-expanded', is_expanded ? 'true' : 'false');
247}
248
249function toggle_aria_hidden(trigger, is_expanded) {
250    $(trigger).attr('aria-hidden', is_expanded ? 'true' : 'false');
251}
252
253function get_first_focusable_element($container, exclude_selector) {
254    if (!$container) return;
255
256    let $element = $container
257        .find('a, button, input, select, textarea, [tabindex]:not([tabindex="-1"])')
258        .filter(':visible')
259        .not('[tabindex="-1"]')
260        .not(':disabled');
261
262    if (exclude_selector) {
263        $element = $element.not(exclude_selector);
264    }
265
266    return $element.first();
267}
268
269/*
270function getFocusedElement() {
271    var focusedElement = $(document.activeElement);
272    focusedElement.addClass('is-focused');
273    console.log('Currently focused element:', focusedElement);
274}
275$(document).on('focusin', function() {
276    getFocusedElement();
277});
278*/

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.