PageSourceSearch

https://piedsdanslesable.fr/wp-content/themes/asona/assets/js/main.js?ver=1.3

js piedsdanslesable.fr collected 2026-10-02 23:03:53 UTC 34,168 bytes, 829 lines download raw bytes

1( function( $ ) {
2    'use strict';
3
4    var $window = $( window ),
5        window_width = Math.max( document.documentElement.clientWidth, window.innerWidth || 0 ),
6        scrollTop = window.pageYOffset || document.documentElement.scrollTop,
7        tempScrollTop = scrollTop,
8        masonry_posts = [],
9        highlight_posts = [],
10        lazy_elements = [],
11        infinite_scroll_elements = [],
12        is_dark_highlight = $( 'body' ).hasClass( 'site-header-dark' ),
13        position_switch_dark = 0,
14        is_loading_more_posts = false,
15
16        rAF = window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || window.msRequestAnimationFrame || function( callback ) { return window.setTimeout( callback, 1000 / 60 ); },
17        user_agent = navigator.userAgent || navigator.vendor || window.opera,
18
19        is_mobile = /(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test( user_agent ) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test( user_agent.substr( 0, 4 ) ),
20        is_object_fit_supported = ( 'objectFit' in document.documentElement.style ),
21        is_ie = /Trident\/|MSIE /.test( user_agent ),
22
23        on_resize = function( callback, timeout ) { onresize = function() { clearTimeout( timeout ); timeout = setTimeout( callback, 10 ) }; return callback };
24
25    if ( is_mobile ) { $( 'html' ).addClass( 'is-mobile' ); }
26    if ( is_ie ) { $( 'html' ).addClass( 'is-ie' ); }
27
28    $( 'html' ).addClass( 'is-using-mouse' );
29
30    // Add class to html when the mouse is being used
31    $( document ).on( 'click', function() {
32        $( 'html' ).addClass( 'is-using-mouse' );
33    });
34
35    // Remove class from html when the keyboard is being used
36    $( document ).on( 'keydown', function() {
37        $( 'html' ).removeClass( 'is-using-mouse' );
38    });
39
40    setTimeout( function() {
41        $( 'html' ).addClass( 'is-animation-ready' );
42    }, 300 );
43
44    var $adebouncedresize = $.event.special.adebouncedresize = {
45        timeout: null,
46        setup: function() {
47            $( this ).on( 'resize', $adebouncedresize.handler );
48        },
49        teardown: function() {
50            $( this ).off( 'resize', $adebouncedresize.handler );
51        },
52        handler: function( event, execAsap ) {
53            // Save the context
54            var context = this,
55                args = arguments,
56                dispatch = function() {
57                    // set correct event type
58                    event.type = 'adebouncedresize';
59                    $.event.dispatch.apply( context, args );
60                };
61
62            if ( $adebouncedresize.timeout ) {
63                clearTimeout( $adebouncedresize.timeout );
64            }
65
66            execAsap ?
67                dispatch() :
68                $adebouncedresize.timeout = setTimeout( dispatch, 50 );
69        },
70    };
71
72    function resize_window() {
73        var temp_width = Math.max( document.documentElement.clientWidth, window.innerWidth || 0 );
74        is_mobile = /(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test( user_agent ) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|
74sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test( user_agent.substr( 0, 4 ) );
75        if ( is_mobile && window_width == temp_width ) {
76            // do nothing, mobile browsers address bar hides and fires resize event
77        } else {
78            window_width = Math.max( document.documentElement.clientWidth, window.innerWidth || 0 );
79            update_masonry();
80            init_highlight_dark();
81            init_highlight_modern();
82            init_lazy_load_media();
83            init_infinite_scroll();
84        }
85    }
86
87    function image_vw() {
88        $( '.window-width, .img-vw' ).remove();
89        $( 'body' ).append( '<span class="window-width">'+ window_width.toFixed(0) + '</span>' );
90
91        $( '.post-media' ).each( function( index, element ) {
92            var $el = $( element );
93            var width = $el.find( '.image-wrapper' ).outerWidth( true );
94            var vw = width / window_width * 100;
95            $el.find( '.image-wrapper' ).append( '<span class="img-vw">'+ width.toFixed(0) + ' - ' + vw.toFixed(2) +'</span>' );
96        });
97    }
98
99    $window.on( 'adebouncedresize orientationchange', function() {
100        rAF( resize_window );
101    } );
102
103    $( window ).on( 'scroll', function() {
104
105        scrollTop = scrollTop = window.pageYOffset || document.documentElement.scrollTop;
106
107        if ( scrollTop > 5 ) {
108            $( '#masthead' ).addClass( 'is-sticky' );
109        } else {
110            $( '#masthead' ).removeClass( 'is-sticky' );
111        }
112
113        if ( is_dark_highlight ) {
114            if ( scrollTop > position_switch_dark ) {
115                $( 'body' ).removeClass( 'site-header-dark' );
116            } else {
117                $( 'body' ).addClass( 'site-header-dark' );
118            }
119        }
120
121        tempScrollTop = scrollTop;
122    });
123
124    $( document ).on( 'click', '.menu-trigger', function( event ) {
125        event.preventDefault();
126
127        var $this = $( this ),
128            $html = $( 'html' ),
129            $header = $( '.site-header' ),
130            $search_trigger = $( '.search-trigger' );
131
132        if ( $this.hasClass( 'is-active' ) ) {
133
134            $this.removeClass( 'is-active' );
135            $header.removeClass( 'is-menu-ready' );
136            $html.removeClass( 'is-scroll-disabled' );
137
138            setTimeout( function() {
139                $header.removeClass( 'is-menu-active' );
140            }, 300 );
141
142        } else {
143
144            $html.addClass( 'is-scroll-disabled' );
145            $this.addClass( 'is-active' );
146            $header.addClass( 'is-menu-active is-menu-ready' ).removeClass( 'is-search-active is-search-ready' );
147            $search_trigger.removeClass( 'is-active' );
148
149        }
150
151    } );
152
153    $( document ).on( 'click', '.search-trigger', function( event ) {
154        event.preventDefault();
155
156        var $this = $( this ),
157            $html = $( 'html' ),
158            $header = $( '.site-header' ),
159            $menu_trigger = $( '.menu-trigger' );
160
161        if ( $this.hasClass( 'is-active' ) ) {
162
163            $header.removeClass( 'is-search-ready' );
164            $html.removeClass( 'is-scroll-disabled' );
165
166            setTimeout( function() {
167                $this.removeClass( 'is-active' );
168                $header.removeClass( 'is-search-active' );
169            }, 50 );
170
171        } else {
172
173            $html.addClass( 'is-scroll-disabled' );
174            $this.addClass( 'is-active' );
175            $header.addClass( 'is-search-active' ).removeClass( 'is-menu-ready' );
176            $menu_trigger.removeClass( 'is-active' );
177
178            setTimeout( function() {
179                $header.addClass( 'is-search-ready' ).removeClass( 'is-menu-active' );
180                $( '.site-search .search-form .search-field' ).focus();
181            }, 250 );
182        }
183
184    } );
185
186    $( document ).on( 'click', '.site-navigation li.menu-item-has-children > a', function( event ) {
187
188        if ( window_width < 980 ) {
189            event.preventDefault();
190
191            var $this = $( this ),
192                $list = $this.closest( 'li' ),
193                $dropdown = $list.find( 'ul:first' ),
194                $parentUl = $list.closest( 'ul' ),
195                subLevel = $list.parents( 'ul' ).length,
196                dropHeight = $dropdown.prop( 'scrollHeight' ),
197                parentUlHeight = $parentUl.prop( 'scrollHeight' );
198
199            if ( $list.hasClass( 'is-active' ) ) {
200
201                if ( 1 < subLevel ) {
202                    $parentUl.get(0).style.setProperty( '--maxHeight', parentUlHeight - dropHeight + 'px' );
203                }
204
205                $list.removeClass( 'is-active' );
206                $dropdown.get(0).style.setProperty( '--maxHeight', '0px' );
207
208            } else {
209
210                if ( 1 < subLevel ) {
211                    $parentUl.get(0).style.setProperty( '--maxHeight', parentUlHeight + dropHeight + 'px' );
212                }
213
214                $list.addClass( 'is-active' );
215                $dropdown.get(0).style.setProperty( '--maxHeight', dropHeight + 'px' );
216            }
217
218        }
219
220    } );
221
222    $( document ).on( 'click', '.site-actions-backdrop', function( event ) {
223        event.preventDefault();
224
225        var $header = $( '.site-header' ),
226            $html = $( 'html' ),
227            $menu_trigger = $( '.menu-trigger' ),
228            $search_trigger = $( '.search-trigger' );
229
230        $html.removeClass( 'is-scroll-disabled' );
231        $header.removeClass( 'is-search-ready is-menu-ready' );
232
233        setTimeout( function() {
234            $header.removeClass( 'is-menu-active is-search-active' );
235            $menu_trigger.removeClass( 'is-active' );
236            $search_trigger.removeClass( 'is-active' );
237        }, 50 );
238
239    } );
240
241    // Featured Tabs
242    $( document ).on( 'click', '.featured-tab', function( event ) {
243        event.preventDefault();
244
245        var $this = $( this ),
246            $tabs = $( '.featured-tab' ),
247            $panel = $( $this.data( 'id' ) ),
248            $panels = $( '.featured-panel' );
249
250        if ( ! $this.hasClass( 'is-active' ) ) {
251
252            $tabs.removeClass( 'is-active' );
253            $this.addClass( 'is-active' );
254            $panels.removeClass( 'is-visible' ).addClass( 'is-animating-out' );
255            $panel.removeClass( 'is-animating-out' );
256
257            setTimeout( function() {
258                $panels.removeClass( 'is-active is-animating-out' );
259                $panel.addClass( 'is-active' );
260                setTimeout( function() {
261                    $panel.addClass( 'is-visible' );
262                }, 50 );
263            }, 200 );
264
265            init_lazy_load_media();
266        }
267    });
268
269    function waitForImages( element, callback ) {
270
271        var matchUrl = /url\(\s*(['"]?)(.*?)\1\s*\)/g;
272        var image = false;
273
274        if ( element.hasAttribute( 'srcset' ) ) {
275            image = {
276                src: element.getAttribute( 'src' ),
277                srcset: element.getAttribute( 'srcset' ),
278                sizes: element.getAttribute( 'sizes' ),
279            };
280        } else if ( element.hasAttribute( 'src' ) ) {
281            image = {
282                src: element.getAttribute( 'src' ),
283            };
284        } else if ( '' !== element.style.backgroundImage ) {
285            var match = matchUrl.exec( element.style.backgroundImage );
286            if ( match ) {
287                image = {
288                    src: match[2],
289                };
290            }
291        }
292
293        if ( image ) {
294            var img = new Image();
295            img.onload = function() {
296                callback( element );
297            }
298            if ( image.srcset ) {
299                img.sizes = image.sizes;
300                img.srcset = image.srcset;
301            }
302            img.src = image.src;
303        }
304    }
305
306    // let's fix image object fit for galleries on browsers that don't support it
307    function fix_ie_image_object_fit() {
308        if ( ! is_object_fit_supported ) {
309            $( '.wp-block-gallery.is-cropped' ).each( function() {
310                var $imgs = $( this ).find( 'img' );
311                $imgs.each( function() {
312                    var $img = $( this );
313                    $img.parents( 'figure' ).addClass( 'is-js-cropped' ).css( 'background-image', 'url(' + $img.attr( 'src' ) + ')' );
314                });
315            });
316        }
317    }
318
319    if ( '1' !== asona_vars.is_lazy_load ) {
320        fix_ie_image_object_fit();
321    }
322
323    function init_highlight_dark() {
324        scrollTop = window.pageYOffset || document.documentElement.scrollTop;
325        var section_highlight = document.querySelector( '.section-highlight' );
326        var single_header_modern = document.querySelector( '.single-posts-type-modern .entry-header' );
327        var single_header_classic = document.querySelector( '.single-posts-type-classic .entry-thumbnail' );
328
329        position_switch_dark = 0;
330
331        if ( section_highlight ) {
332            var rect = section_highlight.getBoundingClientRect();
333            position_switch_dark = scrollTop + rect.bottom - 64;
334        }
335
336        if ( single_header_modern ) {
337            var rect = single_header_modern.getBoundingClientRect();
338            position_switch_dark = scrollTop + rect.bottom - 64;
339        }
340
341        if ( single_header_classic ) {
342            var rect = single_header_classic.getBoundingClientRect();
343            position_switch_dark = scrollTop + rect.bottom - (rect.height / 2) - 64;
344        }
345    }
346
347    init_highlight_dark();
348
349    function init_highlight_modern() {
350
351        scrollTop = window.pageYOffset || document.documentElement.scrollTop;
352        var posts = document.querySelectorAll( '.posts-modern-highlight .post' );
353
354        // empty the set
355        highlight_posts= [];
356
357        for ( var i = 0; i < posts.length; i++ ) {
358            var rect = posts[i].getBoundingClientRect(),
359                content = posts[i].querySelector( '.post-content' ).getBoundingClientRect(),
360                anime = {
361                    'startFadeIn': rect.top + scrollTop - (window.innerHeight * 0.85),
362                    'stopFadeIn': rect.top + scrollTop - (window.innerHeight * 0.4),
363                    'startFadeOut': content.top + scrollTop - 64,
364                    'stopFadeOut': rect.height + rect.top + scrollTop - (rect.height / 8),
365                    'startTranslate': rect.top + scrollTop + (rect.height / 8),
366                    'stopTranslate': rect.top + scrollTop + (rect.height * 3),
367                };
368
369            highlight_posts.push({
370                'element': posts[i],
371                'anime': anime,
372                'height': rect.height,
373            });
374        };
375    }
376
377    init_highlight_modern();
378
379    function min_max( value, min, max ) {
380        return Math.min( max, Math.max(value, min) ).toFixed(2);
381    }
382
383    function highlight_posts_animations() {
384
385        scrollTop = window.pageYOffset || document.documentElement.scrollTop;
386
387        for ( var i = 0; i < highlight_posts.length; i++ ) {
388            var post = highlight_posts[i];
389
390            if ( post.anime.startFadeOut <= scrollTop && post.anime.stopFadeOut >= scrollTop ) {
391                var fadeOutPercentage = 1 - ((scrollTop - post.anime.startFadeOut) / (post.anime.stopFadeOut - post.anime.startFadeOut));
392                post.element.style.opacity = min_max( fadeOutPercentage, 0.1, 1 );
393            }
394
395            if ( post.anime.startFadeOut >= scrollTop && post.anime.startFadeIn <= scrollTop ) {
396                post.element.style.opacity = 1;
397            }
398
399            if ( post.anime.stopFadeOut < scrollTop || post.anime.startFadeIn > scrollTop ) {
400                post.element.style.opacity = 0.1;
401            }
402
403            if ( post.anime.startFadeIn <= scrollTop && post.anime.stopFadeIn >= scrollTop ) {
404                var fadeInPercentage = ((scrollTop - post.anime.startFadeIn) / (post.anime.stopFadeIn - post.anime.startFadeIn));
405                post.element.style.opacity = min_max( fadeInPercentage, 0.1, 1 );
406            }
407
408            if ( post.anime.startTranslate <= scrollTop && post.anime.stopTranslate >= scrollTop && !is_mobile ) {
409                var percentage = ((scrollTop - post.anime.startTranslate) / (post.anime.stopTranslate - post.anime.startTranslate));
410                var translateY = Math.round(percentage * post.height);
411                post.element.style.transform = 'translate3d(0,' + translateY + 'px,0)';
412            }
413
414            if ( post.anime.startTranslate > scrollTop ) {
415                post.element.style.transform = 'translate3d(0,0,0)';
416            }
417        };
418    }
419
420    function inifinity_highlight_loop() {
421        rAF( inifinity_highlight_loop );
422        highlight_posts_animations();
423    }
424
425    rAF( inifinity_highlight_loop );
426
427    function init_lazy_load_media() {
428
429        scrollTop = window.pageYOffset || document.documentElement.scrollTop;
430
431        var lazys = document.querySelectorAll( '.lazy-load-img:not(.is-loaded), .lazy-load-bg-img:not(.is-loaded), .lazy-load-iframe .iframe-placeholder:not(.is-loaded)' ),
432            windowHeight = window.innerHeight,
433            belowFold = windowHeight * 0.2, // 20% below fold
434            offset = windowHeight + belowFold;
435
436        // empty the set
437        lazy_elements = [];
438
439        for ( var i = 0; i < lazys.length; i++ ) {
440            var rect = lazys[i].getBoundingClientRect(),
441                imgOffset = rect.top + scrollTop - offset,
442                imgOffset = Math.max( 0, imgOffset );
443
444            lazy_elements.push({
445                'offset': imgOffset.toFixed(),
446                'element': lazys[i],
447                'type': lazys[i].tagName
448            });
449        };
450    }
451
452    // let's wait a bit for the above the fold script to collect items
453    setTimeout( function() {
454        init_lazy_load_media();
455    }, 50 );
456
457    function lazy_load_media() {
458
459        for ( var i = 0; i < lazy_elements.length; i++ ) {
460            var lazy = lazy_elements[i];
461
462            if ( lazy.offset <= scrollTop ) {
463
464                if ( 'IMG' === lazy.type ) {
465
466                    var image = lazy.element,
467                        src = image.getAttribute( 'data-src' );
468
469                    image.classList.add( 'is-loaded' );
470
471                    if ( image.hasAttribute( 'data-srcset' ) ) {
472                        var sizes = image.getAttribute( 'data-sizes' ),
473                        srcset = image.getAttribute( 'data-srcset' );
474                        image.setAttribute( 'sizes', sizes );
475                        image.setAttribute( 'srcset', srcset );
476                    }
477
478                    image.setAttribute( 'src', src );
479                    lazy_elements.splice( i, 1 );
480
481                    waitForImages( image, function( element ) {
482                        element.classList.add( 'is-ready' );
483
484                        if ( ! is_object_fit_supported ) {
485                            var $el = $( element ),
486                                el_src = element.getAttribute( 'src' ),
487                                $gallery_cropped = $el.parents( '.wp-block-gallery.is-cropped' );
488
489                            if ( $gallery_cropped.length ) {
490                                $el.parents( 'figure' ).addClass( 'is-js-cropped' ).css( 'background-image', 'url(' + el_src + ')' );
491                            }
492                        }
493                    } );
494
495                } else if ( 'I' === lazy.type ) {
496
497                    var placeholder = lazy.element,
498                        wrapper = placeholder.parentNode,
499                        src = placeholder.getAttribute( 'data-src' ),
500                        iframe = document.createElement( 'iframe' );
501
502                    wrapper.insertBefore( iframe, placeholder );
503                    wrapper.removeChild( placeholder );
504                    iframe.classList.add( 'is-loaded' );
505                    iframe.setAttribute( 'src', src );
506                    iframe.setAttribute( 'allowfullscreen', '' );
507                    lazy_elements.splice( i, 1 );
508
509                } else {
510
511                    var image = lazy.element,
512                        src = image.getAttribute( 'data-src' );
513
514                    image.classList.add( 'is-loaded' );
515                    image.style.backgroundImage = 'url(' + src + ')';
516
517                    waitForImages( image, function( element ) {
518                        element.classList.add( 'is-ready' );
519                    } );
520                    lazy_elements.splice( i, 1 );
521                }
522            }
523        };
524    }
525
526    function init_photoswipe( selector, type ) {
527
528        $( selector ).on( 'click' , 'a', function( event ) {
529
530            var $this = $( this ),
531                link_url = $this.attr( 'href' );
532
533            // if link to image
534            if ( /\.(?:jpg|jpeg|gif|png)$/i.test( link_url ) ) {
535                event.preventDefault();
536
537                if ( 'gallery' === type ) {
538                    var $gallery = $this.parents( selector ),
539                        $figures = $gallery.find( 'figure' ),
540                        $list = $this.parents( 'li' ),
541                        index = $list.index(),
542                        items = get_items( $figures );
543
544                    open_photoswipe( index, items );
545
546                } else {
547                    var $figures = $this.parents( 'figure' ),
548                        items = get_items( $figures );
549
550                    open_photoswipe( 0, items );
551                }
552            }
553        });
554
555        var open_photoswipe = function( index, items ) {
556
557            var pswp = $( '.pswp' )[ 0 ];
558            var options = {
559                index: parseInt( index, 10 ),
560                shareEl: false,
561                fullscreenEl: false,
562                bgOpacity: 0.95,
563                showHideOpacity: true,
564                history: false,
565                loadingIndicatorDelay: 10,
566                timeToIdle: 0,
567                timeToIdleOutside: 0,
568                clickToCloseNonZoomable: true,
569                getThumbBoundsFn: function( index ) {
570                    var img = items[ index ].el[ 0 ].getElementsByTagName( 'img' )[ 0 ],
571                        pageYScroll = $( window ).scrollTop(),
572                        rect = img.getBoundingClientRect();
573
574                    return { x: rect.left, y: rect.top + pageYScroll, w: rect.width };
575                }
576            };
577
578            // exit if index not found
579            if ( isNaN( options.index ) ) {
580                return;
581            }
582
583            var ps = new PhotoSwipe( pswp, PhotoSwipeUI_Default, items, options );
584            ps.init();
585        }
586
587        var get_items = function( figures ) {
588            var items = [];
589
590            figures.each( function( index, element ) {
591                var $figure = $( element ),
592                    $link = $figure.find( 'a:first-child' ),
593                    $img = $figure.find( 'img' ),
594                    $caption = $figure.find( 'figcaption' ),
595                    size = $img.attr( 'data-full-size' ).split( 'x' ),
596                    src = $img.data( 'full' ) ? $img.data( 'full' ) : $link.attr( 'href' );
597
598                var item = {
599                    el: $figure,
600                    src: src,
601                    msrc: $img.attr( 'src' ),
602                    srcset: $img.attr( 'srcset' ),
603                    w: parseInt( size[ 0 ], 10 ),
604                    h: parseInt( size[ 1 ], 10 ),
605                };
606
607                if ( $caption.length ) {
608                    item.title = $caption.html();
609                }
610
611                items.push( item );
612            } );
613
614            return items;
615        }
616    }
617
618    init_photoswipe( '.wp-block-image', 'single' );
619    init_photoswipe( '.wp-block-gallery', 'gallery' );
620
621    function init_masonry_posts() {
622        var $container = $( '.is-posts-masonry .posts-block-main .row' );
623        masonry_posts = $container.find( '.post' );
624
625        update_masonry();
626        $container.addClass( 'is-ready' );
627    }
628
629    init_masonry_posts();
630
631    function get_masonry_columns() {
632        var columns = '';
633
634        $.each( asona_vars.posts_columns, function( width, col ) {
635            if ( width <= window_width ) {
636                columns = parseInt( col );
637            } else if ( '' == columns ) {
638                columns = 1;
639            }
640        });
641
642        return columns;
643    }
644
645    function update_masonry() {
646        var $container = $( '.is-posts-masonry .posts-block-main .row' ),
647            columns = get_masonry_columns();
648
649        $container.empty();
650
651        for ( var i = 0; i < columns; i++ ) {
652            $container.append( $( '<div class="post-column column"></div>' ) );
653        }
654
655        add_masonry_posts($container, masonry_posts)
656    }
657
658    function add_masonry_posts( $container, $posts ) {
659        var columns = get_masonry_columns(),
660            columns_height = [];
661
662        for ( var i = 0; i < $posts.length; i++ ) {
663            for ( var j = 0; j < columns; j++ ) {
664                columns_height[j] = $container.find( '.post-column:eq( '+ j +' )' ).outerHeight();
665            }
666
667            var min_height = columns_height.reduce( function (min, height) {
668                return height < min - 100 ? height : min;
669            });
670
671            var column = columns_height.indexOf( min_height );
672
673            $container.find( '.post-column:eq( '+ column +' )' ).append( $( $posts[i] ) );
674        }
675    }
676
677    function ajax_load_more_posts( element, is_infinite_scroll ) {
678        var $loader = $( element ),
679            $nav = $loader.parent(),
680            $container = $loader.closest( '.posts-block' ).find( '.row' ),
681            found_posts = parseInt( $loader.data( 'found-posts' ), 10 ),
682            post_count = parseInt( $loader.data( 'post-count' ), 10 ),
683            query = $loader.data( 'query' ),
684            options = $loader.data( 'options' ),
685            posts_per_page = parseInt( query.posts_per_page, 10 ),
686            offset = parseInt( query.offset, 10 );
687
688        if ( post_count >= found_posts ) {
689            return false;
690        }
691
692        if ( is_loading_more_posts ) {
693            return false;
694        }
695
696        $loader.addClass( 'is-ready is-loading' );
697        is_loading_more_posts = true;
698
699        $.ajax( {
700            type: 'POST',
701            url: asona_vars.ajax_url.toString().replace( '%%action%%', 'load-more-posts' ),
702            data: {
703                query: query,
704                options: options
705            },
706            success: function( response ) {
707
708                if ( response.status === 'success' ) {
709
710                    var $new_items = $( response.html ).filter('.post'),
711                        new_post_count = parseInt( response.post_count, 10 ) + post_count,
712                        new_offset = offset + posts_per_page;
713
714                    $loader.data( 'post-count', new_post_count );
715                    $loader.data( 'query', $.extend( query, { offset: new_offset } ) );
716
717                    $loader.removeClass( 'is-loading' );
718                    $container.append( $new_items );
719
720                    if ( asona_vars.is_posts_masonry ) {
721                        masonry_posts = $.merge( $.merge( [], masonry_posts ), $new_items );
722                        add_masonry_posts( $container, $new_items );
723                    } else {
724                        $container.append( $new_items );
725                    }
726
727                    setTimeout( function() {
728                        $loader.removeClass( 'is-ready' );
729                    }, 300 );
730
731                    init_lazy_load_media();
732
733                    // Are there more items to load?
734                    if ( new_post_count < found_posts ) {
735                        if ( is_infinite_scroll ) {
736                            init_infinite_scroll();
737                        }
738                    } else {
739                        $nav.remove();
740                    }
741
742                } else if ( response.status === 'empty' ) {
743                    $nav.remove();
744                } else if ( response.status === 'error' ) {
745                    $loader.addClass( 'is-error' ).removeClass( 'is-ready is-loading' );
746                    $loader.find( '.loader-error-text' ).attr( 'aria-hidden', 'false' );
747                }
748
749                is_loading_more_posts = false;
750            },
751            error: function() {
752                $loader.addClass( 'is-error' ).removeClass( 'is-ready is-loading' );
753                $loader.find( '.loader-error-text' ).attr( 'aria-hidden', 'false' );
754                is_loading_more_posts = false;
755            }
756        });
757    }
758
759    function init_infinite_scroll() {
760
761        scrollTop = window.pageYOffset || document.documentElement.scrollTop;
762
763        var iscrolls = document.querySelectorAll( '.pagination-infinite-scroll' ),
764            windowHeight = window.innerHeight,
765            belowFold = windowHeight * 0.35, // 35% below fold
766            offset = windowHeight + belowFold;
767
768        // empty the set
769        infinite_scroll_elements = [];
770
771        for ( var i = 0; i < iscrolls.length; i++ ) {
772            var rect = iscrolls[i].getBoundingClientRect(),
773                offset = rect.top + scrollTop - offset,
774                offset = Math.max( 0, offset );
775
776            infinite_scroll_elements.push({
777                'offset': offset.toFixed(),
778                'element': iscrolls[i],
779            });
780        };
781    }
782
783    init_infinite_scroll();
784
785    function infinite_scroll() {
786
787        for ( var i = 0; i < infinite_scroll_elements.length; i++ ) {
788            var iscroll = infinite_scroll_elements[i];
789
790            if ( iscroll.offset <= scrollTop ) {
791                ajax_load_more_posts( iscroll.element, true );
792                infinite_scroll_elements.splice( i, 1 );
793            }
794        }
795    }
796
797    $( '.pagination-load-more' ).on( 'click', function( event ) {
798        event.preventDefault();
799        ajax_load_more_posts( this, false );
800    });
801
802    var inifinity_loop_timeout;
803    function inifinity_loop() {
804        scrollTop = window.pageYOffset || document.documentElement.scrollTop;
805
806        lazy_load_media();
807        infinite_scroll();
808
809        clearTimeout( inifinity_loop_timeout );
810        inifinity_loop_timeout = setTimeout( function() {
811            rAF( inifinity_loop );
812        }, 400 );
813    }
814
815    rAF( inifinity_loop );
816
817    window.addEventListener( 'load', function() {
818        // le't get the new values if something has pushed the content down
819        init_highlight_dark();
820        init_highlight_modern();
821        init_lazy_load_media();
822        init_infinite_scroll();
823    });
824
825    $( document.body ).on( 'ap_popular_posts_fragments_refreshed', function() {
826        init_lazy_load_media();
827    } );
828
829} )( jQuery );

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.