$.fn.randomise = function (a) { (a ? this.find(a) : this).parent().each(function () { $(this).children(a).sort(function () { return Math.random() - 0.5 }).detach().appendTo(this) }); return this }; $.fn.time = function (seconds) { const mins = Math.floor(seconds / 60); const secs = Math.floor(seconds % 60); return $(this).text((mins < 10 ? "0" : "") + mins + ":" + (secs < 10 ? "0" : "") + secs) }; $(document).ready(function () { $.when($(".swiper-wrapper").randomise(".swiper-slide:not(.new)")).done(function () { const swiper = new Swiper(".swiper", { breakpoints: { 540: { slidesPerView: 2, spaceBetween: 12 }, 860: { slidesPerView: 3, spaceBetween: 12 }, 1400: { slidesPerView: 4, spaceBetween: 24 } }, hashNavigation: { replaceState: true }, navigation: { addIcons: false, nextEl: ".swiper-button-next", prevEl: ".swiper-button-prev" }, pagination: { el: ".swiper-pagination" }, slidesPerView: 1, spaceBetween: 12 }); if (window.location.hash) { const hash = window.location.hash.replace(/[^a-zA-Z0-9-]/g, ""); if ($("[data-hash=" + hash + "]")[0]) { $("html, body").scrollTop($("[data-hash=" + hash + "]").closest(".swiper").prevAll("h2").first().offset().top); } } }); $(this).on("click", "[role='link']", function () { window.open($(this).data("href")); }); $(this).on("click", ".ad", function (event) { if (!$(event.target).is("a")) { $(this).find("a")[0].click(); } }); $(this).on("click", ".close-dialog", function () { $(this).parent()[0].close(); return false; }); $(this).on("click", ".open-dialog", function () { $("#" + $(this).data("dialog"))[0].showModal(); return false; }); $(this).on("click", ".swiper-slide:has(a)", function (event) { if (!$(event.target).is("a")) { $(this).find("a")[0].click(); } }); $(this).on("click", "dialog", function (event) { if (event.target == event.currentTarget) { $(this)[0].close(); } }); $(".player").each(function () { const player = $(this); const audio = $(this).find("audio")[0]; $(this).find(".duration").time((audio.duration != audio.duration) ? 0 : audio.duration); $(this).find(".mute").on("click", function () { audio.muted = !audio.muted; if (audio.muted) { $(this).addClass("on").attr("aria-label", "Unmute").attr("aria-pressed", true); } else { $(this).removeClass("on").attr("aria-label", "Mute").attr("aria-pressed", false); } }); $(this).find(".play").on("click", function () { if (audio.paused) { $(this).addClass("on").attr("aria-label", "Pause").attr("aria-pressed", true); audio.play(); } else { $(this).removeClass("on").attr("aria-label", "Play").attr("aria-pressed", true); audio.pause(); } }); $(this).find(".seek").on("input", function () { audio.currentTime = ($(this).val() / 100) * audio.duration; }); $(this).find(".volume").on("input", function () { $(this).attr("aria-valuenow", $(this).val()); audio.volume = $(this).val() / 100; }); $(audio).on("ended", function () { $(player).find(".play").removeClass("on"); }); $(audio).on("timeupdate", function () { $(player).find(".seek").val((audio.currentTime / audio.duration) * 100).attr("aria-valuenow", Math.ceil((audio.currentTime / audio.duration) * 100)); $(player).find(".time").time(audio.currentTime); }); }); $("dialog").each(function () { $(this)[0].addEventListener("close", () => { if ($(this).find("audio")[0]) { const audio = $(this).find("audio")[0]; if (audio.play) { $(this).find(".play").removeClass("on"); audio.pause(); } } }); }); });