PageSourceSearch

https://www.ybs.co.uk/o/ybs-theme/js/main.js?browserId=chrome&minifierType=js&languageId=en_GB&t=1789540992000

js ybs.co.uk collected 2026-09-24 10:07:39 UTC 6,935 bytes, 228 lines download raw bytes

1/*1789540708000*/
2/* eslint-disable lines-around-comment */
3/* eslint-disable no-undef */
4
5/*
6	This it to prevent users from being able to bypass accepting or rejecting cookies when navigating 
7	from pages with the cookie banner switched off e.g. the Privacy and Cookies pages.
8	Liferay works as an SPA (Single Page Application) so that when the user changes the page, the main script is not called again.
9	This means that the cookie banner will not be reloaded on a page change. This function forces the cookie banner to be reloaded.
10	This function uses public methods from the OneTrust Banner Script to reinitialize the SDK and reload the banner.
11*/
12function reloadOTBanner() {
13	var otConsentSdk = document.getElementById('onetrust-consent-sdk');
14	if (otConsentSdk) {
15		otConsentSdk.remove();
16	}
17
18	if (window.OneTrust != null) {
19		OneTrust.Init();
20
21		setTimeout(function () {
22			OneTrust.LoadBanner();
23
24			var toggleDisplay = document.getElementsByClassName(
25				'ot-sdk-show-settings'
26			);
27
28			for (var i = 0; i < toggleDisplay.length; i++) {
29				toggleDisplay[i].onclick = function (event) {
30					event.stopImmediatePropagation();
31					window.OneTrust.ToggleInfoDisplay();
32				};
33			}
34		}, 1000);
35	}
36}
37
38function onloadFunction() {
39	// NOTE: The onetrust banner loading code has been moved into the 
40	// `screenActivate` event handler to prevent it from running on initial 
41	// landing, as well as when the user transitions between pages.
42
43	// check the os and toggle the right app badge to show based on device.
44	if (window.mobileDetect?.os()) {
45		var os = mobileDetect.os().toLowerCase();
46		if (os === 'ios') {
47			// document.querySelectorAll('.is-ios').classList.remove("show-for-android");
48			// loop through all instances of is ios and show the right bits
49			const items = document.querySelectorAll('.is-ios');
50			items.forEach((item) => {
51				item.classList.remove('hide-app-download');
52			});
53		}
54		if (os === 'androidos') {
55			// document.querySelectorAll('.is-android').classList.remove("show-for-ios");
56			// loop through all instances of is android and show the right bits
57			const items = document.querySelectorAll('.is-android');
58			items.forEach((item) => {
59				item.classList.remove('hide-app-download');
60			});
61		}
62	}
63}
64
65function _setupIframeModal() {
66	const elementIframe = document.querySelector(
67		'.box-dropzone a[data-modal="iframe"]'
68	);
69	if (elementIframe !== null) {
70		elementIframe.addEventListener('click', (event) => {
71			event.preventDefault();
72		});
73	}
74}
75
76/**
77 * Function to initialize the MS Phone Number Replacer.
78 * 
79 * This function checks if the replacer should be enabled (based on the presence of a URL parameter or session storage)
80 * and replaces phone numbers in the <a> element with the new number if enabled.
81 * 
82 */
83function initializeMsPhoneReplacer() {
84    const campaignIds = ["lis-15513", "lis-15514", "lis-15503", "lis-15505"];
85    const number = {
86        original: "0345 166 9510", 
87        to: "0345 166 9504" 
88    };
89
90	// Function to check if the phone replacer should be enabled by verifying session storage or URL parameters;
91    const checkAndEnableReplacer = () => {
92        if (sessionStorage.getItem("msPhoneReplacer") === "true") {
93            return true;
94        }
95        
96        const urlParams = new URLSearchParams(window.location.search);
97        const cmpid = urlParams.get('cmpid');
98        if (cmpid && campaignIds.includes(cmpid)) {
99			sessionStorage.setItem("msPhoneReplacer", "true");
100            return true;
101        }
102        
103        return false;
104    };
105
106    // Function to replace phone numbers in the <a> elements
107    const replaceNumber = () => {
108        const elements = document.querySelectorAll("a[href^='tel']"); // Select <a> elements with tel href
109		// Create a regex to find the original phone number, allowing for spaces between digits and ensuring the number is matched exactly
110        const numRegex = new RegExp(`\\b${number.original.replace(/\s/g, "\\s*")}\\b`, 'g'); 
111    
112        elements.forEach(element => {
113			// Replace number in textContent
114			let text = element.textContent;
115			if (numRegex.test(text)) {
116				element.textContent = text.replace(numRegex, number.to);
117			}
118
119            // Replace number in href attribute
120            let hrefVal = element.getAttribute('href');
121            if (hrefVal && numRegex.test(hrefVal)) {
122                element.setAttribute('href', hrefVal.replace(numRegex, number.to));
123            }
124        });
125    };
126
127    // Initialization function to check if enabled and replace numbers
128    const init = () => {
129        if (checkAndEnableReplacer()) {
130            replaceNumber();
131        }
132    };
133
134    // Initialization call
135    init();
136}
137
138AUI().ready(() => {
139	_setupIframeModal();
140	onloadFunction();
141	initializeMsPhoneReplacer();
142});
143
144Liferay.on('endNavigate', () => {
145	initializeMsPhoneReplacer();
146});
147
148Liferay.on('screenActivate', () => {
149	// reload OneTrust Banner on page click
150	reloadOTBanner();
151});
152
153Liferay.Portlet.ready((_portletId, _node) => {});
154
155Liferay.on('allPortletsReady', () => {});
156
157/**
158 *  @name Create a cookie
159 *
160 *  @param {String} name Name of cookie
161 *  @param {String} value Value of cookie
162 *  @param {Number} days Expiry time in days
163 *  @return undefined
164 *
165 *  @details Create a cookie with an optional expiry date.
166 */
167function createCookie(name, value, days) {
168	var expires = '';
169	if (days && (typeof days).toLowerCase() == 'number') {
170		//Specify days as a number = Relative amount of days from this point
171		var date = new Date();
172		var daysToTime = days * 24 * 60 * 60 * 1000;
173
174		date.setTime(date.getTime() + daysToTime);
175		expires = date.toGMTString();
176	} else if (days && (typeof days).toLowerCase() == 'string') {
177		//Specify days as a string, we assume that you have provided the Expires= value;
178		expires = days;
179	}
180
181	var cookieString = [name + '=' + value];
182	cookieString.push('Path=/');
183	cookieString.push('SameSite=Lax');
184
185	if (window.location.host === 'www.ybs.co.uk') {
186		cookieString.push('Domain=ybs.co.uk');
187	}
188
189	if (window.location.host === 'www.thechelsea.co.uk') {
190		cookieString.push('Domain=thechelsea.co.uk');
191	}
192
193	if (expires !== '') {
194		cookieString.push('Expires=' + expires);
195	}
196
197	if (window.location.protocol === 'https') {
198		cookieString.push('Secure');
199	}
200
201	document.cookie = cookieString.join('; ') + ';';
202
203	if (days == -1) {
204		if (readCookie(name)) {
205			console.error(
206				'createCookie| Unable to delete cookie. Name: ' + name
207			);
208		}
209	}
210}
211
212/**
213 *  @name Get a cookie
214 *
215 *  @param {String} name Name of the cookie to get
216 *  @return {String} cookie value if it exists, otherwise null.
217 *
218 *  @details Get a cookie from the users browser. If the cookie doesnt exist, returns null.
219 */
220function readCookie(name) {
221	if (document.cookie.indexOf(name + '=') === -1) {
222		console.warn('readCookie| Cookie not found: ' + name);
223		return null;
224	}
225
226	let cookieValue = document.cookie.split(name + '=')[1].split('; ')[0];
227	return cookieValue;
228}

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.