PageSourceSearch

https://www.metlifepetinsurance.com/content/dam/metlifecom/us/metl…article-listing-pagination-broken/pagfix.js

js metlifepetinsurance.com collected 2026-09-24 20:06:12 UTC 46,725 bytes, 899 lines download raw bytes

1(function() {
2  // Wait for document ready
3  $(document).ready(function() {
4    // First, try to "destroy" or disable the existing module
5    if (window.ArticleListingModule) {
6      // If there's a destroy method, call it
7      if (typeof window.ArticleListingModule.destroy === 'function') {
8        window.ArticleListingModule.destroy();
9      }
10      
11      // Unbind all event handlers from relevant elements
12      $(".article-listing.component .pagination-item-input").off();
13      $(".article-listing.component .pagination-left").off();
14      $(".article-listing.component .pagination-right").off();
15      $(".article-listing.component .total-pag-num").off();
16      $(".article-listing.component .js-dropdown-sort").off();
17      $(".article-listing.component .filter-sort-clear").off();
18      $(".article-listing.component .filter-sort-submit").off();
19      $(".article-listing.component .show-more-button").off();
20      
21		// Remove the original module from the global scope
22		window.ArticleListingModule = null;
23   
24    
25		// Now create a new module with your fixed code
26		window.ArticleListingModule = (function() {
27      var articleListing = $(".article-listing.component");
28    var isRTL = false;
29    var firstRun = true;
30    var searchPaginationNumber;
31    var desktopCountElement = $(".article-listing.component").find("[data-desktop-count]");
32    var deviceCountElement = $(".article-listing.component").find("[data-device-count]");
33    var searchListCount = UtilityModule.getViewport() === "desktop"
34        ? (desktopCountElement.length && desktopCountElement.data("desktop-count")) || 15
35        : (deviceCountElement.length && deviceCountElement.data("device-count")) || 10;
36    if ($("body[dir]").attr("dir") === "rtl") {
37        isRTL = true;
38    }
39
40    var totalArticles;
41
42    // Fetch articles
43    function fetchArticleList(parent, fetchType, showAll) {
44        const contentChangeText = parent.find(".content-changed").data("text");
45        const config = getArticleConfig(parent);
46        const postData = buildPostData(parent, fetchType, showAll);
47
48        // Return a Promise
49        return new Promise((resolve, reject) => {
50            $.ajax({
51                url: config.serviceUrl,
52                type: 'GET',
53                data: postData,
54                dataType: 'json',
55                success: function(response) {
56                    handleSuccessResponse(parent, response, fetchType, showAll, contentChangeText);
57                    resolve(response); // Resolve the promise when done
58                },
59                error: function(error) {
60                    console.error("Error while fetching articles");
61                    handleNoResults(parent);
62                    reject(error); // Reject the promise on error
63                }
64            });
65        });
66    }
67
68    function getArticleConfig(parent) {
69        return {
70            disableImage: parent.find("[data-disable-image]").attr("data-disable-image") === "true",
71            disableDate: parent.find("[data-disable-date]").attr("data-disable-date") === "true",
72            disableDescription: parent.find("[data-disable-description]").attr("data-disable-description") === "true",
73            disableAuthor: parent.find("[data-disable-author]").attr("data-disable-author") === "true",
74            disableRead: parent.find("[data-disable-read]").attr("data-disable-read") === "true",
75            disableCategory: parent.find("[data-disable-category]").attr("data-disable-category") === "true",
76            disableSort: parent.find("[data-disable-sort]").attr("data-disable-sort") === "true",
77            serviceUrl: parent.find("[data-fetch-article-list-url]").attr("data-fetch-article-list-url"),
78            dataArticleConfig: parent.find("[data-fetch-article-config]").attr("data-fetch-article-config"),
79            dataArticleConfigTaxonomy: parent.find("[data-fetch-article-config-taxonomy]").attr("data-fetch-article-config-taxonomy")
80        };
81    }
82
83    function buildPostData(parent, fetchType, showAll) {
84        const config = getArticleConfig(parent);
85        const sortValues = getSortValue(parent);
86
87        const postData = {
88            articleDataConfig: config.dataArticleConfig || "",
89            sortby: sortValues.sortby,
90            dateSort: sortValues.dateSort
91        };
92
93        const articleFilters = buildArticleFilters(parent);
94        if (articleFilters) {
95            postData.articleFilters = articleFilters;
96        }
97
98        setFetchNumbers(postData, parent, fetchType, showAll);
99
100        if (config.dataArticleConfigTaxonomy) {
101            postData.articleDataTaxonomy = config.dataArticleConfigTaxonomy;
102        }
103        return postData;
104    }
105
106
107    function getSortValue(parent) {
108        const config = getArticleConfig(parent);
109        if (config.disableSort) {
110            return {
111                sortby: 'newest',
112                dateSort: "descending"
113            };
114        }
115        const sortValue = parent.find(".js-dropdown-sort").val();
116        if (sortValue === 'newest') {
117            return {
118                sortby: 'newest',
119                dateSort: "descending"
120            };
121        }
122        if (sortValue === 'oldest') {
123            return {
124                sortby: 'oldest',
125                dateSort: "ascending"
126            };
127        }
128        return {
129            sortby: sortValue,
130            dateSort: ""
131        };
132    }
133
134    function buildArticleFilters(parent) {
135        const filters = [];
136        const authorFilter = parent.find(".js-dropdown-author").val();
137        const categoryFilter = parent.find(".js-dropdown-category").val();
138        const yearFilter = parent.find(".js-dropdown-year").val();
139        const monthFilter = parent.find(".js-dropdown-month").val();
140
141        if (authorFilter && authorFilter.length) {
142            filters.push(`(@byName = '${authorFilter.join("' or @byName = '")}')`);
143        }
144
145        if (categoryFilter && categoryFilter.length) {
146            filters.push(`(@cq:tags = '${categoryFilter.join("' or @cq:tags = '")}')`);
147        }
148
149        if (yearFilter && yearFilter.length) {
150            filters.push(`(${yearFilter.map(year => `jcr:like(@publishedDate,'${year}-%')`).join(" or ")})`);
151        }
152
153        if (monthFilter && monthFilter.length) {
154            filters.push(`(${monthFilter.map(month => `jcr:like(@publishedDate,'%-${month}-%')`).join(" or ")})`);
155        }
156        return filters.length ? `[(${filters.join(" or ")})]` : "";
157    }
158
159    function setFetchNumbers(postData, parent, fetchType, showAll) {
160        const isDesktop = UtilityModule.getViewport() === "desktop";
161        const desktopCountElement = parent.find("[data-desktop-count]");
162        const deviceCountElement = parent.find("[data-device-count]");
163        const articlesPerPage = isDesktop
164            ? (desktopCountElement.length && desktopCountElement.data("desktop-count")) || 15
165            : (deviceCountElement.length && deviceCountElement.data("device-count")) || 10;
166        switch (fetchType) {
167            case "fetch-new":
168                postData.startArticleNum = "0";
169                postData.endArticleNum = showAll ? totalArticles : articlesPerPage.toString();
170                break;
171            case "fetch-more":
172                postData.startArticleNum = parent.find("[data-fetch-article-start-num]").attr("data-fetch-article-start-num");
173                postData.endArticleNum = parent.find("[data-fetch-article-end-num]").attr("data-fetch-article-end-num");
174                break;
175            case "fetch-pagination":
176                const currentPage = parseInt(parent.find(".pagination-item-input").val()) || 1;
177                postData.startArticleNum = ((currentPage - 1) * articlesPerPage + 1).toString();
178                postData.endArticleNum = articlesPerPage;
179                break;
180        }
181    }
182
183    function handleSuccessResponse(parent, response, fetchType, showAll, contentChangeText) {
184        if (response.articles && response.articles.length > 0) {
185            totalArticles = response.articleSize;
186            const resultsHTML = buildResultsHTML(parent, response, getArticleConfig(parent));
187            updateArticleList(parent, resultsHTML, fetchType);
188            updatePagination(parent, response.articleSize, fetchType, showAll);
189            updateResultsDisplay(parent, response.articleSize, showAll, fetchType, response.articles.length);
190            parent.find(".content-changed").text(contentChangeText);
191            setTimeout(() => parent.find(".content-changed").text(""), 1500);
192            if (fetchType === "fetch-pagination") {
193                scrollToMiddleOfPage(parent.find(".article-listing--content__wrapper"));
194                parent.find(".article-listing--content__wrapper").first();
195
196                // Find the first .article-list-item and focus the a inside it
197                const firstArticleItem = parent.find(".article-list-item").first();
198                firstArticleItem.find("a").focus();
199            }
200
201            parent.find(".article-listing--content__wrapper-noresults").addClass("d-none");
202            parent.find(".article-listing--content__action-container").removeClass("d-none");
203            parent.find(".article-listing--content__wrapper-noresults").attr("aria-hidden", "true");
204            parent.find(".article-listing--content__action-container").attr("aria-hidden", "false");
205
206            // Hide pagination and 'show more' button if there aren't enough articles
207            const isDesktop = UtilityModule.getViewport() === "desktop";
208            const articleLimit = isDesktop ? 15 : 10;
209            if (response.articleSize <= articleLimit || showAll) {
210                parent.find(".show-more-section, .article-listing__pagination--wrapper").addClass("d-none").attr("aria-hidden", "true");
211            } else if (parent.find(".results_pagination").length > 0) {
212                paginationInit(response.articleSize, parent);
213            }
214
215        } else {
216            handleNoResults(parent);
217        }
218    }
219
220    // Function to scroll the element to the middle of the page
221    function scrollToMiddleOfPage(element) {
222        const elementTop = element.offset().top;
223        const windowHeight = $(window).height();
224        const scrollPosition = elementTop - (windowHeight / 2);
225        $('html, body').animate({
226            scrollTop: scrollPosition
227        }, 500);
228    }
229
230    function handleNoResults(parent) {
231        parent.find(".article-listing--content__wrapper-noresults").removeClass("d-none");
232        parent.find(".article-listing--content__action-container").addClass("d-none");
233        parent.find(".article-listing--content__wrapper-noresults").attr("aria-hidden", "false");
234        parent.find(".article-listing--content__action-container").attr("aria-hidden", "true");
235
236        // Clear any existing articles
237        parent.find(".article-list-wrapper").html("");
238
239        // Hide pagination and 'show more' button
240        parent.find(".show-more-section").addClass("d-none").attr("aria-hidden", "true");
241
242        // Update the results display
243        parent.find(".current-count").text("0 " + parent.find(".total-count").attr("data-results-text"));
244        parent.find(".total-count").addClass("d-none").attr("aria-hidden", "true");
245    }
246
247    function buildResultsHTML(parent, response, config) {
248        return response.articles.map(article => `
249        <div class="col-12 col-sm-6 col-md-4 article-list-item">
250            <div class='article-list-section-content'>
251                ${!config.disableImage ? `
252                    <div class="article-list-item-bg">
253                        <div class="article-list-item-bg-container">
254                            <div class="bg" style="background-image: url('${article.imageThumbnail}')"></div>
255                        </div>
256                    </div>
257                ` : ''}
258                <div class='article-list-section-content-wrapper ${config.disableImage ? 'image' : ''} ${config.disableDate ? 'date' : ''} ${config.disableAuthor ? 'author' : ''}'>
259                    ${buildEyebrow(article, config)}
260                    <a href='${article.path}' target="${parent.attr("data-target-dynamic")}">
261                        <div class="article-list-item-headline">${article.headlineTitle}</div>
262                    </a>
263                    ${!config.disableDescription ? `<div class='article-list-section-description'>${article.description}</div>` : ''}
264                    ${buildFooter(article, config)}
265                </div>
266            </div>
267        </div>
268    `).join('');
269    }
270
271    function buildEyebrow(article, config) {
272        if (config.disableAuthor && config.disableDate) return '';
273        return `
274        <div class='article-list-section-eyebrow'>
275            ${!config.disableAuthor && article.byName ? `
276                <span class="article-list-item-author">${article.byName}</span>
277                <span aria-hidden='true'>·</span>
278            ` : ''}
279            ${!config.disableDate ? `
280                <span class="article-list-item-publishedDate ${config.disableAuthor ? 'no-author' : ''}">${article.publishedDate}</span>
281            ` : ''}
282        </div>
283    `;
284    }
285
286    function buildFooter(article, config) {
287        if ((article.tags == null || config.disableCategory) && (article.readTime == null || config.disableRead)) return '';
288
289        const formatTags = (tags) => {
290            if (typeof tags === 'string') {
291                // Remove the "{tagPath=}" wrapper and any commas
292                return tags.replace(/^\{tagPath=|\}$/g, '').replace(/,/g, '').trim();
293            } else if (Array.isArray(tags)) {
294                return tags.map(tag => tag.replace(/^\{tagPath=|\}$/g, '').trim()).join(', ');
295            } else if (typeof tags === 'object') {
296                return Object.values(tags).map(tag => tag.replace(/^\{tagPath=|\}$/g, '').trim()).join(', ');
297            }
298            return '';
299        };
300
301        return `
302        <div class='article-list-section-footer'>
303            ${article.tags && !config.disableCategory ? `
304                <span class="article-list-item-category">${formatTags(article.tags)}</span>
305            ` : ''}
306            ${article.readTime && !config.disableRead ? `
307                <span class="article-list-item-readTime">${article.readTime}</span>
308            ` : ''}
309        </div>
310    `;
311    }
312
313    function updateArticleList(parent, resultsHTML, fetchType) {
314        const articleListWrapper = parent.find(".article-list-wrapper");
315        if (fetchType === "fetch-new") {
316            articleListWrapper.html(resultsHTML);
317        } else if (fetchType === "fetch-pagination") {
318            articleListWrapper.empty().html(resultsHTML);
319        } else {
320            articleListWrapper.append(resultsHTML);
321        }
322        parent.find(".article-list-item").removeAttr("aria-hidden");
323        parent.find(".article-list-item a").removeAttr("tabindex");
324    }
325
326    function updatePagination(parent, articleSize, fetchType, showAll) {
327        const isDesktop = UtilityModule.getViewport() === "desktop";
328        const desktopCountElement = parent.find("[data-desktop-count]");
329        const deviceCountElement = parent.find("[data-device-count]");
330        const articleLimit = isDesktop
331            ? (desktopCountElement.length && desktopCountElement.data("desktop-count")) || 15
332            : (deviceCountElement.length && deviceCountElement.data("device-count")) || 10;
333        const articleStart = isDesktop
334            ? ((desktopCountElement.length && desktopCountElement.data("desktop-count") + 1) || 16)
335            : ((deviceCountElement.length && deviceCountElement.data("device-count") + 1) || 11);
336        const articleEnd = "6";
337        const articleEndNoMoreResults = isDesktop
338            ? (desktopCountElement.length && desktopCountElement.data("desktop-count")) || 15
339            : (deviceCountElement.length && deviceCountElement.data("device-count")) || 10;
340
341        const startNum = parseInt(parent.find("[data-fetch-article-start-num]").attr("data-fetch-article-start-num"));
342
343        // Set a flag to indicate if we've reached the end of the articles
344        let reachedEnd;
345
346        if (fetchType === "fetch-new") {
347            // For new fetches, we've only reached the end if the total articles is less than or equal to the initial limit
348            reachedEnd = articleSize <= articleLimit;
349        } else {
350            // For subsequent fetches, check if we're near the end
351            reachedEnd = articleSize < startNum + 6 || articleSize <= articleLimit;
352        }
353
354        if (fetchType === "fetch-new") {
355            if (articleSize > articleLimit && !showAll) {
356                parent.find(".show-more-section").removeClass("d-none").attr("aria-hidden", "false");
357                parent.find("[data-fetch-article-start-num]").attr("data-fetch-article-start-num", articleStart);
358                parent.find("[data-fetch-article-end-num]").attr("data-fetch-article-end-num", articleEnd);
359            } else {
360                parent.find(".show-more-section").addClass("d-none").attr("aria-hidden", "true");
361                parent.find("[data-fetch-article-start-num]").attr("data-fetch-article-start-num", "0");
362                parent.find("[data-fetch-article-end-num]").attr("data-fetch-article-end-num", articleEndNoMoreResults);
363            }
364        } else if (fetchType === "fetch-more") {
365            if (articleSize >= startNum + 6) {
366                parent.find(".show-more-section").removeClass("d-none").attr("aria-hidden", "false");
367                parent.find("[data-fetch-article-start-num]").attr("data-fetch-article-start-num", startNum + 6);
368            } else {
369                parent.find(".show-more-section").addClass("d-none").attr("aria-hidden", "true");
370            }
371        } else if (fetchType === "fetch-pagination") {
372            parent.find("[data-fetch-article-start-num]").attr("data-fetch-article-start-num", startNum + articleLimit);
373        }
374
375        // Set a data attribute to indicate if we've reached the end
376        parent.attr("data-reached-end", reachedEnd);
377    }
378
379    function updateResultsDisplay(parent, articleSize, showAll, fetchType) {
380        const showingText = parent.find(".current-count").attr("data-showing-text");
381        const isDesktop = UtilityModule.getViewport() === "desktop";
382        const desktopCountElement = parent.find("[data-desktop-count]");
383        const deviceCountElement = parent.find("[data-device-count]");
384        const articlesPerPage = isDesktop
385            ? (desktopCountElement.length && desktopCountElement.data("desktop-count")) || 15
386            : (deviceCountElement.length && deviceCountElement.data("device-count")) || 10;
387        const hasPagination = parent.find(".results_pagination").length > 0;
388
389        if (showAll) {
390            displayAllResults(parent, articleSize, showingText);
391        } else if (hasPagination) {
392            const currentPage = parseInt(parent.find(".pagination-item-input").val()) || 1;
393            const startIndex = (currentPage - 1) * articlesPerPage + 1;
394            const endIndex = Math.min(currentPage * articlesPerPage, articleSize);
395            displayPaginationResults(parent, articleSize, showingText, startIndex, endIndex);
396        } else {
397            const showingCount = fetchType === "fetch-more" ?
398                parent.find(".article-list-item").length :
399                (isDesktop ? parent.find(".current-count").attr("data-desktop-count") : parent.find(".current-count").attr("data-device-count"));
400            displayPartialResults(parent, articleSize, showingText, showingCount);
401        }
402    }
403
404    function displayAllResults(parent, articleSize, showingText) {
405        parent.find(".show-more-section, .total-count").addClass("d-none").attr("aria-hidden", "true");
406        const resultText = isRTL ?
407            `${parent.find(".total-count").attr("data-results-text")} ${articleSize} ${showingText}` :
408            `${showingText} ${articleSize} ${parent.find(".total-count").attr("data-results-text")}`;
409        parent.find(".current-count").text(resultText);
410    }
411
412    function displayPaginationResults(parent, articleSize, showingText, startIndex, endIndex) {
413        const ofText = parent.find(".current-count").attr("data-of-text");
414        const resultsText = parent.find(".total-count").attr("data-results-text");
415
416        const currentText = isRTL ?
417            `${resultsText} ${articleSize} ${ofText} ${endIndex} - ${startIndex} ${showingText}` :
418            `${showingText} ${startIndex} - ${endIndex} ${ofText} ${articleSize} ${resultsText}`;
419
420        const reachedEnd = parent.attr("data-reached-end") === "true";
421        parent.find(".show-more-section").removeClass("d-none").attr("aria-hidden", "false");
422        if (reachedEnd && articleSize <= searchListCount) {
423            displayAllResults(parent, articleSize, showingText);
424        } else {
425            parent.find(".current-count").text(currentText);
426            parent.find(".total-count").addClass("d-none").attr("aria-hidden", "true");
427        }
428
429        parent.find(".show-more-section").removeClass("d-none").attr("aria-hidden", "false");
430
431        const ariaLabel = parent.find(".total-count").attr("data-aria-label");
432        parent.find(".current-count").attr("aria-label", `${currentText} ${ariaLabel}`);
433    }
434
435    function displayPartialResults(parent, articleSize, showingText, showingCount) {
436        const ofText = parent.find(".current-count").attr("data-of-text");
437        const currentText = isRTL ?
438            `${ofText} ${showingCount} ${showingText} `:
439            `${showingText} ${showingCount} ${ofText} `;
440        parent.find(".current-count").text(currentText);
441        parent.find(".total-count").text(`${articleSize} ${parent.find(".total-count").attr("data-results-text")}`);
442
443        // Check if we've reached the end of the articles
444        const reachedEnd = parent.attr("data-reached-end") === "true";
445
446        if (reachedEnd) {
447            parent.find(".show-more-section").addClass("d-none").attr("aria-hidden", "true");
448            displayAllResults(parent, articleSize, showingText);
449        } else {
450            parent.find(".show-more-section").removeClass("d-none").attr("aria-hidden", "false");
451            parent.find(".total-count").removeClass("d-none").attr("aria-hidden", "false");
452        }
453
454        const ariaLabel = parent.find(".total-count").attr("data-aria-label");
455        parent.find(".total-count").attr("aria-label", `${currentText}${articleSize} ${parent.find(".total-count").attr("data-results-text")} ${ariaLabel}`);
456    }
457
458    //Pagination
459    function paginationInit(totalSearchResults, $parent) {
460        if (totalSearchResults <= searchListCount) {
461            $parent.find('.total-count').removeClass('d-none');
462            $parent.find('.results_pagination').addClass('d-none hidden').attr("aria-hidden", "true");
463            $parent.find('.total-pag-num span').html(1);
464            $parent.find('pagination-item-input').attr('data-max-val', 1);
465        } else {
466            var totalPage = Math.ceil(totalSearchResults / searchListCount);
467            if (totalPage > 1200) {
468                totalPage = 1200;
469                totalSearchResults = 1200 * searchListCount;
470            }
471            $parent.find('.total-count').removeClass('d-none');
472            $parent.find('.total-count').html('&nbsp;' + totalSearchResults);
473            $parent.find('.results_pagination').removeClass('d-none hidden').attr("aria-hidden", "false");
474            $parent.find(".pagination-right").removeClass("disabled");
475            $parent.find('.total-pag-num span').html(totalPage);
476            $parent.find('.pagination-item-input').attr('data-max-val', totalPage);
477        }
478        // Get original aria-label and of-text
479        const originalAriaLabel = $parent.find('.total-pag-num').data('aria');
480        const ofText = $parent.find('.of-text').text();
481
482        // Update aria-label with page numbers
483        $parent.find('.total-pag-num').attr('aria-label',
484            `${originalAriaLabel} ${totalPage} ${ofText} ${totalPage}`
485        );
486        if (searchPaginationNumber === 0) {
487            $parent.find('.pagination-item-input').val(1);
488        }
489    }
490
491      return {
492          init: function() {
493            $(window).on("load", function() {
494                articleListing.each(function() {
495                    var parent = $(this);
496                    if ((parent.isOnScreen() || parent.hasClass("author")) && firstRun === true) {
497                        firstRun = false;
498                        fetchArticleList(parent, "fetch-new", false);
499                    }
500                });
501            });
502
503            $(window).on("scroll", function() {
504                if (firstRun === true) {
505                    articleListing.each(function() {
506                        var parent = $(this);
507                        if (parent.isOnScreen()) {
508                            firstRun = false;
509                            fetchArticleList(parent, "fetch-new", false);
510                        }
511                    });
512                }
513            });
514
515            $(window).on("load", function() {
516                try {
517                    const dropdownContainer = document.querySelector('.article-listing .dropdown.sort-selector');
518                    const selectElement = dropdownContainer?.querySelector('.js-dropdown-sort');
519                    const $selectElement = $(".article-listing .js-dropdown-sort");
520
521                    if (selectElement && $selectElement.length) {
522                        const selectWidth = $selectElement.outerWidth();
523                        if (selectWidth) {
524                            selectElement.style.width = `${selectWidth + 16}px`;
525                        }
526                    }
527                } catch (error) {
528                    console.warn('Error adjusting dropdown width:', error);
529                }
530            });
531
532            $(window).on("load resize", function() {
533                if (UtilityModule.getViewport() === "desktop") {
534                    articleListing.find(".filters-desktop").attr("aria-hidden", "false");
535                    articleListing.find(".filters-device").attr("aria-hidden", "true");
536                } else {
537                    articleListing.find(".filters-device").attr("aria-hidden", "false");
538                    articleListing.find(".filters-desktop").attr("aria-hidden", "true");
539                }
540            });
541
542            // Filter Desktop Clear
543            articleListing.find(".dropdown .filter-sort-clear").on("click", function(evt) {
544                var parent = $(this).closest(".dropdown");
545                DropDown.filterClear(evt, parent);
546                fetchArticleList($(this).closest(".article-listing.component"), "fetch-new", false);
547            }).on("keydown", function(evt) {
548                if (evt.keyCode === 13 || evt.keyCode === 32) {
549                    evt.preventDefault();
550                    $(this)[0].click();
551                }
552            });
553
554            // Filters Change
555            articleListing.find(".js-dropdown-sort").on("change", function(evt) {
556                var parent = $(this).closest(".article-listing.component");
557                $(this).closest(".dropdown").addClass("filled");
558                parent.find(".showingResults").removeClass("d-none");
559                parent.find(".show-more-button").removeClass("d-none");
560                parent.find(".article-list-item").remove();
561                fetchArticleList(parent, "fetch-new", false);
562            });
563
564            // Filters Submit
565            articleListing.find(".filter-sort-submit").on("click", function(evt) {
566                var parent = $(this).closest(".article-listing.component");
567                if ($(this).parent(".article-listing__filters--overlay-footer").length > 0) {
568                    DropDown.filterSubmit($(this), evt, $(this).closest(".component").find(".article-listing__filters-toggle"), false);
569                } else {
570                    DropDown.filterSubmit($(this).closest(".dropdown"), evt, $(this).closest(".dropdown").find(".dropdown__wrapper--select-input"), true);
571                }
572                parent.find(".showingResults").removeClass("d-none");
573                parent.find(".show-more-button").removeClass("d-none");
574                parent.find(".article-list-item").remove();
575                fetchArticleList(parent, "fetch-new", false);
576            }).on("keydown", function(evt) {
577                if (evt.keyCode === 13 || evt.keyCode === 32) {
578                    evt.preventDefault();
579                    $(this)[0].click();
580                }
581            });
582
583            // Overlay Filter Device Overlay Clear
584            articleListing.find(".article-listing__filters--overlay-container .filter-sort-clear").on("click", function(evt) {
585                var articleListing = $(this).closest(".article-listing.component");
586                var parent = $(this).closest(".article-listing__filters--overlay-container");
587                articleListing.find(".dropdown.multiple").each(function() {
588                    DropDown.filterClear(evt, $(this));
589                });
590                parent.find("input").each(function() {
591                    if ($(this).prop("checked") === true) {
592                        $(this).prop("checked", false);
593                        $(this).attr("aria-checked", false);
594                    }
595                });
596                fetchArticleList($(this).closest(".article-listing.component"), "fetch-new", false);
597            }).on("keydown", function(evt) {
598                if (evt.keyCode === 13 || evt.keyCode === 32) {
599                    evt.preventDefault();
600                    $(this)[0].click();
601                }
602            });
603
604            // Overlay Filter Device Submit Close Overylay
605            articleListing.find(".article-listing__filters--overlay .filter-sort-submit").on("click", function(evt) {
606                var parent = $(this).closest(".article-listing.component");
607                parent.find(".article-listing__filters--overlay").addClass("d-none").attr("aria-hidden", true);
608                UtilityModule.closeModal(parent.find(".article-listing__filters--overlay"));
609                parent.find(".article-listing__filters-toggle").focus();
610            }).on("keydown", function(evt) {
611                if (evt.keyCode === 13 || evt.keyCode === 32) {
612                    evt.preventDefault();
613                    $(this)[0].click();
614                }
615            });
616
617            // Overlay Filter Device Overlay Close
618            articleListing.find(".article-listing__filters__close button").on("click", function() {
619                var parent = $(this).closest(".article-listing.component");
620                parent.find(".article-listing__filters--overlay").addClass("d-none").attr("aria-hidden", true);
621                UtilityModule.closeModal(parent.find(".article-listing__filters--overlay"));
622                parent.find(".article-listing__filters-toggle").focus();
623            }).on("keydown", function(evt) {
624                if (evt.keyCode === 13 || evt.keyCode === 32) {
625                    evt.preventDefault();
626                    $(this)[0].click();
627                }
628            });
629
630            // Overlay Filter Device Open
631            articleListing.find(".article-listing__filters-toggle").on("click", function() {
632                var parent = $(this).closest(".article-listing.component");
633                parent.find(".article-listing__filters--overlay").removeClass("d-none").attr("aria-hidden", false);
634                UtilityModule.openModal(parent.find(".article-listing__filters--overlay"));
635                parent.find(".article-listing__filters--overlay .article-listing__filters__close button").focus();
636            }).on("keydown", function(evt) {
637                if (evt.keyCode === 13 || evt.keyCode === 32) {
638                    evt.preventDefault();
639                    $(this)[0].click();
640                }
641            });
642
643            // Overlay Filter Device Checkbox Click
644            articleListing.find('fieldset input[type="checkbox"]').on("change", function(evt) {
645                evt.preventDefault();
646                var parent = $(this).closest(".article-listing.component");
647                if (UtilityModule.getViewport() !== "desktop") {
648                    var group = $(this).closest("fieldset").attr('data-group');
649                    parent.find("li[data-selected-text='" + group + "']").attr('aria-selected', 'false');
650                }
651                var thisVale = $(this).val();
652                parent.find(".dropdown.pills-dropdown li[data-value='" + thisVale + "']").attr('aria-selected', $(this).prop("checked"));
653                parent.find(".dropdown.pills-dropdown option[value='" + thisVale + "']").prop("selected", $(this).prop("checked"));
654            }).on("keydown", function(evt) {
655                if (evt.keyCode === 13 || evt.keyCode === 32) {
656                    evt.preventDefault();
657                    $(this)[0].click();
658                }
659            });
660
661            // "show more" button click handler
662            articleListing.find(".show-more-button").on("click", function() {
663                var parent = $(this).closest(".article-listing.component");
664                fetchArticleList(parent, "fetch-more", false);
665            }).on("keydown", function(evt) {
666                if (evt.keyCode === 13 || evt.keyCode === 32) {
667                    evt.preventDefault();
668                    $(this)[0].click();
669                }
670            });
671
672            // load all articles
673            articleListing.find(".total-count").on("click", function() {
674                var parent = $(this).closest(".article-listing.component");
675                fetchArticleList(parent, "fetch-new", true);
676            }).on("keydown", function(evt) {
677                if (evt.keyCode === 13 || evt.keyCode === 32) {
678                    evt.preventDefault();
679                    $(this)[0].click();
680                }
681            });
682
683            //Scroll To Top
684            articleListing.find(".backTopTop button").on("click", function() {
685                var parent = $(this).closest(".article-listing.component");
686                $('html, body').animate({
687                    scrollTop: parent.offset().top - 70
688                }, 1);
689            }).on("keydown", function(evt) {
690                if (evt.keyCode === 13 || evt.keyCode === 32) {
691                    evt.preventDefault();
692                    $(this)[0].click();
693                }
694            });
695
696            //List View
697            articleListing.find(".icon-search-list").on("click", function() {
698                var parent = $(this).closest(".article-listing.component");
699                parent.addClass("list-view");
700                parent.removeClass("grid-view");
701                parent.find(".icon-search-list").addClass("d-none");
702                parent.find(".icon-search-list").attr("aria-pressed", false).attr("aria-hidden", true);
703                parent.find(".icon-search-grid").removeClass("d-none");
704                parent.find(".icon-search-grid").attr("aria-pressed", true).attr("aria-hidden", false);
705                parent.find(".icon-search-grid").focus();
706            }).on("keydown", function(evt) {
707                if (evt.keyCode === 13 || evt.keyCode === 32) {
708                    evt.preventDefault();
709                    $(this)[0].click();
710                }
711            });
712            //Grid View
713            articleListing.find(".icon-search-grid").on("click", function() {
714                var parent = $(this).closest(".article-listing.component");
715                parent.removeClass("list-view");
716                parent.addClass("grid-view");
717                parent.find(".icon-search-list").removeClass("d-none");
718                parent.find(".icon-search-list").attr("aria-pressed", true).attr("aria-hidden", false);
719                parent.find(".icon-search-grid").addClass("d-none");
720                parent.find(".icon-search-grid").attr("aria-pressed", false).attr("aria-hidden", true);
721                parent.find(".icon-search-list").focus();
722            }).on("keydown", function(evt) {
723                if (evt.keyCode === 13 || evt.keyCode === 32) {
724                    evt.preventDefault();
725                    $(this)[0].click();
726                }
727            });
728
729            //Pagination
730            articleListing.find(".pagination-item-input").on("input", function(e) {
731                e.preventDefault();
732                var parent = $(this).closest(".article-listing.component");
733                var currentVal = $(this).val();
734                var maxVal = parseInt($(this).attr('data-max-val'));
735
736                if (currentVal.length > 0) {
737                    var regextTest = new RegExp("^\\d+$");
738                    if (!regextTest.test(currentVal)) {
739                        $(this).val(currentVal.slice(0, -1));
740                        return;
741                    }
742
743                    var pageNum = parseInt(currentVal);
744
745                    if (pageNum > maxVal) {
746                        pageNum = maxVal;
747                    } else if (pageNum < 1) {
748                        pageNum = 1;
749                    }
750
751                    $(this).val(pageNum);
752                    $(this).attr("data-current-page", pageNum);
753
754                    // Update button states
755                    parent.find(".total-pag-num").removeClass("disabled").attr("aria-disabled","false").attr("tabindex","0");
756                    if (pageNum === 1) {
757                        parent.find(".pagination-left").addClass("disabled").attr("aria-disabled","true").attr("tabindex","-1");
758                        parent.find(".pagination-right").removeClass("disabled").attr("aria-disabled","false").attr("tabindex","0");
759                    } else if (pageNum === maxVal) {
760                        parent.find(".pagination-left").removeClass("disabled").attr("aria-disabled","false").attr("tabindex","0");
761                        parent.find(".pagination-right").addClass("disabled").attr("aria-disabled","true").attr("tabindex","-1");
762                        parent.find(".total-pag-num").addClass("disabled").attr("aria-disabled","true").attr("tabindex","0");
763                    } else {
764                        parent.find(".pagination-left, .pagination-right").removeClass("disabled").attr("aria-disabled","false").attr("tabindex","0");
765                    }
766
767                    parent.find(".pagination-left").attr("data-lp-prev", pageNum - 1);
768                    parent.find(".pagination-right").attr("data-lp-next", pageNum + 1);
769
770                    searchPaginationNumber = pageNum;
771                    fetchArticleList(parent, "fetch-pagination", false)
772                        .then(() => {
773                            // This code will only run after fetchArticleList completes
774                            $('html, body').animate({
775                                scrollTop: articleListing.offset().top
776                            }, 500);
777                        })
778                        .catch(error => {
779                            console.error("Error in pagination:", error);
780                        });
781                }
782            });
783
784            articleListing.find(".pagination-left").on("click", function() {
785                var parent = $(this).closest(".article-listing.component");
786                var currentVal = parseInt(parent.find(".pagination-item-input").val());
787                var maxVal = parseInt(parent.find(".pagination-item-input").attr('data-max-val'));
788
789                if (currentVal > maxVal) {
790                    currentVal = maxVal;
791                }
792
793                if (currentVal - 1 >= 1) {
794                    var newPage = currentVal - 1;
795                    parent.find(".pagination-item-input").val(newPage);
796                    parent.find(".pagination-item-input").attr("data-current-page", newPage);
797                    searchPaginationNumber = newPage;
798                    fetchArticleList(parent, "fetch-pagination", false)
799                        .then(() => {
800                            // This code will only run after fetchArticleList completes
801                            $('html, body').animate({
802                                scrollTop: articleListing.offset().top
803                            }, 500);
804
805                            // Update button states
806                            parent.find(".pagination-right").removeClass("disabled").attr("aria-disabled","false").attr("tabindex","0");
807                            parent.find(".total-pag-num").removeClass("disabled").attr("aria-disabled","false").attr("tabindex","0");
808                            if (newPage === 1) {
809                                $(this).addClass("disabled").attr("aria-disabled","true").attr("tabindex","-1");
810                            }
811                        })
812                        .catch(error => {
813                            console.error("Error in pagination:", error);
814                        });
815                }
816                parent.find(".pagination-left").attr("data-lp-prev", currentVal - 1);
817                parent.find(".pagination-right").attr("data-lp-next", currentVal + 1);
818            })
819
820            articleListing.find(".pagination-right").on("click", function() {
821                var parent = $(this).closest(".article-listing.component");
822                var currentVal = parseInt(parent.find(".pagination-item-input").val());
823                var maxVal = parseInt(parent.find(".pagination-item-input").attr('data-max-val'));
824                if (currentVal + 1 <= maxVal) {
825                    var newPage = currentVal + 1;
826                    parent.find(".pagination-item-input").val(newPage);
827                    parent.find(".pagination-item-input").attr("data-current-page", newPage);
828                    searchPaginationNumber = newPage;
829                    fetchArticleList(parent, "fetch-pagination", false)
830                        .then(() => {
831                            // This code will only run after fetchArticleList completes
832                            $('html, body').animate({
833                                scrollTop: articleListing.offset().top
834                            }, 500);
835
836                            // Update button states
837                            parent.find(".pagination-left").removeClass("disabled").attr("aria-disabled","false").attr("tabindex","0");
838                            parent.find(".total-pag-num").removeClass("disabled").attr("aria-disabled","false").attr("tabindex","0");
839                            if (newPage === maxVal) {
840                                $(this).addClass("disabled").attr("aria-disabled","true");
841                                parent.find(".total-pag-num").addClass("disabled").attr("aria-disabled","true").attr("tabindex","-1");
842                            }
843                        })
844                        .catch(error => {
845                            console.error("Error in pagination:", error);
846                        });
847                }
848                parent.find(".pagination-left").attr("data-lp-prev", currentVal - 1);
849                parent.find(".pagination-right").attr("data-lp-next", currentVal + 1);
850            })
851
852            articleListing.find(".total-pag-num").on("click", function() {
853                var parent = $(this).closest(".article-listing.component");
854                var maxVal = parseInt(parent.find(".pagination-item-input").attr('data-max-val'));
855                parent.find(".pagination-item-input").val(maxVal);
856                parent.find(".pagination-left").attr("data-lp-prev", parseInt(maxVal) - 1);
857                parent.find(".pagination-left").removeClass("disabled").attr("aria-disabled","false").attr("tabindex","0");
858                parent.find(".pagination-right").attr("data-lp-next", maxVal);
859                parent.find(".pagination-right").addClass("disabled").attr("aria-disabled","true").attr("tabindex","-1");
860                parent.find(".total-pag-num").addClass("disabled").attr("aria-disabled","true").attr("tabindex","-1");
861                searchPaginationNumber = maxVal;
862                fetchArticleList(parent, "fetch-pagination", false)
863                    .then(() => {
864                        // This code will only run after fetchArticleList completes
865                        $('html, body').animate({
866                            scrollTop: articleListing.offset().top
867                        }, 500);
868                    })
869                    .catch(error => {
870                        console.error("Error in pagination:", error);
871                    });
872
873            }).on("keypress", function(evt) {
874                if (13 === evt.keyCode || 32 === evt.keyCode) {
875                    $(this).trigger("click");
876                }
877            });
878            //Pagination
879
880            // analytics link click for article
881            $(document).on("click", ".article-list-item a", function() {
882                var title = $(this).closest(".article-listing.component").find(".article-listing--header__wrapper--title").text().trim();
883                var componentName = "Article Listing - Article";
884                var clickedLink = $(this).find(".article-list-item-headline").text().trim();
885                AnalyticsModule.linkClick(title, componentName, clickedLink);
886            }).on("keydown", ".article-list-item a", function(evt) {
887                if (evt.keyCode === 13 || evt.keyCode === 32) {
888                    evt.preventDefault();
889                    $(this)[0].click();
890                }
891            });
892        }
893      };
894    })();
895		// Immediately initialize the new module
896		window.ArticleListingModule.init();
897	}
898  });
899})();

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.