PageSourceSearch

https://qsport.org.au/wp-content/themes/qsport/js/main.js?ver=7.1.2

js qsport.org.au collected 2026-10-02 19:15:58 UTC 23,076 bytes, 609 lines download raw bytes

1jQuery(function ($) {
2    /*--------------------------------------------------------------
3    Main
4    --------------------------------------------------------------*/
5    // vars
6    var $window = $(window);
7    var $body = $("body");
8    var headerHeight = $(".site-header").outerHeight();
9
10    // load
11    $window.on("load", function () {});
12
13    // resize
14    $window.on("resize", function () {});
15
16    // scroll
17    $window.on("scroll", function () {
18        var windowTop = $window.scrollTop();
19        // fixed header
20        if (windowTop > 50) {
21            $body.addClass("fixed");
22        } else {
23            $body.removeClass("fixed");
24        }
25    });
26
27    /*--------------------------------------------------------------
28    Functions
29    --------------------------------------------------------------*/
30    // scroll to element
31    function scrollTo($step) {
32        $("html, body").animate({ scrollTop: $step.offset().top - 60 }, 750);
33    }
34
35    // smooth scroll to anchor points
36    $('a[href*="#"]')
37        .not('[href="#"]')
38        .not('[href="#0"]')
39        .on("click", function (event) {
40            if (location.pathname.replace(/^\//, "") == this.pathname.replace(/^\//, "") && location.hostname == this.hostname) {
41                var target = $(this.hash);
42                target = target.length ? target : $("[name=" + this.hash.slice(1) + "]");
43                if (target.length) {
44                    event.preventDefault();
45                    $("html, body").animate({ scrollTop: target.offset().top - 60 }, 750);
46                }
47            }
48        });
49
50    // button loader toggle
51    function loaderToggle($el, $option) {
52        if ($option === 0) {
53            $(".btn-loader", $el).hide();
54            $(".button-label", $el).css("visibility", "visible");
55        } else if ($option === 1) {
56            $(".button-label", $el).css("visibility", "hidden");
57            $(".btn-loader", $el).show();
58        }
59    }
60
61    // copy to clipboard + fallback function
62    function copyToClipboardFallback(text) {
63        let clipboard_textarea = document.createElement("textarea");
64        clipboard_textarea.value = text;
65
66        // avoid scrolling to bottom
67        clipboard_textarea.style.top = "0";
68        clipboard_textarea.style.left = "0";
69        clipboard_textarea.style.position = "fixed";
70
71        document.body.appendChild(clipboard_textarea);
72        clipboard_textarea.focus();
73        clipboard_textarea.select();
74
75        try {
76            let successful = document.execCommand("copy");
77            let msg = successful ? "successful" : "unsuccessful";
78            console.log("Fallback: Copying to clipboard was " + msg);
79        } catch (err) {
80            console.error("Fallback: Unable to copy", err);
81        }
82        document.body.removeChild(clipboard_textarea);
83    }
84    function copyToClipboard(text) {
85        if (!navigator.clipboard) {
86            copyToClipboardFallback(text);
87            return;
88        }
89        navigator.clipboard.writeText(text).then(
90            function () {
91                console.log("Async: Copying to clipboard was successful");
92            },
93            function (err) {
94                console.error("Async: Unable to copy: ", err);
95            },
96        );
97    }
98
99    /*--------------------------------------------------------------
100    Menu
101    --------------------------------------------------------------*/
102    // mobile menu
103    $(".navigation-toggle").on("click", function (event) {
104        event.preventDefault();
105        if ($body.hasClass("menu-toggled")) {
106            $body.off("swiperight");
107        } else {
108            $body.on("swiperight", function () {
109                $(".navigation-toggle").trigger("click");
110            });
111        }
112        $body.toggleClass("menu-toggled");
113    });
114
115    // mobile submenu
116    $(".mobile-navigation ul li.menu-item-has-children > a > span").on("click", function (event) {
117        event.preventDefault();
118        $(this).closest(".mobile-navigation ul li.menu-item-has-children").toggleClass("active");
119        $(this).closest(".mobile-navigation ul li.menu-item-has-children").find(".sub-menu").slideToggle(300);
120    });
121
122    /*--------------------------------------------------------------
123    Theme
124    --------------------------------------------------------------*/
125    // parallax
126    let parallaxScrolled;
127    function parallaxUpdate() {
128        $(".parallax").css("transform", "translate3d(0, " + parallaxScrolled * 0.5 + "px, 0)");
129        $(".parallax").css("opacity", 1 - parallaxScrolled / 1000);
130    }
131    $window.on("scroll", function () {
132        parallaxScrolled = $window.scrollTop();
133        requestAnimationFrame(parallaxUpdate);
134    });
135
136    // content animation
137    var $animate = $(".animate");
138    function in_view() {
139        var window_height = $window.height();
140        var window_top_position = $window.scrollTop();
141        var window_bottom_position = window_top_position + window_height;
142
143        $animate.each(function () {
144            var $element = $(this);
145            var element_height = $element.outerHeight();
146            var element_top_position = $element.offset().top;
147            var element_bottom_position = element_top_position + element_height;
148            if (element_bottom_position >= window_top_position && element_top_position <= window_bottom_position) {
149                $element.addClass("in-view");
150            }
151        });
152    }
153    $window.on("scroll resize", in_view);
154
155    // copy to clipboard
156    let clipboard = document.querySelector(".clipboard-copy");
157    let tooltip = document.querySelector(".clipboard-copy .tooltip");
158
159    $(clipboard).on("click", function (event) {
160        event.preventDefault();
161        let clipboard_text = clipboard.dataset.clipboard;
162        tooltip.innerHTML = "Copied!";
163        copyToClipboard(clipboard_text);
164    });
165
166    $(clipboard).mouseout(function (event) {
167        event.preventDefault();
168        tooltip.innerHTML = "Copy to clipboard";
169    });
170
171    // accordion
172    $(".accordion .accordion-header").on("click", function () {
173        $(this).parent().toggleClass("active");
174        $(this).next(".accordion-content").slideToggle(300);
175    });
176
177    /* Tabbed Section */
178    const tabbedSection = document.querySelectorAll(".tabbed-section");
179    if (tabbedSection.length) {
180        tabbedSection.forEach((section) => {
181            section.querySelectorAll(".tabbed-nav-item").forEach((item) => {
182                item.addEventListener("click", function (event) {
183                    event.preventDefault();
184                    let tab_id = this.dataset.tab;
185                    section.querySelectorAll(".tabbed-nav-item").forEach((navItem) => {
186                        navItem.classList.remove("active");
187                    });
188                    this.classList.add("active");
189
190                    section.querySelectorAll(".tabbed-entry").forEach((entry) => {
191                        entry.classList.remove("active");
192                    });
193                    section.querySelector('.tabbed-entry[data-tab="' + tab_id + '"]').classList.add("active");
194                });
195            });
196        });
197    }
198
199    // scroll to and open accordion on anchor linking
200    let accordionEntriesWithId = document.querySelectorAll(".accordion-entry[id]");
201    if (accordionEntriesWithId.length) {
202        let locationHash = window.location.hash;
203        if (locationHash) {
204            let accordionEntry = document.querySelector(locationHash);
205            if (accordionEntry) {
206                accordionEntry.classList.add("active");
207                accordionEntry.querySelector(".accordion-content").style.display = "block";
208                setTimeout(() => {
209                    window.scroll({
210                        top: accordionEntry.offsetTop - (headerHeight + 10),
211                        behavior: "smooth",
212                    });
213                }, 100);
214            }
215        }
216    }
217
218    /* Sport Awards Nomination Accordion*/
219    $(".sport-awards-about-main-list .sport-awards-about-main-list-item-header").on("click", function () {
220        $(this).parent().toggleClass("active");
221        $(this).next(".sport-awards-about-main-list-item-content").slideToggle(300);
222    });
223
224    /*--------------------------------------------------------------
225    Videos
226    --------------------------------------------------------------*/
227    /* Video File Embeds */
228    const videoFileEmbeds = document.querySelectorAll(".video-embed-file");
229    if (videoFileEmbeds && videoFileEmbeds.length > 0) {
230        videoFileEmbeds.forEach((videoFileEmbed) => {
231            videoFileEmbed.querySelector(".video-embed-wrap").addEventListener("click", (event) => {
232                if (!videoFileEmbed.classList.contains("played")) {
233                    videoFileEmbed.querySelector("video").play();
234                    videoFileEmbed.querySelector("video").controls = true;
235                    videoFileEmbed.classList.add("played");
236                }
237            });
238        });
239    }
240
241    /*--------------------------------------------------------------
242    Posts
243    --------------------------------------------------------------*/
244    // category filter
245    const categoryFilter = document.querySelector(".post-archive-filter-select");
246    if (categoryFilter) {
247        const categoryFilterActive = categoryFilter.querySelector(".post-archive-filter-select-active");
248        categoryFilterActive.addEventListener("click", (event) => {
249            event.preventDefault();
250            categoryFilter.classList.toggle("active");
251        });
252        // escape close
253        document.addEventListener("keyup", function (event) {
254            if (event.key === "Escape") {
255                categoryFilter.classList.remove("active");
256            }
257        });
258        // click anywhere to close
259        document.addEventListener("click", (event) => {
260            if (!categoryFilter.contains(event.target)) {
261                categoryFilter.classList.remove("active");
262            }
263        });
264    }
265
266    /*--------------------------------------------------------------
267    Events
268    --------------------------------------------------------------*/
269    // category filter
270    const eventCategoryFilter = document.querySelector(".event-archive-filter-select");
271    if (eventCategoryFilter) {
272        const eventCategoryFilterActive = eventCategoryFilter.querySelector(".event-archive-filter-select-active");
273        eventCategoryFilterActive.addEventListener("click", (event) => {
274            event.preventDefault();
275            eventCategoryFilter.classList.toggle("active");
276        });
277        // escape close
278        document.addEventListener("keyup", function (event) {
279            if (event.key === "Escape") {
280                eventCategoryFilter.classList.remove("active");
281            }
282        });
283        // click anywhere to close
284        document.addEventListener("click", (event) => {
285            if (!eventCategoryFilter.contains(event.target)) {
286                eventCategoryFilter.classList.remove("active");
287            }
288        });
289    }
290
291    /*--------------------------------------------------------------
292    Team
293    --------------------------------------------------------------*/
294    /* Modal */
295    const teamMemberModalEL = document.querySelector(".fs-modal.team-member-modal");
296    const teamMemberModalToggleELs = document.querySelectorAll(".team-entry-perma");
297    if (teamMemberModalEL && teamMemberModalToggleELs.length) {
298        const teamMemberModalCloseEL = teamMemberModalEL.querySelector(".fs-modal-close");
299        // open modal
300        teamMemberModalToggleELs.forEach((teamMemberModalToggleEL) => {
301            teamMemberModalToggleEL.addEventListener("click", (event) => {
302                event.preventDefault();
303                const teamID = teamMemberModalToggleEL.dataset.id;
304                teamMemberModalEL.querySelector(".fs-modal-inner").innerHTML = '<div class="team-member-modal-loader"><i class="fas fa-circle-notch fa-spin"></i></div>';
305                teamMemberModalEL.classList.add("active");
306                $.ajax({
307                    url: main_ajax.url,
308                    type: "POST",
309                    data: {
310                        action: "qsport_team_member_modal",
311                        token: main_ajax.token,
312                        dataType: "json",
313                        teamID: teamID,
314                    },
315                    success: function (response) {
316                        teamMemberModalEL.querySelector(".fs-modal-inner").innerHTML = response;
317                    },
318                });
319            });
320        });
321        // close modal
322        teamMemberModalCloseEL.addEventListener("click", (event) => {
323            event.preventDefault();
324            teamMemberModalEL.classList.remove("active");
325        });
326        // escape close
327        document.addEventListener("keyup", function (event) {
328            if (event.key === "Escape") {
329                teamMemberModalEL.classList.remove("active");
330            }
331        });
332        // close modal on click outside
333        teamMemberModalEL.addEventListener("click", function (event) {
334            if (!event.target.closest(".fs-modal-content")) {
335                teamMemberModalEL.classList.remove("active");
336            }
337        });
338    }
339
340    /*--------------------------------------------------------------
341    Hall of Fame
342    --------------------------------------------------------------*/
343    const hofTableSort = document.querySelector(".hof-table-sort");
344    if (hofTableSort) {
345        const hofTableSortActive = hofTableSort.querySelector(".hof-table-sort-active");
346        hofTableSortActive.addEventListener("click", (event) => {
347            event.preventDefault();
348            hofTableSort.classList.toggle("active");
349        });
350        // escape close
351        document.addEventListener("keyup", function (event) {
352            if (event.key === "Escape") {
353                hofTableSort.classList.remove("active");
354            }
355        });
356        // click anywhere to close
357        document.addEventListener("click", (event) => {
358            if (!hofTableSort.contains(event.target)) {
359                hofTableSort.classList.remove("active");
360            }
361        });
362    }
363
364    /* Modal */
365    const hofProfileModalEL = document.querySelector(".fs-modal.hof-profile-modal");
366    const hofProfileModalToggleELs = document.querySelectorAll("a.hof-table-col-person-name");
367    if (hofProfileModalEL && hofProfileModalToggleELs.length) {
368        const hofProfileModalCloseEL = hofProfileModalEL.querySelector(".fs-modal-close");
369        // open modal
370        hofProfileModalToggleELs.forEach((hofProfileModalToggleEL) => {
371            hofProfileModalToggleEL.addEventListener("click", (event) => {
372                event.preventDefault();
373                const personID = hofProfileModalToggleEL.dataset.id;
374                hofProfileModalEL.querySelector(".fs-modal-inner").innerHTML = '<div class="hof-profile-modal-loader"><i class="fas fa-circle-notch fa-spin"></i></div>';
375                hofProfileModalEL.classList.add("active");
376                $.ajax({
377                    url: main_ajax.url,
378                    type: "POST",
379                    data: {
380                        action: "qsport_hof_profile_modal",
381                        token: main_ajax.token,
382                        dataType: "json",
383                        personID: personID,
384                    },
385                    success: function (response) {
386                        hofProfileModalEL.querySelector(".fs-modal-inner").innerHTML = response;
387                        if (hofProfileModalEL.querySelector(".swiper.standard-gallery-swiper")) {
388                            new Swiper(".swiper.standard-gallery-swiper", {
389                                loop: true,
390                                slidesPerView: 1,
391                                centeredSlides: true,
392                                spaceBetween: 20,
393                                watchSlidesVisibility: true,
394                                autoHeight: true,
395                                navigation: {
396                                    prevEl: ".standard-gallery-swiper-prev",
397                                    nextEl: ".standard-gallery-swiper-next",
398                                },
399                                pagination: {
400                                    el: ".standard-gallery-swiper-pagination",
401                                    type: "fraction",
402                                },
403                            });
404                        }
405                    },
406                });
407            });
408        });
409        // close modal
410        hofProfileModalCloseEL.addEventListener("click", (event) => {
411            event.preventDefault();
412            hofProfileModalEL.classList.remove("active");
413        });
414        // escape close
415        document.addEventListener("keyup", function (event) {
416            if (event.key === "Escape") {
417                hofProfileModalEL.classList.remove("active");
418            }
419        });
420        // close modal on click outside
421        hofProfileModalEL.addEventListener("click", function (event) {
422            if (!event.target.closest(".fs-modal-content")) {
423                hofProfileModalEL.classList.remove("active");
424            }
425        });
426    }
427
428    /*--------------------------------------------------------------
429    Resource filter
430    --------------------------------------------------------------*/
431
432    document.querySelectorAll(".post-archive-filter-group").forEach((group) => {
433        const checkboxes = group.querySelectorAll('input[type="checkbox"]');
434        const viewAll = checkboxes[0];
435
436        viewAll.onchange = () => {
437            if (viewAll.checked) {
438                checkboxes.forEach((cb) => {
439                    if (cb !== viewAll) cb.checked = false;
440                });
441            }
442        };
443
444        checkboxes.forEach((cb) => {
445            if (cb !== viewAll) {
446                cb.onchange = () => {
447                    if (cb.checked) viewAll.checked = false;
448                };
449            }
450        });
451    });
452
453    /*--------------------------------------------------------------
454    Swipers
455    --------------------------------------------------------------*/
456    // standard gallery
457    const standard_gallery_swiper = new Swiper(".swiper.standard-gallery-swiper", {
458        loop: true,
459        slidesPerView: 1,
460        centeredSlides: true,
461        spaceBetween: 20,
462        watchSlidesVisibility: true,
463        autoHeight: true,
464        navigation: {
465            prevEl: ".standard-gallery-swiper-prev",
466            nextEl: ".standard-gallery-swiper-next",
467        },
468        pagination: {
469            el: ".standard-gallery-swiper-pagination",
470            type: "fraction",
471        },
472        keyboard: {
473            enabled: true,
474        },
475    });
476
477    // cutoff gallery
478    const cutoff_gallery_swiper = new Swiper(".swiper.cutoff-gallery-swiper", {
479        loop: true,
480        slidesPerView: "1.4",
481        centeredSlides: true,
482        spaceBetween: 20,
483        watchSlidesVisibility: true,
484        autoHeight: true,
485        navigation: {
486            prevEl: ".cutoff-gallery-swiper-prev",
487            nextEl: ".cutoff-gallery-swiper-next",
488        },
489        pagination: {
490            el: ".cutoff-gallery-swiper-pagination",
491            type: "fraction",
492        },
493        breakpoints: {
494            500: {
495                spaceBetween: 30,
496            },
497            768: {
498                spaceBetween: 40,
499            },
500        },
501        keyboard: {
502            enabled: true,
503        },
504    });
505
506    // logos swiper
507    let logos_swiper = new Swiper(".swiper.logos-swiper", {
508        slidesPerView: 2,
509        spaceBetween: 30,
510        loop: true,
511        freeMode: true,
512        centerInsufficientSlides: true,
513        watchOverflow: true,
514        // centeredSlides: true,
515        autoplay: {
516            delay: 1,
517            disableOnInteraction: false,
518        },
519        allowTouchMove: false,
520        noSwiping: true,
521        speed: 2500,
522        breakpoints: {
523            768: {
524                slidesPerView: 3,
525                spaceBetween: 40,
526            },
527            992: {
528                slidesPerView: 4,
529                spaceBetween: 40,
530            },
531        },
532    });
533
534    // award years swiper
535    let award_year_swiper = new Swiper(".swiper.sport-awards-nav-swi
535per", {
536        slideClass: "sport-awards-nav-item",
537        slidesPerView: "auto",
538        spaceBetween: 0,
539        resistanceRatio: 0.75,
540        autoplay: false,
541        navigation: {
542            prevEl: ".sport-awards-nav-swiper-prev",
543            nextEl: ".sport-awards-nav-swiper-next",
544        },
545        initialSlide: document.querySelector(".sport-awards-nav-item.active")?.swiper?.activeIndex || 0,
546        on: {
547            init: function () {
548                const activeSlide = this.el.querySelector(".sport-awards-nav-item.active");
549                if (activeSlide) {
550                    const activeIndex = [...this.slides].indexOf(activeSlide);
551                    this.slideTo(activeIndex, 0);
552                }
553            },
554        },
555    });
556
557    /*--------------------------------------------------------------
558    PhotoSwipe
559    --------------------------------------------------------------*/
560    // Cutoff Gallery
561    const cutoff_gallery_swiper_dom = document.querySelector(".cutoff-gallery-swiper");
562    if (cutoff_gallery_swiper_dom) {
563        const cutoff_gallery_photoswipe_options = {
564            gallery: ".cutoff-gallery-swiper",
565            pswpModule: PhotoSwipe,
566            bgOpacity: 1,
567            showHideOpacity: true,
568            children: "a",
569            loop: true,
570            showHideAnimationType: "zoom",
571            wheelToZoom: true,
572
573            imageClickAction: "next",
574            tapAction: "next",
575
576            zoom: false,
577            close: true,
578            counter: false,
579            arrowKeys: true,
580        };
581
582        const cutoff_gallery_lightbox = new PhotoSwipeLightbox(cutoff_gallery_photoswipe_options);
583        cutoff_gallery_lightbox.init();
584
585        cutoff_gallery_lightbox.on("change", () => {
586            const { pswp } = cutoff_gallery_lightbox;
587            cutoff_gallery_swiper.slideTo(pswp.currIndex, 0, false);
588        });
589
590        cutoff_gallery_lightbox.on("afterInit", () => {
591            const { pswp } = cutoff_gallery_lightbox;
592            if (cutoff_gallery_swiper.params.autoplay.enabled) {
593                cutoff_gallery_swiper.autoplay.stop();
594            }
595        });
596
597        cutoff_gallery_lightbox.on("closingAnimationStart", () => {
598            const { pswp } = cutoff_gallery_lightbox;
599            cutoff_gallery_swiper.slideTo(pswp.currIndex, 0, false);
600            if (cutoff_gallery_swiper.params.autoplay.enabled) {
601                cutoff_gallery_swiper.autoplay.start();
602            }
603        });
604    }
605
606    // trigger events
607    $window.trigger("resize");
608    $window.trigger("scroll");
609});

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.