$(document).ready(function() {
	if (typeof(window.CM) === 'undefined') {
		embedWebfonts({ webfonts:true });
	} else {
		let inputWebfonts = document.querySelectorAll('.consent-input[data-storage-key="webfonts"]');
		if(!inputWebfonts.length) {
			embedWebfonts({ webfonts:true });
		}
	}
});
document.addEventListener('consent.ready', function(e) {
	embedWebfonts(e.detail);
});
document.addEventListener('consent.updated', function(e) {
	embedWebfonts(e.detail);
});
function embedWebfonts(detail) {
	if (detail !== null && typeof detail.webfonts !== 'undefined' && detail.webfonts === true) {
		let embeds = document.querySelectorAll('script[data-consent="webfonts"]');
		for (let i = 0; i < embeds.length; ++i) {
			embeds[i].src = embeds[i].dataset.src;
			embeds[i].className = 'webfonts';
		}
	}
}