function youtubeLoader(identifier) {
	var collection = document.querySelectorAll(identifier);

	for (var i = 0; i < collection.length; ++i) {
		var theElem = collection[i];
		var id = theElem.getAttribute("id");

		// set bg image
		if (theElem.hasAttribute('data-background')) {
			theElem.style.backgroundImage = 'url(' + theElem.getAttribute('data-background') + ')';
		} else {
			theElem.style.backgroundImage = 'url(//i.ytimg.com/vi/' + id + '/hqdefault.jpg)';
		}

		// click event
		theElem.addEventListener("click", function(e) {
			// build iframe
			var iframe = document.createElement('iframe');
			var url = '//www.youtube.com/embed/' + id + '?autoplay=1&autohide=1&' + theElem.getAttribute('data-params');
			iframe.src = url;
			iframe.setAttribute('allowfullscreen', 'allowfullscreen');
			iframe.setAttribute('frameborder', '0');
			iframe.setAttribute('aria-label', 'GeoPortal video tutorial');
			theElem.appendChild(iframe);
		});
	};

}

if (typeof module === 'object') {
    module.exports = youtubeLoader;
}

@@ -1,16 +1,32 @@
+%0Aexport default 
 function youtube
@@ -46,16 +46,211 @@
 fier) %7B%0A
+%09if ('requestIdleCallback' in window) %7B%0A%09%09requestIdleCallback(function(deadline) %7B%0A%09%09%09makeElement(identifier);%0A%09%09%7D);%0A%09%7D else %7B%0A%09%09makeElement(identifier);%0A%09%7D%0A%7D%0A%0Afunction makeElement(identifier) %7B%0A
 %09var col
@@ -737,16 +737,17 @@
 function
+ 
 (e) %7B%0A%09%09
@@ -1160,84 +1160,10 @@
 %7D);%0A
+
 %09%7D;
-%0A%0A%7D%0A%0Aif (typeof module === 'object') %7B%0A    module.exports = youtubeLoader;
 %0A%7D%0A

move image load to requestidlecallback where available