PageSourceSearch

https://www.premier.org.uk/wp-content/plugins/premiercc-advent-2023/premier-advent.js?ver=1764341746

js premier.org.uk collected 2026-10-02 03:04:21 UTC 6,001 bytes, 214 lines download raw bytes

1jQuery(document).ready(function () {
2	"use strict";
3
4	$ = jQuery;
5
6	function stopVideo(videoContainer) {
7		// When a modal with class modal__video is closed, stop autoplay
8		var iframe = videoContainer.find("iframe"),
9			src = iframe.prop("src");
10		src = src.replace("&autoplay=1", "");
11		iframe.prop("src", src);
12	}
13
14	$(document).on("mouseover focus", ".advent-open-door", function (e) {
15		e.preventDefault();
16		var $door = $(this).closest(".advent-calendar-door");
17		$door.addClass("is-hovered");
18		// $("#advent-success").trigger("pause");
19		// $("#advent-ambience").trigger("pause");
20	});
21
22	$(document).on("mouseleave focusout", ".advent-open-door", function (e) {
23		e.preventDefault();
24		var $door = $(this).closest(".advent-calendar-door");
25		$door.removeClass("is-hovered");
26	});
27
28	$(document).on("click touch", ".advent-open-door", function (e) {
29		$("#advent-success").trigger("pause");
30
31		if (!$(this).hasClass("has-video")) {
32			$("#advent-ambience").trigger("play");
33		}
34		var $door = $(this).closest(".advent-calendar-door");
35		$door.addClass("is-opening");
36	});
37
38	$(document).on("click touch", ".advent-moments-complete", function (e) {
39		e.preventDefault();
40		let taskId = $(this).attr("data-taskid");
41
42		let button = $(this);
43
44		var data = {
45			action: "adventMoments",
46			nonce: adventMomentsAjax.nonce, // adventMomentsAjax is added by localize script
47			taskID: taskId,
48			userID: adventMomentsAjax.userID,
49			locale: jfReadCookie("locationPreference"),
50		};
51
52		// console.log(data);
53
54		// Send to AJAX
55		$.ajax({
56			type: "POST",
57			url: adventMomentsAjax.ajaxurl, // adventMomentsAjax is added by localize script
58			data: data,
59			dataType: "json",
60			// response is returned from php
61			success: function (response) {
62				// console.log(response);
63
64				if (response.data == "completed") {
65					// Find the matching door
66					let door = $(
67						".advent-calendar-door[data-challengeid=" + taskId + "]"
68					);
69
70					// If a door is found...
71					if (door.length > 0) {
72						// Get the first one as we are getting an array returned
73						door = door.first();
74						door.addClass("opened");
75						door.addClass("is-complete");
76
77						// Replace the image src
78						let image = door.find("img");
79						let src = image.attr("src");
80						src = src.replace("-mono", "");
81						image.attr("src", src);
82
83						// Remove anchor bg image
84						let anchor = door.find(".advent-open-door");
85						anchor.css("background-image", "");
86
87						// Close magnific popups
88						$.magnificPopup.close();
89
90						// Update number of tasks completed
91						let participantElem = button
92								.closest(".modal")
93								.find(".participants"),
94							participantCount = Number(participantElem.html());
95
96						participantElem.html(participantCount + 1);
97
98						// Play success noise
99						$("#advent-ambience").trigger("pause");
100						$("#advent-success").prop("currentTime", 0);
101						$("#advent-success").trigger("play");
102					}
103					// REPLACE IMAGE AND REMOVE THE OTHER CRUFT
104
105					button.fadeOut(300);
106				}
107			},
108			error: function (err) {
109				// console.log(err);
110			},
111		});
112	});
113
114	$(".advent-open-door").on("click touch", function (e) {
115		let popupID = $(this).attr("href");
116
117		let modalClass = "mfp-christmas";
118		let transformOrigin = "from-" + $(this).attr("data-transform-origin");
119		modalClass = modalClass + " " + transformOrigin;
120		var $door = $(this).closest(".advent-calendar-door");
121
122		// Get offset of clicked anchor relative to viewport
123		let offset = $(this).offset();
124		let elemTop = offset.top - $(document).scrollTop();
125		let elemLeft = offset.left - $(document).scrollLeft();
126
127		// Get width and height of anchor itself
128		let elemWidthHalf = $(this).outerWidth() / 2;
129		let elemHeightHalf = $(this).outerHeight() / 2;
130
131		// console.log("elemHeight: " + elemHeightHalf, " elemWidth:" + elemWidthHalf);
132
133		elemTop = elemTop + elemHeightHalf;
134		elemLeft = elemLeft + elemWidthHalf;
135
136		// console.log("elemTop: " + elemTop, " elemLeft:" + elemLeft);
137
138		// Get center point of viewport
139		let vpHorizontalCenter = $(window).width() / 2;
140		let vpVerticalCenter = $(window).height() / 2;
141
142		let elementHorizontalOffset, elementVerticalOffset;
143
144		// Calculate the offset for the modal based on the elements position from the viewport center
145
146		if (elemTop >= vpVerticalCenter) {
147			elementVerticalOffset = " + " + (elemTop - vpVerticalCenter) + "px";
148		} else {
149			elementVerticalOffset = " - " + (vpVerticalCenter - elemTop) + "px";
150		}
151
152		if (elemLeft >= vpHorizontalCenter) {
153			elementHorizontalOffset = " + " + (elemLeft - vpHorizontalCenter) + "px";
154		} else {
155			elementHorizontalOffset = " - " + (vpHorizontalCenter - elemLeft) + "px";
156		}
157
158		// console.log("elementVerticalOffset: " + elementVerticalOffset);
159		// console.log("elementHorizontalOffset: " + elementHorizontalOffset);
160
161		// console.log(
162		// 	"vpHorizontalCenter: " + vpHorizontalCenter,
163		// 	"vpVerticalCenter: " + vpVerticalCenter
164		// );
165
166		$(".page").css({
167			"--advent-origin-y": "calc(0% " + elementVerticalOffset + ")",
168		});
169		$(".page").css({
170			"--advent-origin-x": "calc(0% " + elementHorizontalOffset + ")",
171		});
172
173		e.preventDefault();
174
175		var timeOut;
176		if ($door.hasClass("is-complete")) {
177			timeOut = 0;
178		} else {
179			timeOut = 250;
180		}
181
182		setTimeout(function () {
183			// console.log(popupID);
184
185			$.magnificPopup.open({
186				type: "inline",
187				items: {
188					src: popupID,
189				},
190				closeBtnInside: true,
191				mainClass: modalClass,
192				callbacks: {
193					open: function () {
194						let videoPlay = $(popupID).find("button.play");
195						if (videoPlay.length > 0) {
196							videoPlay.trigger("click");
197							$(popupID).find(".video-overlay").remove();
198						}
199					},
200					close: function () {
201						$("#advent-ambience").trigger("pause");
202						$(".advent-calendar-door").removeClass("is-opening");
203
204						// Stop any playing videos
205						let hasVideo = $(popupID).find("iframe");
206						if (hasVideo.length > 0) {
207							stopVideo($(popupID));
208						}
209					},
210				},
211			});
212		}, timeOut);
213	});
214});

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.