PageSourceSearch

https://valtioneuvosto.fi/o/yja-valtioneuvosto-theme/js/main.js?br…=other&languageId=fi_FI&t=1790004294000

js valtioneuvosto.fi collected 2026-09-24 08:39:37 UTC 10,457 bytes, 246 lines download raw bytes

1AUI().ready(
2    /*
3    This function gets loaded when all the HTML, not including the portlets, is
4    loaded.
5    */
6
7    function () {
8    }
9);
10
11Liferay.Portlet.ready(
12
13    /*
14    This function gets loaded after each and every portlet on the page.
15
16    portletId: the current portlet's id
17    node: the Alloy Node object of the current portlet
18    */
19
20    function (portletId, node) {
21    }
22);
23
24Liferay.on(
25    'allPortletsReady',
26
27    /*
28    This function gets loaded when everything, including the portlets, is on
29    the page.
30    */
31
32    function() {
33        // prevent scripts from running in iframes
34        if(window.self === window.top) {
35            // general keyboard controllers
36            document.body.addEventListener('keydown', function (event) {
37                switch (event.key) {
38                case 'Escape':
39                    if(mobileNavigationActive === true) {
40                        toggleMobileNavigation();
41                    }
42                    break;
43                default:
44                    break;
45                }
46            });
47
48            document.body.addEventListener('pointerup', function (event) {
49                // some window width checks here, if one drags the vertical scrollbar on this width
50                if(mobileNavigationActive === true && window.innerWidth > 399.98 && window.innerWidth < 1280.02 && event.clientX > 359.98 && event.clientX < (window.innerWidth - 20)) {
51                    toggleMobileNavigation();
52                }
53            });
54
55            // mobile navigation buttons
56            let heading = document.getElementById('banner');
57            let mobileNavButtons = heading.querySelectorAll('button.heading-mobile-menu');
58
59            mobileNavButtons.forEach((element) => {
60                element.addEventListener('click', function(e) {
61                    e.preventDefault();
62                    toggleMobileNavigation();
63                }, false);
64            });
65
66            /* 
67            * NAVIGATION ACCORDIONS
68            * partial copy and modification of site-template-theme app.js
69            */
70            var toggleButtonOpenSrElem = '';
71            var toggleButtonCloseSrElem = '';
72            var pageName = '';
73            var activeSelector = {
74                mobile: jQuery('#site-mobile-navigation > ul .selected'),
75                desktop: jQuery('.portlet-navigation .list-menu .layouts .selected')
76            };
77            var activePagePresent = true;
78
79            // if theres no current page
80            if(jQuery('#site-mobile-navigation > ul .selected').length == 0 && jQuery('.portlet-navigation .list-menu .layouts [aria-current="page"]').length == 0) {
81                activeSelector = {
82                    mobile: jQuery('#site-mobile-navigation > ul [aria-current="true"]'),
83                    desktop: jQuery('.portlet-navigation .list-menu .layouts [aria-current="true"]')
84                };
85                activePagePresent = false;
86            }
87
88            // mobile
89            activeSelector.mobile.parents('li').addClass('selected');
90
91            // desktop
92            jQuery('.portlet-navigation .list-menu .layouts > li').has('ul').addClass('hasChild') // Top level elements
93                .find('li').has('ul').addClass('hasChild'); // Sub level elements
94            activeSelector.desktop.parents('li').addClass('selected');
95
96            // if active page is not present, set selected class to last known instance
97            if(activePagePresent === false) {
98                activeSelector.mobile.last().addClass('selected');
99                activeSelector.desktop.last().addClass('selected');
100            }
101
102            jQuery('.hasChild > a').each(function () {
103                jQuery(this).wrap('<span class="buttonWrapper"></span>');
104                pageName = jQuery(this).text();
105                toggleButtonOpenSrElem = '<span class="sr-only">' + 'Avaa\x20alavalikko' + ', ' + pageName + '</span>';
106                toggleButtonCloseSrElem = '<span class="sr-only">' + 'Sulje\x20alavalikko' + ', ' + pageName + '</span>';
107                if (jQuery(this).parent().parent().hasClass('selected')) {
108                    jQuery(this).after('<button aria-expanded="true" class="toggleVisibility icon-chevron-down">' + toggleButtonCloseSrElem + '</button>');
109                } else {
110                    jQuery(this).after('<button aria-expanded="false" class="toggleVisibility icon-chevron-right">' + toggleButtonOpenSrElem + '</button>');
111                }
112            });
113
114            jQuery('button.toggleVisibility').click(function () {
115                var elem = jQuery(this);
116
117                pageName = jQuery(this).prev('a').text();
118                toggleButtonOpenSrElem = '<span class="sr-only">' + 'Avaa\x20alavalikko' + ', ' + pageName + '</span>';
119                toggleButtonCloseSrElem = '<span class="sr-only">' + 'Sulje\x20alavalikko' + ', ' + pageName + '</span>';
120
121                jQuery(elem.parent().next('ul')).slideToggle('fast');
122
123                if (elem.hasClass('icon-chevron-right')) {
124                    elem.removeClass('icon-chevron-right');
125                    elem.addClass('icon-chevron-down');
126                    elem.attr('aria-expanded', 'true');
127                    elem.html(toggleButtonCloseSrElem);
128                } else {
129                    elem.removeClass('icon-chevron-down');
130                    elem.addClass('icon-chevron-right');
131                    elem.attr('aria-expanded', 'false');
132                    elem.html(toggleButtonOpenSrElem);
133                }
134
135                elem.parent().parent().addClass('skipme');
136                elem.parent().parent().siblings().each(function() {
137                    $(this).not('.skipme').has('button.toggleVisibility[aria-expanded="true"]').find('button.toggleVisibility[aria-expanded="true"]').eq(0).click();
138                });
139                elem.parent().parent().removeClass('skipme');
140            });
141
142            setTimeout(() => {
143                jQuery('.portlet-navigation .list-menu li').removeAttr('aria-current');
144                jQuery('.portlet-navigation .list-menu li.selected a.selected.active').attr('aria-current', 'page');
145            }, 500);
146        }
147    }
148);
149
150(function ($) {
151    $(function () {
152        var laptop = window.matchMedia("(min-width: 1024px)");
153
154        if (laptop.matches) {
155
156            // Add arrow navigation to YJA Content Carousel
157            var carousel = $('.carousel');
158            var page_width = $('.carousel').width();
159            var firstItem = jQuery('.carousel-wrapper ul li:first');
160            var extraWidth = parseInt(firstItem.css('paddingRight')) * 2;
161            var dataNum = 0;
162            page_width = page_width + extraWidth;
163
164            // Check if Carousel Content is loaded
165            if (carousel.length > 0) {
166                var totalSlides = Math.ceil($('.carousel-wrapper ul').children('li').length / 5);
167
168                if (totalSlides > 1) {
169                    carousel.append('<div class="controller--arrows"><a href="#" data-page="0" class="js-control-prev"></a><a href="#" data-page="1" class="js-control-next"></a></div>');
170
171                    // Remove default actions from links
172                    $('.controller--arrows a').click(function (e) {
173                        e.preventDefault();
174
175                        // Move selected marker on default pagination depending on click
176                        if ($(this).hasClass('js-control-next')) {
177                            if (!$('.position-nav').children('li:last-child').hasClass('selected')) {
178                                $('.position-nav').children('li.selected').removeClass('selected').next('li').addClass('selected');
179                                dataNum++;
180                                moveToPage(dataNum);
181                            }
182                        } else {
183                            if (!$('.position-nav li:first-child').hasClass('selected')) {
184                                $('.position-nav').children('li.selected').removeClass('selected').prev('li').addClass('selected');
185                                dataNum--;
186                                moveToPage(dataNum);
187                            }
188                        }
189                    });
190                }
191            }
192
193            function moveToPage(page_num) {
194                $('.carousel-wrapper ul').animate({
195                    left: -1 * page_num * page_width
196                }, 600, function () { }
197                );
198            }
199
200            /**
201             * http://stackoverflow.com/questions/3971841/how-to-resize-images-proportionally-keeping-the-aspect-ratio
202             * Conserve aspect ratio of the orignal region. Useful when shrinking/enlarging
203             * images to fit into a certain area.
204             *
205             * @param {Number} srcWidth Source area width
206             * @param {Number} srcHeight Source area height
207             * @param {Number} maxWidth Fittable area maximum available width
208             * @param {Number} maxHeight Fittable area maximum available height
209             * @return {Object} { width, heigth }
210             */
211            function calculateAspectRatioFit(srcWidth, srcHeight, maxWidth, maxHeight) {
212                var ratio = Math.min(maxWidth / srcWidth, maxHeight / srcHeight);
213                return { width: srcWidth * ratio, height: srcHeight * ratio };
214            }
215        }
216    });
217})(jQuery);
218
219// mobile navigation status
220let mobileNavigationActive = false;
221
222// mobile navigation status
223function toggleMobileNavigation() {
224    const documentBody = document.querySelector('body');
225    const heading = document.getElementById('banner');
226    const buttons = heading.querySelectorAll('button.heading-mobile-menu');
227    const mobileNav = document.getElementById('site-mobile-menu');
228
229    if (buttons[0].classList.contains('open')) {
230        mobileNav.classList.remove('expanded');
231        buttons.forEach((element) => {
232            element.ariaExpanded = false;
233            element.classList.remove('open');
234        });
235        documentBody.removeAttribute('style');
236        mobileNavigationActive = false;
237    } else {
238        mobileNav.classList.add('expanded');
239        buttons.forEach((element) => {
240            element.ariaExpanded = true;
241            element.classList.add('open');
242        });
243        documentBody.style.overflow = 'hidden';
244        mobileNavigationActive = true;
245    }
246}

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.