PageSourceSearch

https://galleryclimatecoalition.org/lib/jquery/plugins/pageload/1.…=989b809&g=df5dbdf2f50b73e7c4e699672d5f0660

js galleryclimatecoalition.org collected 2026-09-24 10:52:08 UTC 106,179 bytes, 1,873 lines download raw bytes

1/**
2 * jQuery PageLoad by Artlogic
3 *
4 * Copyright 2018, Artlogic Media Ltd, http://www.artlogic.net/
5 */
6
7
8(function($) {
9
10    $.pageload = function(user_options) {
11        // Options setup
12
13        var options = {
14            'splash_screen_enabled': false,
15            'splash_screen_always_enabled': false,
16            'splash_screen_cookie_expiry': 900,
17            'splash_screen_click_to_close': false,
18            'popup_content_enabled': false,
19            'popup_content_force_open': false, // Force popup content to open in fallback mode - when you arrive directly on a page with content ordinarily opened in a popup
20            'popup_content_update_url': true,
21            'ajax_navigation_enabled': true,
22            'disable_ajax_param': true, // Removes ajax post parameter from each page load, improves server performance enabling cached pages
23            'development_mode': false,
24            'development_mode_pause_splash_screen': false,
25            'development_mode_show_splash_screen_on_refresh': false,
26            'loader_orientation': 'width',
27            'verbose': false,
28            'content_area_selector': '#container_inner',
29            'content_load_adjacent': false,
30            'preloader_additional_html': '',
31            'body_classes_to_retain_defaults': 'browser-js-enabled, first-load-complete, ajax-loading, page-transition-active, loader-active, overlay-visible, overlay-active, loader-incoming-type-standard, show-image-alt-tags, core-accessibility-stylesheet-checked, tabbing-listener-added, clicking-detected, website-editor-mode',
32            'body_classes_to_retain': '',
33            'url_params_to_retain_defaults': ['_cms-website-editor=1'],
34            'url_params_to_retain': [],
35            'splash_screen_primary_preload_images_selector': '#loader_logo', // Previously splash_logo_selector
36            'splash_screen_secondary_preload_images_selector': '#preloader', // Previously splash_background_selector
37            'splash_screen_delay_after_complete': 200,
38            'splash_screen_auto_delays_enabled': true,
39            'page_transition_delay': 600,
40            'preload_images_selector': '',
41            'popstate_custom_functions': {},
42            'page_scroll_history': false,
43            'destroy_after_load': function() {},
44            'init_after_load': function() {
45                if(window.galleries) {
46                    window.galleries.init();
47                }
48                if(window.theme) {
49                    window.theme.init();
50                }
51                if(window.cart) {
52                    window.cart.init();
53                }
54                if (window.archimedes && typeof window.archimedes != 'undefined') {
55                    window.archimedes.archimedes_core.init();
56                }
57                if(window.feature_panels) {
58                    window.feature_panels.init();
59                }
60                if (window.modules && typeof window.modules != 'undefined') {
61                    window.modules.init_all();
62                }
63                if(window.site) {
64                    window.site.init();
65                }
66                try {
67                    h.accessibility.init();
68                } catch (error) {
69                    console.log(error);
70                }
71                try {
72                    h.accessibility.role_button();
73                } catch (error) {
74                    console.log(error);
75                }
76            },
77            'before_load': function() {
78                if ($('body').hasClass('navigation-open')) {
79                    $('body').removeClass('navigation-open');
80                    $('#top_nav_section').fadeOut(500);
81                    $('#top_nav_section_reveal').removeClass('open');
82                    $('#top_nav_section li').removeClass('show');
83                }
84            },
85            'on_page_transition': function() {},
86            'after_load_complete': function() {},
87            'preloader_in': function() {},
88            'splash_screen_in': function() {},
89            'splash_screen_out': function() {},
90            'popup_before': function() {},
91            'popup_after': function() {},
92            'popup_after_close': function() {},
93            'page_transition_start': function() {},
94            'page_transition_end': function() {}
95        };
96        $.extend(options, user_options);
97        $.pageload.options = options;
98
99
100        // Setup aliases
101
102        $.pageload.load = function(element_href, pushstate, callback, navigation_type, element, page_scroll_top_value, incoming_content_type, inner_content_selector, post_data) {
103            $.pageload.fn.pages.load(element_href, pushstate, callback, navigation_type, element, page_scroll_top_value, incoming_content_type, inner_content_selector, post_data);
104        }
105
106        $.pageload.refresh = function(element_context) {
107            $.pageload.fn.pages.add_click_events(element_context);
108        }
109
110        $.pageload.popup_close = function(forced) {
111            var forced = forced && typeof forced != 'undefined' ? true : false;
112            $.pageload.fn.popup.close_popup(forced);
113        }
114
115        $.pageload.popup_open = function(content) {
116            var content_exists = content && typeof content != 'undefined' ? true : false;
117            if (content_exists) {
118                $.pageload.fn.popup.open(content);
119            }
120        }
121
122
123        // Functions
124
125        $.pageload.fn = {
126
127            init: function() {
128                if ($.pageload.options.popup_content_enabled) {
129                    $.pageload.fn.popup.init();
130                }
131                $.pageload.fn.preloader.init();
132                $.pageload.fn.pages.init();
133            },
134
135            _fetchBackgroundImages: function(images_to_load_selector) {
136                $(images_to_load_selector).length === 0 ? console.warn('images_to_load_selector returned none') : "";
137                // Put background images in place to initiate load
138                $(images_to_load_selector).each(function() {
139                    if ($(this).filter('[data-style]').length) {
140                        var new_style_value = $(this).attr('data-style');
141                        if ($(this).attr('style') && typeof $(this).attr('style') != 'undefined') {
142                            var new_style_value = new_style_value + $(this).attr('style');
143                            // console.log(new_style_value);
144                        }
145                        $(this).attr('style', new_style_value);
146                        $(this).removeAttr('data-style');
147                    }
148                });
149            },
150
151
152            _decryptContent: function(encryptedContent, salt) {
153
154                if (!encryptedContent || !salt) {
155                    console.info('_decryptContent - no encryptedcontent or salt.')
156                    return '';
157                }
158                
159                // Decode the base64 cacheData so we can separate iv and crypt text.
160                var rawData = atob(encryptedContent);
161                var iv = rawData.slice(0,16);
162                var crypttext = rawData.slice(16);
163                
164                // Decrypt...
165                var plaintextArray = CryptoJS.AES.decrypt(
166                    { ciphertext: CryptoJS.enc.Latin1.parse(crypttext) },
167                    CryptoJS.enc.Latin1.parse(salt),
168                    { iv: CryptoJS.enc.Latin1.parse(iv) }
169                );
170
171                var decryptedContent = CryptoJS.enc.Utf8.stringify(plaintextArray);
172                return decryptedContent;
173            },
174
175
176            _replace_main_content: function(originalContent, newContent){
177                
178                var regex = /([\s\S]*)<!--contentstart-->([\s\S]*)<!--contentend-->([\s\S]*)/gm;
179
180                var m,
181                preContent,
182                mainContent,
183                postContent;
184
185                while ((m = regex.exec(originalContent)) !== null) {
186                    // This is necessary to avoid infinite loops with zero-width matches
187                    if (m.index === regex.lastIndex) {
188                        regex.lastIndex++;
189                    }
190
191                    // The result can be accessed through the `m`-variable.
192                    m.forEach(function (match, groupIndex) {
193                        if (groupIndex == 1) {
194                            preContent = match;
195                        } 
196                        if (groupIndex == 2) {
197                            mainContent = match;
198                        } 
199                        if (groupIndex == 3) {
200                            postContent = match;
201                        } 
202                        // console.log(`Found match, group ${groupIndex}: ${match}`);
203                    });
204                }
205                var result = preContent + newContent + postContent;
206                return result;
207
208            },
209
210            preloader: {
211
212                init: function() {
213                    var preloader_html = '<div id="preloader"><div id="preloader_mask"></div>' + $.pageload.options.preloader_additional_html + '<div id="loader_wrapper"><div id="loader"></div></div><div id="loader_logo"></div></div>';
214
215                    var first_page_load = $('body').hasClass('first-load-complete');
216                    var internal_link = document.referrer && typeof document.referrer != 'undefined' ? true : false;
217                    
218                    
219                    var load_type = '';
220                    
221                    if (!$.pageload.options.development_mode_show_splash_screen_on_refresh) {
222                        if (typeof window.performance !== 'undefined' && typeof window.performance.getEntriesByType !== 'undefined') {
223                            if (performance.getEntriesByType("navigation").length && typeof performance.getEntriesByType("navigation") !== 'undefined') {
224                                if (performance.getEntriesByType("navigation")[0].type && typeof performance.getEntriesByType("navigation")[0].type != 'undefined') { 
225                                    if (performance.getEntriesByType("navigation")[0].type == 'reload'){
226                                        load_type = 'reload';
227                                    }
228                                }
229                            }
230                        }
231                    }
232
233                    var show_splash_screen = (($.pageload.options.splash_screen_always_enabled && !internal_link && load_type != 'reload') || ($.pageload.options.splash_screen_enabled && !h.getCookie('splash_screen_disabled') && load_type != 'reload' )); // (!h.getCookie('splash_screen_disabled'))
234                    // Force splash screen in development mode
235                    
236                    if ($.pageload.options.development_mode || window.location.search == '?pageloaddevmode=1') {
237                        var show_splash_screen = true;
238                    }
239
240                    // Only show the preloader on the first page load
241                    if (!first_page_load) {
242                        
243                        if (!$('body').attr('data-pathname')) {
244                            $('body').attr('data-pathname', window.location.pathname + window.location.search);
245                        }
246                        
247                        $('body').attr('data-page-title', document.title);
248                        if ($('body').find('#preloader').length === 0) {
249                            //console.info("Splash screen loader via javascript");
250                            $('body').append(preloader_html);
251                        }
252                        history.replaceState({'firstPageLoad': true}, null, window.location.pathname + location.search + window.location.hash);
253                        if (show_splash_screen) {
254                            // Show splash screen if its the very first page load, otherwise a cookie is set for 15 minutes and will stop the splash screen showing again during the same website visit
255                            $.pageload.fn.preloader.start_load();
256                        } else {
257                            // If the splash screen is not displayed, only add the first-load-complete class to the body and don't fire the loader script
258                            $.pageload.fn.preloader.start_load(true);
259                        }
260                    }
261
262                    // Set a cookie so the splash screen doesn't show again in the same visit
263                    h.setCookie('splash_screen_disabled', 'true', '', $.pageload.options.splash_screen_cookie_expiry); // Set cookie for 15 minutes
264
265                },
266
267                start_load: function(short_load) {
268                    // debugger;
269                    // Start loader
270                    if (short_load) {
271                        $('body').addClass('loader-active first-load-complete skip-splash-screen content-load-waiting');
272                        $('body')
273                            .addClass('loader-active ajax-links-disabled')
274                            .delay(50)
275                            .queue(function() {
276                                $('body').addClass('ajax-loading ajax-initial-loading');
277                                $(this).dequeue();
278                            })
279                        ;
280                        $.pageload.fn.preloader.preload_images(short_load);
281                    } else {
282                        $('body').addClass('loader-active splash-loader-active content-load-waiting');
283                        // debugger;
284                        $.pageload.options.preloader_in();
285
286                        $('#preloader')
287                            .delay(20)
288                            .queue(function() {
289                                $(this).addClass('loading-start');
290                                $(this).dequeue();
291                                // debugger;
292                            })
293                            .delay($.pageload.options.splash_screen_auto_delays_enabled ? 200 : 0)
294                            .queue(function() {
295                                $(this).addClass('loading-bar-start');
296                                $(this).dequeue();
297                                // debugger;
298                            })
299                            .delay($.pageload.options.splash_screen_auto_delays_enabled ? 300 : 0)
300                            .queue(function() {
301                                $(this).dequeue();
302                                $.pageload.fn.preloader.preload_images();
303                                // debugger;
304                            })
305                        ;
306                    }
307
308                },
309
310                preload_images: function(short_load) {
311
312                    // Define the images/backgrounds which should be preloaded on first page load
313                    // We preload the first two images of the hero slider, and the generic sidebar image for the full detail page of each record
314
315                    var images_to_load_selector = $.pageload.options.preload_images_selector;
316
317                    if ($(images_to_load_selector).length) {
318
319                        // IMPORTANT: Images to be preloaded must be supplied as a selector string to the 'mutliple_elements' parameter.
320                        // Otherwise if you use the normal method the script will go through each of the selector items individually and the 'progress' and 'done' callbacks will NOT be run in one single process.
321                        // $('body').pageLoadwaitForImages({
322                        //     waitForAll: true,
323                        //     multiple_elements: images_to_load_selector
324                        // });
325
326                        // Check the logo image is loaded before displaying the splash screen.
327                        // If there isn't a logo image it should fall through to done.
328
329                        // Put logo image in place to initiate load
330                        $.pageload.fn._fetchBackgroundImages($.pageload.options.splash_screen_primary_preload_images_selector);
331                        $('body').pageLoadwaitForImages({
332                            waitForAll: true,
333                            multiple_elements: $.pageload.options.splash_screen_primary_preload_images_selector
334                        }).done(function(e){
335                            $('body').addClass('pageload-splash-primary-images-preloaded');
336                            $($.pageload.options.splash_screen_primary_preload_images_selector).css('opacity', 1);
337
338                            if ($.pageload.options.verbose) {
339                                console.log('#########');
340                                console.log('Preloading images:');
341                            }
342                            percentCounter = 0;
343                            percentIncrements = (100 / $(images_to_load_selector).length);
344
345
346                            // Put background images in place to initiate load
347                            $.pageload.fn._fetchBackgroundImages(images_to_load_selector);
348                            // console.log()
349
350                            $('body').pageLoadwaitForImages({
351                                    waitForAll: true,
352                                    multiple_elements: images_to_load_selector
353                                })
354                                .progress(function(loaded, count, success) {
355                                    percentIncrements = (100 / count);
356                                    percentCounter = percentCounter + percentIncrements;
357                                    var currentPercentage = percentCounter + '%';
358                                    $('#loader').css($.pageload.options.loader_orientation, currentPercentage);
359                                    // Connect stuff to the loader here!!!
360                                    // var superpathPercentage = 327.86 * (Math.round(percentCounter) / 100);
361                                    // $('.superpath').css('stroke-dashoffset', Math.round(327.86 - superpathPercentage));
362
363                                    if ($.pageload.options.verbose) {
364                                        console.log('#########');
365                                        console.log('Status:');
366                                        console.log(currentPercentage);
367                                    }
368                                })
369                                .done(function() {
370                                    if ($.pageload.options.verbose) {
371                                        console.log('#########');
372                                        console.log('Status:');
373                                        console.log('complete');
374                                    }
375
376                                    $('#loader')
377                                        .delay(500)
378                                        .queue(function() {
379                                            $.pageload.fn.preloader.load_complete(short_load);
380                                            $(this).dequeue();
381                                        })
382                                    ;
383                                });
384                            ;
385
386                            // Fade in the background image once it's finished downloading.
387                            // Put logo image in place to initiate load
388                            $.pageload.fn._fetchBackgroundImages($.pageload.options.splash_screen_secondary_preload_images_selector);
389                            // This has no effect if the page content is loaded before the background image, this is by design!
390                            $('body').pageLoadwaitForImages({
391                                waitForAll: true,
392                                multiple_elements: $.pageload.options.splash_screen_secondary_preload_images_selector
393                            })
394                            .done(function(e){
395                                $('body').addClass('pageload-splash-secondary-images-preloaded');
396                                $('#home_splash_image_container').css({
397                                    'opacity': 1
398                                });
399                            });
400
401
402                        });
403                    } else {
404                        // Fade in the background image once it's finished downloading.
405                        // Put logo image in place to initiate load
406                        $.pageload.fn._fetchBackgroundImages($.pageload.options.splash_screen_secondary_preload_images_selector);
407                        // This has no effect if the page content is loaded before the background image, this is by design!
408                        $('body').pageLoadwaitForImages({
409                            waitForAll: true,
410                            multiple_elements: $.pageload.options.splash_screen_secondary_preload_images_selector
411                        })
412                        .done(function(e){
413                            $('body').addClass('pageload-splash-secondary-images-preloaded');
414                            $('#bk-img-container').css('opacity', 1);
415                            $('#home_splash_image_container').css({
416                                'opacity': 1
417                            });
418                        });
419
420                        $('#loader')
421                            .delay($.pageload.options.splash_screen_auto_delays_enabled ? 100 : 0)
422                            .queue(function() {
423                                $(this).css($.pageload.options.loader_orientation, '100%');
424                                $(this).dequeue();
425                            })
426                            .delay($.pageload.options.splash_screen_auto_delays_enabled ? 300 : 0)
427                            .queue(function() {
428                                $.pageload.fn.preloader.load_complete(short_load);
429                                $(this).dequeue();
430                            })
431                        ;
432                    }
433                },
434
435                load_complete: function(short_load) {
436                    // Finish the preloader animations
437                    if (short_load) {
438
439                        $('body').removeClass('content-load-waiting skip-splash-screen');
440                        $.pageload.fn.preloader.end_ajax();
441                        
442                    } else {
443                        if (!$('body').hasClass('first-load-complete')) {
444                            if ($.pageload.options.development_mode || $.pageload.options.splash_screen_click_to_close) {
445                                $('#preloader').click(function() {
446                                    $(this).dequeue();
447                                });
448                            }
449                            $('#preloader')
450                                .queue(function() {
451                                    $(this).addClass('loading-complete');
452                                    $('#loader').css($.pageload.options.loader_orientation, '100.1%'); // Important: Setting the width as 100.1 (or anything other than 100) forces CSS transitions to update if one has specifically been set for .loading-complete (e.g. we usually speed up the progress bar at the end)
453                                    if (!$.pageload.options.development_mode) {
454                                        $(this).dequeue();
455                                    }
456                                })
457                                .delay($.pageload.options.splash_screen_auto_delays_enabled ? 400 : 0)
458                                .queue(function() {
459                                    $(this).addClass('loading-bar-end');
460                                    $('#loader').css($.pageload.options.loader_orientation, '');
461                                    if (!$.pageload.options.development_mode) {
462                                        $(this).dequeue();
463                                    }
464                                })
465                                .delay($.pageload.options.splash_screen_auto_delays_enabled ? 500 : 0)
466                                .queue(function() {
467                                    $(this).addClass('splash-screen-in');
468                                    $.pageload.options.splash_screen_in();
469                                    if (!$.pageload.options.development_mode && !$.pageload.options.development_mode_pause_splash_screen && !$.pageload.options.splash_screen_click_to_close) {
470                                        $(this).dequeue();
471                                    }
472                                })
473                                .delay($.pageload.options.splash_screen_click_to_close ? 0 : $.pageload.options.splash_screen_delay_after_complete)
474                                .queue(function() {
475                                    $('body').addClass('pageload-splash-page-content-in');
476                                    $(this).dequeue();
477                                })
478                                .delay(400)
479                                .queue(function() {
480                                    $(this).addClass('splash-screen-out');
481                                    $.pageload.options.splash_screen_out();
482                                    $('body').removeClass('content-load-waiting');
483                                    $('body').removeClass('pageload-splash-page-content-hidden');
484                                    if (!$.pageload.options.development_mode) {
485                                        $(this).dequeue();
486                                    }
487                                })
488                                .delay(400)
489                                .queue(function() {
490                                    $('body').addClass('first-load-complete');
491                                    $('body').removeClass('loader-active ajax-loading splash-loader-active pageload-splash-page-content-in');
492                                    $(this).removeClass('loading-start loading-bar-start loading-complete loading-bar-end splash-screen-in 
492splash-screen-out');
493                                    $('#loader').css($.pageload.options.loader_orientation, '');
494                                    $(this).dequeue();
495                                })
496                            ;
497                        }
498                    }
499
500                    // After preload has completed, load the rest of the hero images (only the first 2 are preloaded)
501
502                    $('#hero_slider .hero_item .image div[data-style]').each(function() {
503                        $(this).attr('style', $(this).attr('data-style'));
504                        $(this).removeAttr('data-style');
505                    });
506                    
507                },
508
509                start_ajax: function(clicked_element, incoming_content_type) {
510
511                    var clicked_element = (clicked_element && typeof clicked_element != 'undefined' ? clicked_element : false);
512                    
513                    var assumed_incoming_content_type = 'standard'; // A class can be added to the original clicked element which allows us to assume the content type before it arrives, if this exists use it to add certain classes
514                    var content_type_body_class = 'loader-incoming-type-standard';
515
516                    if (incoming_content_type && typeof incoming_content_type != 'undefined') {
517                        var assumed_incoming_content_type = incoming_content_type;
518                    }
519
520                    if (clicked_element) {
521                        if (clicked_element.hasClass('pageload-link-type-ajax-enabled-content')) {
522                            var assumed_incoming_content_type = 'inner';
523                            var content_type_body_class = 'loader-incoming-type-inner';
524                        } else if (clicked_element.hasClass('pageload-link-type-popup-enabled-content')) {
525                            var assumed_incoming_content_type = 'popup';
526                        }
527                    }
528                    
529                    if (assumed_incoming_content_type == 'inner') {
530                        var content_type_body_class = 'loader-incoming-type-inner';
531                    } else if (assumed_incoming_content_type == 'popup') {
532                        var content_type_body_class = 'loader-incoming-type-popup';
533                    }
534
535                    // Reset some things first, if the end of the last load has not completely finished
536                    $('body').removeClass('loader-active ajax-loading-complete');
537                    $(this).removeClass('loading-start loading-bar-start loading-complete loading-bar-end splash-screen-in splash-screen-out');
538                    $('#loader').css($.pageload.options.loader_orientation, '');
539
540                    // Start loading of new page
541                    $('body')
542                        .clearQueue()
543                        .addClass('loader-active ajax-links-disabled page-transition-active ' + content_type_body_class)
544                        .delay(50)
545                        .queue(function() {
546                            $('body').addClass('ajax-loading ajax-initial-loading');
547                            $(this).dequeue();
548                        })
549                    ;
550                    $.pageload.options.page_transition_start();
551                    if (assumed_incoming_content_type == 'popup') {
552                        $.pageload.options.popup_before();
553                    }
554                    $('body')
555                        .clearQueue('pageload-disable-links')
556                        .addClass('pageload-links-disabled-temporarily')
557                        .delay(500, 'pageload-disable-links')
558                        .queue('pageload-disable-links', function() {
559                            $('body').removeClass('pageload-links-disabled-temporarily');
560                            $(this).dequeue('pageload-disable-links');
561                        })
562                    ;
563
564
565                },
566
567                end_ajax: function() {
568                    $('body')
569                        .removeClass('ajax-initial-loading ajax-links-disabled pageload-links-disabled-temporarily')
570                        .removeClass('page-transition page-transition2')
571                        .queue(function() {
572                            $('body').removeClass('page-transition ajax-loading').removeClass('page-transition2').addClass('ajax-loading-complete');
573                            $(this).dequeue();
574                        })
575                        .delay(400)
576                        .queue(function() {
577                            $.pageload.options.page_transition_end();
578                            $('body').removeClass('page-transition-active loader-active ajax-loading-complete loader-incoming-type-standard loader-incoming-type-inner loader-incoming-type-popup');
579                            $(this).removeClass('complete4').removeClass('loading');
580                            $('#loader').css($.pageload.options.loader_orientation, '');
581                            $(this).dequeue();
582                        })
583                    ;
584
585                }
586
587            },
588
589            popup: {
590                
591                settings: {
592                    fallback_close_path: typeof $.pageload.fn != 'undefined' ? (typeof $.pageload.fn.popup.settings != 'undefined' ? (typeof $.pageload.fn.popup.settings.fallback_close_path != 'undefined' ? $.pageload.fn.popup.settings.fallback_close_path : '') : '') : ''
593                },
594
595                init: function() {
596                    
597                    // if the popup doesn't have a title with an id of 'popup_regi
597on' give a generic aria label of 'popup'
598                    if ($('#popup_container #popup_region').length) {
599                        var popup_region_aria_label = 'aria-labelledby="popup_region"'
600                    } else {
601                        var popup_region_aria_label = 'aria-label="modal"'
602                    }
603
604                    if (!$('#popup_container').length) {
605                        $('body').append('<div id="popup_container"><div id="popup_overlay"></div><div id="popup_box"><div class="inner" role="dialog" aria-modal="true" aria-live="polite" ' + popup_region_aria_label + '><div id="popup_content"></div><div class="pagination_controls"><div class="previous pagination_controls_previous"><a href="#" role="button">Previous</a></div><div class="next pagination_controls_next"><a href="#" role="button">Next</a></div></div><div class="close"><a href="javascript:;" role="button">Close</a></div></div></div></div>');
606                    }
607                    
608                    if ($('.site-popup-enabled-content').length) {
609                        if ($.pageload.options.popup_content_force_open) {
610                            var popup_content_html = $('.site-popup-enabled-content').html();
611                            var forced_close_path = $('.site-popup-enabled-content').attr('data-pageload-popup-fallback-close-path');
612                            
613                            $('.site-popup-enabled-content').remove();
614                            
615                            $.pageload.popup_open(popup_content_html);
616                            
617                            $('body').addClass('site-popup-fallback-forced-open');
618                            
619                            if (forced_close_path && typeof forced_close_path != 'undefined') {
620                                $.pageload.fn.popup.settings.fallback_close_path = forced_close_path;
621                            } else {
622                                $.pageload.fn.popup.settings.fallback_close_path = '/';
623                            }
624                        } else {
625                            $('body').addClass('site-popup-fallback-mode');
626                        }
627                    } else {
628                        if (!$('body').hasClass('page-popup-active')) {
629                            $('body').removeClass('site-popup-fallback-mode site-popup-fallback-forced-open');
630                        }
631                    }
632
633                    $('#popup_box .close').unbind('click.closefunction').bind('click.closefunction', function() {
634                        $.pageload.fn.popup.close_popup();
635                    });
636
637                    $('#popup_overlay').click(function() {
638                        $('#popup_box .close').trigger('click');
639                    });
640
641                },
642                
643                open: function(content) {
644                    $('#popup_content').html(content);
645                    $('html').addClass('page-popup-active');
646                    $('body')
647                        .clearQueue()
648                        .addClass('page-popup-active')
649                        .removeClass('ajax-initial-loading')
650                        .delay(50)
651                        .queue(function() {
652                            $(this).addClass('page-popup-visible');
653                            $(this).dequeue();
654                        })
655                    ;
656                    $.pageload.fn.popup.after_load();
657                    $.pageload.fn.preloader.end_ajax();
658                },
659
660                close_popup: function(forced) {
661                    if (typeof pageload_xhr != 'undefined') {
662                        pageload_xhr.abort('forced_abort');
663                    }
664                    var forced = forced && typeof forced != 'undefined' ? true : false;
665                    if ($('body').hasClass('page-popup-force-close')) {
666                        var forced = true;
667                    }
668                    
669                    var forced_close_path = $.pageload.fn.popup.settings.fallback_close_path;
670                    
671                    if ($('body').hasClass('site-popup-fallback-forced-open') && forced_close_path && !forced) {
672
673                            $.pageload.load(forced_close_path, true);
674                        
675                    } else {
676                        if (!forced) {
677                            $('body').addClass('page-popup-clicked-close');
678                            if ($.pageload.options.popup_content_update_url){
679                                window.history.back();
680                            }
681                        }
682                        $('body')
683                            .clearQueue()
684                            .removeClass('page-popup-visible loader-incoming-type-popup')
685                            .delay(600)
686                            .queue(function() {
687                                $.pageload.options.popup_after_close();
688                                
689                                // remove keyboard pagination listener
690                                $(window).off('keydown.popup_pagination');
691                                
692                                //if (!$('body').hasClass('page-popup-force-close')) {
693                                //    history.replaceState({'ajaxPageLoad': true}, null, $('body').attr('data-pathname'));
694                                //}
695                                
696                                // change url used in seo edit screen
697                                if ($('#cms-frontend-toolbar-seo-admin .seo-tools-btn').length) {
698                                    $('#cms-frontend-toolbar-seo-admin .seo-tools-btn').attr("href", window.location.pathname)
699                                    try {
700                                        window.seo.init();
701                                    } catch (error) {
702                                        console.error(error);
703                                    }
704                                }
705                                if ($('#popup_box iframe').length > 0) {
706                                    $('#popup_box iframe').remove();
707                                }
708                                $('html').removeClass('page-popup-active');
709                                
710                                //Return non-popup page title
711                                var base_page_title = $('body').attr('data-page-title');
712                                if (base_page_title && typeof base_page_title != 'undefined') {
713                                    document.title = base_page_title;
714                                } 
715                                $(this).removeClass('page-popup-active page-popup-force-close page-popup-clicked-close');
716                                $(this).dequeue();
717                            })
718                        ;
719                        try {
720                            h.accessibility.on_popup_closing();
721                        }
722                        catch(error) {
723                            console.log(error);
724                        }
725                    }
726                    
727                    $.pageload.fn.popup.settings.fallback_close_path = '';
728
729                },
730
731                after_load: function() {
732
733                    // Previous/Next buttons
734
735                    $('#popup_box').delay(400).queue(function() {
736                        $('body').removeClass('page-popup-transition-initial');
737                        $(this).removeClass('popup-direction-left popup-direction-right');
738                        $(this).dequeue();
739                    });
740                    
741                    var link_suffix = '';
742                    if (window.location.search != '') {
743                        if (window.location.search.indexOf('?_preview_uid') == 0 || window.location.search.indexOf('?_cmspreview=1') == 0) {
744                            var link_suffix = window.location.search;
745                        }
746                    }
747                    var previous_link = $('#popup_content .pagination_controls .pagination_controls_prev a').attr('href');
748                    var previous_clicked_element = $('#popup_content .pagination_controls .pagination_controls_prev a');
749                    var next_link = $('#popup_content .pagination_controls .pagination_controls_next a').attr('href');
750                    var next_clicked_element = $('#popup_content .pagination_controls .pagination_controls_next a');
751                    
752                    // Add language in front of link if it exists
753                    if (window.archimedes.proxy_dir && typeof window.archimedes.proxy_dir != 'undefined' && previous_link && typeof previous_link != 'undefined' && !previous_link.startsWith(window.archimedes.proxy_dir + '/')) {
754                        previous_link = window.archimedes.proxy_dir + previous_link;
755                    }
756                    if (window.archimedes.proxy_dir && typeof window.archimedes.proxy_dir != 'undefined' && next_link && typeof next_link != 'undefined' && !next_link.startsWith(window.archimedes.proxy_dir + '/')) {
757                        next_link = window.archimedes.proxy_dir + next_link;
758                    }
759
760                    if (previous_link && typeof previous_link != 'undefined') {
761                        $('#popup_box > .inner .pagination_controls .previous')
762                            .unbind()
763                            .attr('data-href', previous_link + link_suffix)
764                            .removeClass('disabled')
765                            .click(function() {
766                                $('body').addClass('page-popup-transition-initial');
767                                $('#popup_box').addClass('popup-direction-left');
768                                
769                                $.pageload.fn.pages.load($(this).attr('data-href'), false, null, null, previous_clicked_element, null, 'popup');
770                                return false;
771                            })
772                        ;
773                        $('#popup_box > .inner .pagination_controls .previous a').removeAttr("data-disabled aria-label").attr('tabindex', 0);
774                    } else {
775                        $('#popup_box > .inner .pagination_controls .previous').unbind().attr('data-href', '').addClass('disabled');
776                        $('#popup_box > .inner .pagination_controls .previous a').attr({"data-disabled": true, "tabindex": -1, "aria-label": "disabled"});
777                    }
778
779                    if (next_link && typeof next_link != 'undefined') {
780                        $('#popup_box > .inner .pagination_controls .next')
781                            .unbind()
782                            .attr('data-href', next_link + link_suffix)
783                            .removeClass('disabled')
784                            .click(function() {
785                                $('body').addClass('page-popup-transition-initial');
786                                $('#popup_box').addClass('popup-direction-right');
787                                $.pageload.fn.pages.load($(this).attr('data-href'), false, null, null, next_clicked_element, null, 'popup');
788                                return false;
789                            })
790                        ;
791                        $('#popup_box > .inner .pagination_controls .next a').removeAttr("data-disabled aria-label").attr('tabindex', 0);
792                    } else {
793                        $('#popup_box > .inner .pagination_controls .next').unbind().attr('data-href', '').addClass('disabled');
794                        $('#popup_box > .inner .pagination_controls .next a').attr({"data-disabled": true, "tabindex": -1, "aria-label": "disabled"});
795                    }
796                    
797                    var popup_meta_title = $('.site-popup-enabled-content').attr('data-pageload-popup-meta-title');
798                    if (popup_meta_title && typeof popup_meta_title != 'undefined') {
799                        console.log('-------------------');
800                        console.log(popup_meta_title);
801                    } 
802
803                    // Run functions required in the popup
804
805                    $.pageload.options.popup_after();
806                    
807                    // Popup key listeners
808                    
809                    if ($('#popup_container .pagination_controls').length) {
810                        var next_btn = $('#popup_container .pagination_controls .next').not('.disabled').eq(0);
811                        var prev_btn = $('#popup_container .pagination_controls .previous').not('.disabled').eq(0);
812                        
813                        $(window).off('keydown.popup_pagination').on('keydown.popup_pagination', function(e) {
814                            
815                            // isTopPopup variable is to determine which popup is the current popup / top layered popup.
816                            try {
817                                var isTopPopup = h.accessibility.is_current_popup("#popup_box .inner");
818                            } catch(error) {
819                                var isTopPopup = true;
820                            }
821                            
822                            if(e.keyCode == 39 && isTopPopup) {
823                                if(next_btn.length ) {// right
824                                    $(window).off('keydown.popup_pagination');
825                                    next_btn.trigger('click');
826                                }
827                            } else if(e.keyCode == 37 && isTopPopup) {
828                                if(prev_btn.length) {
829                                    $(window).off('keydown.popup_pagination');
830                                    prev_btn.trigger('click');
831                                }
832                            } 
833						});
834                    }
835                    
836                       
837                    // Accessibility - add id for region label & focus on popup content
838                    if ($('#popup_content .title:first').length) {
839                        $('#popup_content .title:first').attr("id", "popup_regi
839on");
840                    } else if ($('#popup_content .artist').length) {
841                        $('#popup_content .artist').attr("id", "popup_region");
842                    }
843                    
844                    try {
845                        if ($("#popup_box.popup-direction-right").length || $("#popup_box.popup-direction-left").length) {
846                            h.accessibility.focus_untrap();
847                            h.accessibility.focus_trap('#popup_box .inner', false, '#popup_container .close');
848                        } else {
849                            h.accessibility.on_popup_opening('#popup_box .inner', '#popup_box .focustrap-first', '#popup_container .close');
850                        }
851                    }
852                    catch(error) {
853                        
854                        console.log(error);
855                        
856                        // backup escape key functionality
857                        $(window).off('keydown.popup_close');
858                        if ($('#popup_container .close').length) {
859                            $(window).on('keydown.popup_close', function(e) {
860                                if(e.keyCode == 27) {
861                                    $(window).off('keydown.popup_close');
862                                    $('#popup_container .close').trigger('click');
863                                }
864                            });
865                        }
866                        
867                    }
868                    
869                    // Set focus on popup inner container on open or next/previous
870                    if ( $('#popup_box .inner:first').length ) {
871                        $('#popup_box .inner:first').attr('tabindex', -1)[0].focus({preventScroll:true});
872                    }
873                    
874                    try {
875                        h.accessibility.role_button();
876                    } catch (error) {
877                        console.log(error);
878                    }
879
880                }
881
882            },
883
884            pages: {
885
886                init: function() {
887
888                    $.pageload.fn.pages.add_click_events();
889
890                    if ($.pageload.options.page_scroll_history) {
891                        // If page scroll history is enabled, block automatic browser scroll restoration until loading has completed
892                        if ('scrollRestoration' in history) {
893                            history.scrollRestoration = 'manual';
894                        }
895                    }
896
897                    $(window).on("popstate", function (ev) {
898
899                        if (ev.originalEvent.state) {
900                            if (ev.originalEvent.state.ajaxPageLoad || ev.originalEvent.state.firstPageLoad) {
901                                
902                                var previous_page_url = ''
903                                if ($.pageload.previous_url && typeof $.pageload.previous_url != 'undefined') {
904                                    previous_page_url = $.pageload.previous_url.split('#')[0];
905                                }
906                                
907                                var allow_hash_url = false;
908                                if (previous_page_url && previous_page_url != window.location.pathname || ev.originalEvent.state.firstPageLoad) {
909                                    allow_hash_url = true;
910                                }
911                                
912                                if (!window.location.hash || typeof window.location.hash == 'undefined' || allow_hash_url) {
913                                    // Tom: In development: check custom functions
914                                    if (window.location.pathname in $.pageload.options.popstate_custom_functions) {
915                                        var custom_function = $.pageload.options.popstate_custom_functions[window.location.pathname];
916                                        custom_function(ev);
917                                    } else if (($('body').hasClass('page-popup-active') || $('body').hasClass('page-popup-clicked-close')) && !$('body').hasClass('site-popup-fallback-forced-open')) {
918                                        if (!$('body').hasClass('page-popup-force-close') && !$('body').hasClass('page-popup-clicked-close')) {
919                                            $('body').addClass('page-popup-force-close');
920                                            $('#popup_box .close').trigger('click');
921                                        }
922                                    } else {
923                                        var page_scroll_top_value = 0;
924                                        if ($.pageload.options.page_scroll_history && ev.originalEvent.state.scrollTop && typeof ev.originalEvent.state.scrollTop != 'undefined') {
925                                            var page_scroll_top_value = ev.originalEvent.state.scrollTop;
926                                        }
927                                        $.pageload.fn.pages.load(window.location.pathname + window.location.search + window.location.hash, false, null, 'history_change', null, page_scroll_top_value);
928                                    }
929                                }
930                            }
931                        }
932                    });
933
934                    $(window).on("beforeunload", function(){
935                        if ($.pageload.options.page_scroll_history) {
936                            history.scrollRestoration = 'auto';
937                        }
938                    });
939
940                },
941
942
943                add_click_events: function(element_context) {
944                    if (!element_context || typeof element_context == 'undefined') {
945                        var element_context = '#container';
946                    }
947                    
948                    if ($.pageload.options.ajax_navigation_enabled){
949                        $('a', element_context).unbind('click.pageload').bind('click.pageload', function() {
950                            
951                            // For accessibility - tracks which element to refocus on
952                            try {
953                                h.accessibility.global_variables.element_to_refocus_to = $(this);
954                            } catch(error) {
955                                console.log(error);
956                            }
957                            
958                            var element = $(this);
959                            var element_href = $(this).attr('href');
960                            
961                            if (element_href) {
962                                if (!$(this).hasClass('link-no-ajax') && !$(this).hasClass('page-load-within') && !$('body').hasClass('slider-drag') && element_href != '#' && element_href.indexOf('/') == 0 && (element_href.indexOf('#') < 0 || (element_href.indexOf('#') > -1 && element_href != window.location.pathname)) && element_href.indexOf('/custom_images/') < 0 && element_href.indexOf('/usr/') < 0 && element.attr('target') != '_blank') {
963                                    // console.log(element_href);
964                                    if ($('body').hasClass('pageload-links-disabled-temporarily')) {
965                                        // Links temporarily disabled, this is to avoid double clicks making pages load twice
966                                        return false;
967                                    } else if ($('body').hasClass('ajax-links-disabled')) {
968                                        // Already loading page content, we could also cancel the request and start a new one. Currently we are allowing standard navigation in this case.
969                                    } else if ($('body').hasClass('website-editor-mode') && window.parent.website_editor && $.isFunction(window.parent.website_editor.init)) {
970                                        
971                                        function success_callback() {
972                                            $.pageload.fn.pages.load(element_href, true, null, null, element);
973                                        }
974                                        window.parent.website_editor.warnings_and_notifications.check_for_unsaved_changes(success_callback);
975                                        return false;
976                                        
977                                    } else {
978                                        $.pageload.fn.pages.load(element_href, true, null, null, element);
979                                        return false;
980                                    }
981                                } else if ($('body').hasClass('slider-drag')) {
982                                    return false;
983                                }
984                            }
985                        });
986                    }
987
988                },
989
990                load: function(element_href, pushstate, callback, navigation_type, element, page_scroll_top_value, incoming_content_type, inner_content_selector, post_data) {
991                    
992                    $.pageload.options.before_load(element_href, pushstate, callback, navigation_type, element, page_scroll_top_value, incoming_content_type, inner_content_selector);
993 
994                    if (window.history.state && typeof window.history.state != 'undefined' && typeof window.history.state != 'null') {
995                        var current_page_history_state = window.history.state;
996                        var previous_page_scroll_top = $(window).scrollTop();
997                        current_page_history_state['scrollTop'] = previous_page_scroll_top;
998                        history.replaceState(current_page_history_state, null);
999                    }
1000                    
1001                    if (element_href != '#' && element_href.indexOf('/') == 0 && (element_href.indexOf('#') < 0 || (element_href.indexOf('#') > -1 && element_href != window.location.pathname)) && (element_href.indexOf('/custom_images/') < 0 || element_href.indexOf('?') > -1 && element_href.indexOf('/custom_images/') > element_href.indexOf('?')) && element_href.indexOf('/usr/') < 0) {
1002                        if (element_href == '/') {
1003                            target_top_level = '[href="' + element_href + '"]';
1004                        } else {
1005                            if (typeof $(element).attr('data-original-url') != 'undefined') {
1006                                target_top_level = $(element).attr('data-original-url').split('/')[1];
1007                                target_top_level = '/' + target_top_level + '/';
1008                                target_top_level = '[data-original-url^="' + target_top_level + '"]';
1009                            } else {
1010                                target_top_level = element_href.split('/')[1];
1011                                target_top_level = '/' + target_top_level + '/';
1012                                target_top_level = '[href^="' + target_top_level + '"]';
1013                            }
1014                        }
1015                        $.pageload.fn.preloader.start_ajax(element, incoming_content_type);
1016                        
1017                        if ($.pageload.options.verbose) {
1018                            console.log('#########');
1019                            console.log('Starting page load:');
1020                            console.log(element_href);
1021                        }
1022                        
1023                        pageload_save_attempts = 0;
1024                        pageload_save_attempt_limit = 5;
1025                        
1026                        pageload_load_new_page = function(element_href) {
1027                            
1028                            var url_params_to_retain_defaults = $.pageload.options.url_params_to_retain_defaults;
1029                            var url_params_to_retain = $.pageload.options.url_params_to_retain;
1030                            var combined_list_of_url_params_to_retain = url_params_to_retain_defaults.concat(url_params_to_retain);
1031                            var current_path = window.location.pathname + window.location.search;
1032                            
1033                            if (combined_list_of_url_params_to_retain) {
1034                                var href_contains_params = false;
1035                                if (element_href.indexOf('?') >= 0) {
1036                                    href_contains_params = true;
1037                                }
1038                                
1039                                // Append params to be retained to element href
1040                                $.each(combined_list_of_url_params_to_retain, function( index, param_to_retain ) {
1041                                    if (current_path.indexOf(param_to_retain) >= 0) {
1042                                        if (element_href.indexOf(param_to_retain) < 0) {
1043                                            element_href += (href_contains_params ? '&' : '?') + param_to_retain;
1044                                            href_contains_params = true;
1045                                        }
1046                                    }
1047                                });
1048                            }
1049                            
1050                            var post_params = {};
1051                            var load_method = 'GET';
1052                            
1053                            if (post_data) {
1054                                load_method = 'POST';
1055                                post_params = post_data;
1056                            }
1057                            
1058                            if (!$.pageload.options.disable_ajax_param) {
1059                                post_params['ajax'] = true;
1060                            }
1061                            
1062                            pageload_xhr = $.ajax({
1063                                url: element_href,
1064                                data: post_params,
1065                                method: load_method,
1066                                cache: true,
1067                                dataType: 'html',
1068                                error: function(e) {
1069                                    var error_status_code = e.status;
1070                                    var load_attempt_limit_reached = pageload_save_attempts >= pageload_save_attempt_limit ? true : false;
1071                                    if (e.statusText == 'forced_abort') {
1072                                        // User forced the request to be cancelled, dont show an error
1073                                        $.pageload.fn.preloader.end_ajax();
1074                                    } else {
1075                                        if (String(error_status_code) == '0') {
1076                                            window.location.href = element_href;
1077                                        } else if (String(error_status_code) != '404' && !load_attempt_limit_reached) {
1078                                            // Retry loading after a timeout
1079                                            window.setTimeout(function() {
1080                                                pageload_load_new_page(element_href);
1081                                            },500);
1082                                        } else {
1083                                            // When load attempts have been exchausted or if it the error is a 404
1084                                            h.alert('Sorry, that page could not be loaded. Please try again later.');
1085                                            $.pageload.fn.preloader.end_ajax();
1086                                        }
1087                                        pageload_save_attempts = pageload_save_attempts + 1;
1088                                    }
1089                                },
1090                                success: function(new_page_html) {
1091                                    if (new_page_html) {
1092                                        if ($.pageload.options.verbose) {
1093                                            console.log('#########');
1094                                            console.log('PAGE LOAD COMPLETE');
1095                                        }
1096    
1097                                        new_page_html = new_page_html;
1098                                        
1099                                        var body_classes_remembered = ''
1100                                        function add_to_body_classes_remembered(classe
1100s) {
1101                                            additional_classes_to_remember = classes.split(',');
1102                                            for (i = 0; i < additional_classes_to_remember.length; i++) {
1103                                                var classname = $.trim(additional_classes_to_remember[i]).replace('.', '');
1104                                                if ($('body').hasClass(classname)) {
1105                                                    body_classes_remembered += ' ' + classname;
1106                                                }
1107                                            }
1108                                        }
1109                                        
1110                                        if ($.pageload.options.body_classes_to_retain_defaults) {
1111                                            add_to_body_classes_remembered($.pageload.options.body_classes_to_retain_defaults);
1112                                        }
1113                                        if ($.pageload.options.body_classes_to_retain) {
1114                                            add_to_body_classes_remembered($.pageload.options.body_classes_to_retain);
1115                                        }
1116    
1117                                        if (false) {
1118                                            // DEPRICATED STYLE
1119                                            new_page_title = (new_page_html.match(/<title>(.*?)<\/title>/) ? new_page_html.match(/<title>(.*?)<\/title>/)[1] : '');
1120                                            new_page_body_class = (new_page_html.match(/body class=\"(.*?)\"/) ? new_page_html.match(/body class=\"(.*?)\"/)[1] : '') + ' ' + body_classes_remembered;
1121                                            new_page_html = new_page_html.replace(/data-style=/g, 'style=');
1122                                            new_page_html_body = $.parseHTML('<div id="ajax_container">' + new_page_html.replace(/^[\S\s]*<body[^>]*?>/i, "").replace(/<\/body[\S\s]*$/i, "") + '</div>');
1123                                        }
1124    
1125                                        // Create 'parsed' version of the incoming HTML so we can interact as a jQuery object
1126                                        new_page_html_parsed = $.parseHTML(new_page_html);
1127                                        // Change instances of 'data-style' to 'style' so we can preload these images later on
1128                                        new_page_html = new_page_html.replace(/data-style=/g, 'style=');
1129    
1130                                        // Grab the title of the new page
1131                                        new_page_title = $(new_page_html_parsed).filter('title').text();
1132    
1133                                        // Grab the canonical of the new page
1134                                        var new_page_canonical = $(new_page_html_parsed).filter('link[rel="canonical"]').attr('href');
1135    
1136                                        if (new_page_canonical){
1137                                            if ($('link[rel="canonical"]').length){
1138                                                // Amend the skin's existing canonical tag to match the new page canonical
1139                                                $('link[rel="canonical"]').attr('href', new_page_canonical);
1140                                            } else {
1141                                                // The skin doesn't have a canonical tag so let's add one
1142                                                $('head').append('<link rel="canonical" href="'+new_page_canonical+'">')
1143                                            }
1144                                        }
1145                                        else {
1146                                            // The new page doesn't have a canonical set so let's remove the tag from the skin
1147                                            $('link[rel="canonical"]').remove();
1148                                        }
1149    
1150                                        // Grab the robots of the new page
1151                                        var new_page_robots = $(new_page_html_parsed).filter('meta[name="robots"]').attr('content');
1152                                        if (new_page_robots){
1153                                            if ($('meta[name="robots"]').length){
1154                                                // Amend the skin's existing robots tag to match the new page canonical
1155                                                $('meta[name="robots"]').attr('content', new_page_robots);
1156                                            } else {
1157                                                // The skin doesn't have a robots tag so let's add one
1158                                                $('head').append('<meta name="robots" content="'+new_page_robots+'">')
1159                                            }
1160                                        } else {
1161                                            // The new page doesn't have a robot set so let's remove the tag from the skin
1162                                            $('meta[name="robots"]').remove();
1163                                        }
1164                                        
1165                                        // Grab meta objects and replicate on this page
1166                                        $(new_page_html_parsed).filter('meta[property]').each(function() {
1167                                            var meta_property_attr = $(this).attr('property');
1168                                            var meta_content_attr = $(this).attr('content');
1169                                            if (meta_property_attr && typeof meta_property_attr != 'undefined' && typeof meta_content_attr != 'undefined') {
1170                                                $('meta[property="' + meta_property_attr + '"]').attr('content', meta_content_attr);
1171                                            }
1172                                        });
1173    
1174                                        // Grab the body classes of the new page
1175                                        new_page_body_class = (new_page_html.match(/body class=\"(.*?)\"/) ? new_page_html.match(/body class=\"(.*?)\"/)[1] : '') + ' ' + body_classes_remembered;
1176    
1177                                        // Parse the body of the new page HTML so we can interact with it with jQuery
1178                                        new_page_html_body = $.parseHTML('<div id="ajax_container">' + new_page_html.replace(/^[\S\s]*<body[^>]*?>/i, "").replace(/<\/body[\S\s]*$/i, "") + '</div>');
1179    
1180                                        if (new_page_html_body.length > 1) {
1181                                            // This is to fix an issue where more than one element was being returned by new_page_html_body - #ajax_container is the only element we want. Other elements included comment tags.
1182                                            new_page_html_body = $(new_page_html_body).filter('#ajax_container');
1183                                        }
1184    
1185                                        // Find the container_inner of the new page content
1186                                        new_page_main_content = $($.pageload.options.content_area_selector, new_page_html_body).html();
1187    
1188                                        if (typeof new_page_main_content == 'undefined') {
1189                                            // Force the page to reload if the main content area has not been found
1190                                            window.location.href = element_href;
1191                                            return false;
1192                                        }
1193                                            
1194                                            
1195                                        if (new_page_main_content.indexOf('cachedata') > -1) {
1196                                            
1197                                            var protected_path_data = localStorage.getItem('protected_paths_access') ? JSON.parse(localStorage.getItem('protected_paths_access')) : false;
1198                                            var check_type = 'localstorage'; // Options: 'localstorage', 'backend'
1199                                            if (protected_path_data) {    
1200                                                if (typeof protected_path_data[$('#protected_path_login_form', new_page_html_body).attr('data-protected-path-id')] != 'undefined') {
1201                                                    
1202                                                    var access_token = protected_path_data[$('#protected_path_login_form',new_page_html_body).attr('data-protected-path-id')]['access_token'];
1203                                                    var private_area_access_key = protected_path_data[$('#protected_path_login_form',new_page_html_body).attr('data-protected-path-id')]['private_area_access_key'];
1204                                                    var uid = protected_path_data[$('#protected_path_login_form',new_page_html_body).attr('data-protected-path-id')]['uid'];
1205                                                }
1206                                            }
1207                                            var cacheData = $('#cachedata', new_page_html_body).val()
1208                                            var salt = private_area_access_key;
1209                                            var decryptedContent = $.pageload.fn._decryptContent(cacheData, salt)
1210                                            
1211                                            //REPLACE EVERYWHERE
1212                                            if (decryptedContent.indexOf('protected page access allowed') > 0) {
1213                                                $('#cachedata', new_page_main_content).replaceWith(decryptedContent)
1214                                                $('#cachedata', new_page_html_body).replaceWith(decryptedContent)
1215                                                new_page_main_content = $.pageload.fn._replace_main_content(new_page_main_content, decryptedContent);
1216                                            } else {
1217                                                console.error('Encrypted content - access forbidden');
1218                                            }
1219                                            
1220                                        }
1221    
1222    
1223                                        if (new_page_main_content.indexOf('pageload-force-hard-reload') > -1) {
1224                                            
1225                                            // Force the page to reload on location change
1226                                            window.location.href = element_href;
1227                                            
1228                                        } else {
1229                                            // Find out if the content of the new page is popup enabled content (popup mode)
1230                                            new_page_popup_mode_enabled = new_page_main_content.indexOf('site-popup-enabled-content') > -1; // Seemed to slow performance: $(new_page_main_content).find('.site-popup-enabled-content').length;
1231                                            new_page_popup_content = (new_page_popup_mode_enabled ?  $('.site-popup-enabled-content', new_page_html_body).html() : '');
1232    
1233    
1234                                            // Find out if the content of the new page can be displayed 'within' the current page (e.g. inner mode)
1235                                            new_page_inner_mode_enabled = new_page_main_content.indexOf('site-ajax-enabled-inner-content') > -1; // $(new_page_main_content).find('.site-ajax-enabled-inner-content').length;
1236                                            new_page_inner_content = (new_page_inner_mode_enabled ?  $('.site-ajax-enabled-inner-content', new_page_html_body).html() : '');
1237                                            
1238                                            
1239                                            // Forced 'inner' mode coming directly from external param passed to load event
1240                                            if (incoming_content_type == 'inner') {
1241                                                if (inner_content_selector && typeof inner_content_selector != 'null' && typeof inner_content_selector != 'undefined') {
1242                                                    //If custom selector is supplied, check for this and load
1243                                                    new_page_inner_mode_enabled = $(new_page_main_content).find(inner_content_selector).length;
1244                                                    new_page_inner_content = (new_page_inner_mode_enabled ?  $(inner_content_selector, new_page_html_body).html() : '');
1245                                                } else {
1246                                                    //Otherwise load entire page
1247                                                    new_page_inner_mode_enabled = true;
1248                                                    new_page_inner_content = (new_page_inner_mode_enabled ?  $(new_page_html_body).html() : '');
1249                                                }
1250                                            } 
1251    
1252                                            new_page_requires_protection = new_page_body_class.indexOf('page-requires-frontend-protection') > -1;
1253                                            new_page_protection_login = (new_page_requires_protection ?  $('#protected_path_login', new_page_html_body).wrap('<div>').parent().html() : '');
1254                                            
1255                                            // Preload images for new page
1256                                            images_to_load_selector = $.pageload.options.preload_images_selector;
1257        
1258                                            // Wait for the images to load
1259                                            if ($(images_to_load_selector, new_page_html_body).length) {
1260                                                if ($.pageload.options.verbose) {
1261                                                    console.log('#########');
1262                                                    console.log('Preloading images:');
1263                                                }
1264        
1265                                                percentCounter = 0;
1266                                                percentIncrements = (100 / $(images_to_load_selector, new_page_html_body).length);
1267        
1268                                                // IMPORTANT: Images to be preloaded must be supplied as a selector string to the 'mutliple_elements' parameter.
1269                                                // Otherwise if you use the normal method the script will go through each of the selector items individually and the 'progress' and 'done' callbacks will NOT be run in one single process.
1270        
1271                                                $(new_page_html_body).pageLoadwaitForImages({
1272                                                        waitForAll: true,
1273                                                        multiple_elements: images_to_load_selector
1274                                                    })
1275                                                    .progress(function(loaded, count, success) {
1276                                                        percentIncrements = (100 / count);
1277                                                        percentCounter = percentCounter + percentIncrements;
1278                                                        var currentPercentage = percentCounter + '%';
1279                                                        $('#loader').css($.pageload.options.loader_orientation, currentPercentage);
1280        
1281                                                        if ($.pageload.options.verbose) {
1282                                                            console.log('#########');
1283                                                            console.log('Status:');
1284                                                            console.log(currentPercentage);
1285                                                        }
1286                                                    })
1287                                                    .done(function() {
1288                                                        if ($.pageload.options.verbose) {
1289                                                            console.log('#########');
1290                                                            console.log('Status:');
1291                                                            console.log('complete');
1292                                                        }
1293                                                        $.pageload.fn.preloader.load_complete();
1294                                                        $.pageload.fn.pages.after_load(new_page_title, new_page_body_class, new_page_html_body, new_page_main_content, new_page_popup_content, target_top_level, element_href, new_page_popup_mode_enabled, new_page_inner_mode_enabled, new_page_inner_content, callback, pushstate, navigation_type, page_scroll_top_value, new_page_requires_protection, new_page_protection_login, new_page_html);
1295                                                    })
1296                                                ;
1297                                            } else {
1298                                                // No images to preload
1299                                                if ($.pageload.options.verbose) {
1300                                                    console.log('#########');
1301                                                    console.log('No images to load');
1302                                                }
1303                                                setTimeout(function() {
1304                                                    $('#loader').css($.pageload.options.loader_orientation, '100%');
1305                                                    $.pageload.fn.preloader.load_complete();
1306                                                    $.pageload.fn.pages.after_load(new_page_title, new_page_body_class, new_page_html_body, new_page_main_content, new_page_popup_content, target_top_level, element_href, new_page_popup_mode_enabled, new_page_inner_mode_enabled, new_page_inner_content, callback, pushstate, navigation_type, page_scroll_top_value, new_page_requires_protection, new_page_protection_login, new_page_html);
1307                                                }, 100);
1308                                            }
1309    
1310                                        }
1311                                    }
1312                                }
1313                            });
1314                        };
1315                        
1316                        // Start loading new page
1317                        pageload_load_new_page(element_href);
1318                    }
1319
1320                },
1321
1322                after_load: function(new_page_title, new_page_body_class, new_page_html_body, new_page_main_content, new_page_popup_content, target_top_level, element_href, new_page_popup_mode_enabled, new_page_inner_mode_enabled, new_page_inner_content, callback, pushstate, navigation_type, page_scroll_top_value, new_page_requires_protection, new_page_protection_login, new_page_html) {
1323
1324                    // Show new page content
1325                    
1326                    if (new_page_popup_mode_enabled && !$('body').hasClass('site-popup-fallback-mode')) { // Skip this 
1326step if we are on a full page where the content usually opens as popup content, continue to open in fallback mode - not in a popup
1327
1328                        // Popup mode content
1329                        
1330                        if ($('body').hasClass('page-popup-active')) {
1331                            // If a popup is already open
1332                            if ($.pageload.options.popup_content_update_url ){
1333                                history.replaceState({'ajaxPageLoad': true}, null, element_href);
1334                            }
1335                            $('body')
1336                                .addClass('page-popup-transition')
1337                                .delay(400)
1338                                .queue(function() {
1339                                    $('#popup_content').html(new_page_popup_content);
1340                                    $.pageload.fn.popup.after_load();
1341                                    $.pageload.fn.preloader.end_ajax();
1342                                    $(this).addClass('page-popup-transition2');
1343                                    $(this).dequeue();
1344                                })
1345                                .delay(10)
1346                                .queue(function() {
1347                                    $(this).removeClass('page-popup-transition page-popup-transition2');
1348                                    $(this).dequeue();
1349                                })
1350                            ;
1351                            // change url used in seo edit screen
1352                            if ($('#cms-frontend-toolbar-seo-admin .seo-tools-btn')) {
1353                                $('#cms-frontend-toolbar-seo-admin .seo-tools-btn').attr("href", element_href)
1354                                try {
1355                                    window.seo.init();
1356                                } catch (error) {
1357                                    console.error(error);
1358                                }
1359                            }
1360                        } else {
1361                            // If there is no existing popup, open a new one
1362                            if ($.pageload.options.popup_content_update_url ){
1363                                $.pageload.previous_url = element_href;
1364                                history.pushState({'ajaxPageLoad': true}, null, element_href);
1365                            }
1366                            // Open the popup
1367                            $.pageload.fn.popup.open(new_page_popup_content);
1368                            // change url used in seo edit screen
1369                            if ($('#cms-frontend-toolbar-seo-admin .seo-tools-btn')) {
1370                                $('#cms-frontend-toolbar-seo-admin .seo-tools-btn').attr("href", element_href)
1371                                if (window.seo && typeof window.seo != 'undefined') {
1372                                    window.seo.init();
1373                                }
1374                            }
1375                        }
1376                        
1377                        if (new_page_title) {
1378                            document.title = new_page_title;
1379                        }
1380                        
1381                        $.pageload.fn.pages.track_pageview(element_href);
1382
1383                    } else if (new_page_inner_mode_enabled && callback) {
1384
1385                        // Inner ajax content mode
1386
1387                        callback(new_page_inner_content, element_href, new_page_main_content);
1388
1389                        $('body')
1390                            .clearQueue()
1391                            .removeClass('ajax-initial-loading')
1392                            .delay(10)
1393                            .queue(function() {
1394                                $(this).dequeue();
1395                            })
1396                        ;
1397
1398                        $.pageload.fn.preloader.end_ajax();
1399                        
1400                        if (pushstate) {
1401                            $.pageload.previous_url = element_href;
1402                            history.pushState({'ajaxPageLoad': true}, null, element_href);
1403                        }
1404
1405                        $.pageload.fn.pages.track_pageview(element_href);
1406
1407                    } else {
1408
1409                        // Standard page content
1410                        if (callback && typeof callback != 'null' && typeof callback != 'undefined') {
1411                            callback();
1412                        }
1413
1414
1415                        if ($.pageload.options.content_load_adjacent) {
1416                            // Content load adjacent loads the content into a duplicate element which is a
1416ppended after the current element
1417                            // This allows two pages to be visible at the same time and transition between them
1418                                // Unbind all events
1419                                $.pageload.options.destroy_after_load();
1420                                $(window).unbind();
1421                                $('#container *, #cms-frontend-toolbar *').unbind().off();
1422                            
1423                            // Clone and build the new objects
1424                                var cloned_content_area = $($.pageload.options.content_area_selector).get(0).cloneNode();
1425                                $($.pageload.options.content_area_selector).addClass('pageload-old-content-area');
1426                                $($.pageload.options.content_area_selector).after(cloned_content_area);
1427                                $($.pageload.options.content_area_selector).filter(':eq(1)').html(new_page_main_content).addClass('pageload-new-content-area');
1428
1429                            // Initialise everything again
1430                                $.pageload.options.init_after_load();
1431
1432                            // Do the page transition
1433                                setTimeout(function() {
1434                                    
1435                                    $.pageload.options.on_page_transition();
1436                                    $('body')
1437                                        .clearQueue()
1438                                        .addClass('page-transition')
1439                                        .removeClass('ajax-initial-loading')
1440                                        .delay($.pageload.options.page_transition_delay)
1441                                        .queue(function() {
1442                                            $(this).addClass('page-transition2');
1443                                            $(this).dequeue();
1444                                        })
1445                                    ;
1446                                }, 50);
1447
1448                            setTimeout(function() {
1449                                $($.pageload.options.content_area_selector).filter(':eq(0)').remove();
1450                                $($.pageload.options.content_area_selector).removeClass('pageload-new-content-area');
1451                            }, $.pageload.options.page_transition_delay);
1452                        }
1453
1454                        if (navigation_type == 'history_change') {
1455                            // If navigation_type has been set as 'history_change', instantly show the content
1456                            $('body')
1457                                .clearQueue()
1458                                .removeClass('ajax-initial-loading')
1459                            ;
1460                        } else {
1461                            // If navigation_type has been set as default, show the page transition effects
1462                            if (!$.pageload.options.content_load_adjacent) {
1463                                $.pageload.options.on_page_transition();
1464                                $('body')
1465                                    .clearQueue()
1466                                    .addClass('page-transition')
1467                                    .removeClass('ajax-initial-loading')
1468                                    .delay($.pageload.options.page_transition_delay)
1469                                    .queue(function() {
1470                                        $(this).addClass('page-transition2');
1471                                        $(this).dequeue();
1472                                    })
1473                                ;
1474                            }
1475                        }
1476
1477                        setTimeout(function() {
1478                            
1479                            // Scroll page to top
1480                            $('html,body').animate(
1481                                {scrollTop: 0},
1482                                0,
1483                                'easeInOutQuad'
1484                            );
1485
1486                            if (!$.pageload.options.content_load_adjacent) {
1487                                // This is done earlier with this option
1488
1489                                // Unbind all events
1490                                $.pageload.options.destroy_after_load();
1491                                $(window).unbind();
1492                                $('#container *, #cms-frontend-toolbar *').unbind().off();
1493                            }
1494
1495                            // Destroy jQuery plugin instances
1496                            $('#slideshow ul, #ig_slideshow, .lists ul li .panel_image_slideshow').cycle('destroy');
1497
1498                            // Update CMS toolbar
1499                            $('#cms-frontend-toolbar').html($('#cms-frontend-toolbar', new_page_html_body).html());
1500                            
1501                            // init axe accessibility audit
1502                            try {
1503                                h.accessibility.axe_automatic_audit()
1504                            } catch(error) {
1505                                console.log(error);
1506                            }
1507                            
1508                            $('#top_nav.navigation ul li').removeClass('active');
1509                            $('#top_nav.navigation ul li a').removeAttr('aria-label');
1510                            $('#top_nav.navigation ul li a' + target_top_level + '').parent().addClass('active');
1511                            var nav_label = $('#top_nav.navigation ul li a' + target_top_level + '').text();
1512                            $('#top_nav.navigation ul li a' + target_top_level + '').attr('aria-label', ( nav_label + ' (current nav item)' ));
1513                            
1514                            
1515
1516                            if ($('body').hasClass('page-transition')) {
1517                                new_page_body_class = new_page_body_class + ' page-transition';
1518                            }
1519                            $('body').attr('class', new_page_body_class);
1520                            
1521                            if (!$.pageload.options.content_load_adjacent) {
1522                                // Adjacent pageload will add the content in an alternative way, see above 
1523                                if ($($.pageload.options.content_area_selector).length) {
1524                                    // console.log('CHANGING HTML')
1525                                    $($.pageload.options.content_area_selector).html(new_page_main_content).css('margin-top', '');
1526                                } else {
1527                                    
1528                                    // Content area does not exist, try to force load the page manually
1529                                    window.location.href = element_href;
1530                                }
1531                            }
1532                            
1533                            // If the page requires protection, add the login form
1534                            
1535                            if (new_page_requires_protection) {
1536                                $('body').append(new_page_protection_login);
1537                            } else {
1538                                if (new_page_body_class.indexOf('page-requires-protection') < 0) {
1539                                    $('#protected_path_login').remove();
1540                                }
1541                            }
1542
1543                            if (pushstate) {
1544                                $.pageload.previous_url = element_href;
1545                                history.pushState({'ajaxPageLoad': true}, null, element_href);
1546                            }
1547                            
1548                            if (new_page_title) {
1549                                document.title = new_page_title;
1550                            }
1551                            
1552                            // Grab pathname data attribute from new page and update it
1553                            var new_page_pathname = (new_page_html.match(/data-pathname=\"(.*?)\"/) ? new_page_html.match(/data-pathname=\"(.*?)\"/)[1] : '')
1554                            if (new_page_pathname) {
1555                                $('body').attr('data-pathname', new_page_pathname);
1556                            } else {
1557                                $('body').attr('data-pathname', window.location.pathname + window.location.search);
1558                            }
1559                            
1560                            $('body').attr('data-page-title', document.title);
1561                            
1562                            if (!$.pageload.options.content_load_adjacent) {
1563                                // This is done earlier with this option
1564                                $.pageload.options.init_after_load();
1565                            }
1566
1567                            if (window.cms_toolbar) {
1568                                window.cms_toolbar.init();
1569                            }
1570
1571                            $.pageload.options.after_load_complete();
1572
1573                            if (!$('body').hasClass('site-generic-overlay-fallback-mode')) {
1574                                $('#overlay-close').trigger('click');
1575                            }
1576                            
1577                            // Scroll page to top
1578                            $('html,body').animate(
1579                                {scrollTop: 0},
1580                                0,
1581                                'easeInOutQuad'
1582                            );
1583
1584                            $(window).trigger('resize');
1585
1586                            $('html,body').scrollTop(page_scroll_top_value);
1587
1588                            $.pageload.fn.preloader.end_ajax();
1589
1590                            $.pageload.fn.pages.track_pageview(element_href);
1591
1592
1593                        }, ($.pageload.options.page_transition_delay));
1594                    }
1595
1596
1597                },
1598
1599                track_pageview: function(element_href) {
1600
1601                    // Track pageview with Analytics if it is installed
1602
1603                    if (window._gaq || window.ga) {
1604                        if (window.ga) {
1605                            // Universal analytics
1606                            ga('send', 'pageview', element_href);
1607                            // Send tracker2 pageview if a secondary tracker has been installed
1608                            ga('tracker2.send', 'pageview', element_href);
1609                            ga('tracker3.send', 'pageview', element_href);
1610                            ga('artlogic_tracker.send', 'pageview', element_href);
1611                        } else if (window._gaq) {
1612                            // Legacy analytics
1613                            _gaq.push(['_trackPageview', element_href]);
1614                        }
1615                    }
1616                    
1617                    // Track pageview with Facebook Pixel if it is installed
1618
1619                    if (typeof window.fbq != 'undefined') {
1620                        if (window.fbq) {
1621                            fbq('track', 'PageView');
1622                        }
1623                    }
1624                }
1625
1626            }
1627        };
1628
1629
1630        // Initialise function
1631
1632        //$(window).ready(function() {
1633            $.pageload.fn.init();
1634        //});
1635
1636    };
1637
1638})(window.jQuery);
1639
1640
1641
1642
1643/**
1644 * jQuery PageLoadWaitForImages
1645 *
1646 * Copyright 2016, Artlogic Media Ltd, http://www.artlogic.net/
1647 */
1648
1649(function (factory) {
1650    if (typeof define === 'function' && define.amd) {
1651        // AMD. Register as an anonymous module.
1652        define(['jquery'], factory);
1653    } else if (typeof exports === 'object') {
1654        // CommonJS / nodejs module
1655        module.exports = factory(require('jquery'));
1656    } else {
1657        // Browser globals
1658        factory(jQuery);
1659    }
1660}(function ($) {
1661    // Namespace all events.
1662    var eventNamespace = 'pageLoadwaitForImages';
1663
1664    // CSS properties which contain references to images.
1665    $.pageLoadwaitForImages = {
1666        hasImageProperties: [
1667            'backgroundImage',
1668            'listStyleImage',
1669            'borderImage',
1670            'borderCornerImage',
1671            'cursor'
1672        ],
1673        hasImageAttributes: ['srcset']
1674    };
1675
1676    // Custom selector to find all `img` elements with a valid `src` attribute.
1677    $.expr[':']['has-src'] = function (obj) {
1678        // Ensure we are dealing with an `img` element with a valid
1679        // `src` attribute.
1680        return $(obj).is('img[src][src!=""]');
1681    };
1682
1683    // Custom selector to find images which are not already cached by the
1684    // browser.
1685    $.expr[':'].uncached = function (obj) {
1686        // Ensure we are dealing with an `img` element with a valid
1687        // `src` attribute.
1688        if (!$(obj).is(':has-src')) {
1689            return false;
1690        }
1691
1692        return !obj.complete;
1693    };
1694
1695    $.fn.pageLoadwaitForImages = function () {
1696
1697        var allImgsLength = 0;
1698        var allImgsLoaded = 0;
1699        var deferred = $.Deferred();
1700
1701        var finishedCallback;
1702        var eachCallback;
1703        var waitForAll;
1704        var multiple_elements;
1705
1706        // Handle options object (if passed).
1707        if ($.isPlainObject(arguments[0])) {
1708
1709            multiple_elements = arguments[0].multiple_elements;
1710            waitForAll = arguments[0].waitForAll;
1711            eachCallback = arguments[0].each;
1712            finishedCallback = arguments[0].finished;
1713
1714        } else {
1715
1716            // Handle if using deferred object and only one param was passed in.
1717            if (arguments.length === 1 && $.type(arguments[0]) === 'boolean') {
1718                waitForAll = arguments[0];
1719            } else {
1720                finishedCallback = arguments[0];
1721                eachCallback = arguments[1];
1722                waitForAll = arguments[2];
1723            }
1724
1725        }
1726
1727        // Handle missing callbacks.
1728        finishedCallback = finishedCallback || $.noop;
1729        eachCallback = eachCallback || $.noop;
1730
1731        // Convert waitForAll to Boolean
1732        waitForAll = !! waitForAll;
1733
1734        // Ensure callbacks are functions.
1735        if (!$.isFunction(finishedCallback) || !$.isFunction(eachCallback)) {
1736            throw new TypeError('An invalid callback was supplied.');
1737        }
1738
1739        this.each(function () {
1740            // Build a list of all imgs, dependent on what images will
1741            // be considered.
1742            if (multiple_elements) {
1743                // If the 'multiple_elements' parameter has been suplied, use this, otherwise use the original element specified
1744                var obj = $(multiple_elements, this);
1745            } else {
1746                var obj = $(this);
1747            }
1748            var allImgs = [];
1749            // CSS properties which may contain an image.
1750            var hasImgProperties = $.pageLoadwaitForImages.hasImageProperties || [];
1751            // Element attributes which may contain an image.
1752            var hasImageAttributes = $.pageLoadwaitForImages.hasImageAttributes || [];
1753            // To match `url()` references.
1754            // Spec: http://www.w3.org/TR/CSS2/syndata.html#value-def-uri
1755            var matchUrl = /url\(\s*(['"]?)(.*?)\1\s*\)/g;
1756
1757            if (waitForAll) {;
1758                // Get all elements (including the original), as any one of
1759                // them could have a background image.
1760                obj.find('*').addBack().each(function () {
1761                    var element = $(this);
1762                    // If an `img` element, add it. But keep iterating in
1763                    // case it has a background image too.
1764
1765                    if (element.is('img:has-src') &&
1766                        !element.is('[srcset]')) {
1767                        allImgs.push({
1768                            src: element.attr('src'),
1769                            element: element[0]
1770                        });
1771                    }
1772
1773                    $.each(hasImgProperties, function (i, property) {
1774                        var propertyValue = element.css(property);
1775                        var match;
1776                        // If it doesn't contain this property, skip.
1777                        if (!propertyValue) {
1778                            return true;
1779                        }
1780
1781                        // Get all url() of this element.
1782                        while (match = matchUrl.exec(propertyValue)) {
1783                            allImgs.push({
1784                                src: match[2],
1785                                element: element[0]
1786                            });
1787                        }
1788                    });
1789
1790                    $.each(hasImageAttributes, function (i, attribute) {
1791                        var attributeValue = element.attr(attribute);
1792                        var attributeValues;
1793
1794                        // If it doesn't contain this property, skip.
1795                        if (!attributeValue) {
1796                            return true;
1797                        }
1798
1799                        allImgs.push({
1800                            src: element.attr('src'),
1801                            srcset: element.attr('srcset'),
1802                            element: element[0]
1803                        });
1804
1805                    });
1806
1807                });
1808            } else {
1809                // For images only, the task is simpler.
1810                obj.find('img:has-src')
1811                    .each(function () {
1812                    allImgs.push({
1813                        src: this.src,
1814                        element: this
1815                    });
1816                });
1817            }
1818
1819            window.setTimeout(function() {
1820                allImgsLength = allImgs.length;
1821                allImgsLoaded = 0;
1822
1823
1824                if (allImgsLength === 0) {
1825                    finishedCallback.call(obj[0]);
1826                    deferred.resolveWith(obj[0]);
1827                }
1828
1829                $.each(allImgs, function (i, img) {
1830
1831                    var image = new Image();
1832                    var events =
1833                      'load.' + eventNamespace + ' error.' + eventNamespace;
1834
1835                    // Handle the image loading and error with the same callback.
1836                    $(image).one(events, function me (event) {
1837                        // If an error occurred with loading the image, set the
1838                        // third argument accordingly.
1839                        var eachArguments = [
1840                            allImgsLoaded,
1841                            allImgsLength,
1842                            event.type == 'load'
1843                        ];
1844                        allImgsLoaded++;
1845
1846                        eachCallback.apply(img.element, eachArguments);
1847                        deferred.notifyWith(img.element, eachArguments);
1848
1849                        // Unbind the event listeners. I use this in addition to
1850                        // `one` as one of those events won't be called (either
1851                        // 'load' or 'error' will be called).
1852                        $(this).off(events, me);
1853
1854                        if (allImgsLoaded == allImgsLength) {
1855                            finishedCallback.call(obj[0]);
1856                            deferred.resolveWith(obj[0]);
1857                            return false;
1858                        }
1859
1860                    });
1861
1862                    if (img.srcset) {
1863                        image.srcset = img.srcset;
1864                    }
1865                    image.src = img.src;
1866                });
1867            }, 0);
1868        });
1869
1870        return deferred.promise();
1871
1872    };
1873}));

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.