influxweb
3/24/2017 - 4:57 PM

Updated Image Machine Template for Levels ReadyTheme

Updated Image Machine Template for Levels ReadyTheme

<mvt:assign name="l.settings:clean:product:name" value="glosub(l.settings:product:name, asciichar(39), '&#39;')" />
<script>
	(function () {
		/**
		 * This is a 'CustomEvent()' polyfill for IE 9-11 to generate the proper thumbnails.
		 * https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/CustomEvent
		 */
		
		if (typeof window.CustomEvent === "function") return false;
		
		function CustomEvent(event, params) {
			params = params || {bubbles: false, cancelable: false, detail: undefined};
			var evt = document.createEvent('CustomEvent');
			evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail);
			return evt;
		}
		
		CustomEvent.prototype = window.Event.prototype;
		
		window.CustomEvent = CustomEvent;
	})();


	var gallery = [],
		thumbnailIndex = 0,
		generate_thumbnail_event = new CustomEvent('ImageMachine_Generate_Thumbnail');

	ImageMachine.prototype.ImageMachine_Generate_Thumbnail = function (thumbnail_image, main_image, closeup_image, type_code) {
		var thumbnail,
			img;

		thumbnail = document.createElement('div');
		thumbnail.className = 'thumbnail-img-wrap';
		thumbnail.setAttribute('data-index', thumbnailIndex++);

		if (typeof(thumbnail_image) === 'string' && thumbnail_image.length > 0) {
			img = document.createElement('img');
			img.src = thumbnail_image;
			thumbnail.appendChild(img);
		}

		var gallery_image = (typeof(closeup_image) === 'string' && closeup_image.length > 0) ? closeup_image : main_image;
		gallery.push({
			src: gallery_image,
			title: '&mvt:clean:product:name;'
		});

		document.dispatchEvent(generate_thumbnail_event);

		return thumbnail;
	};
</script>