<commit_before>/* global jQuery, OC ,OCA, $, t, oc_requesttoken, SlideShowControls, bigshot */
/**
 *
 * @param {jQuery} container
 * @param {{name:string, url: string, path: string, fallBack: string}[]} images
 * @param {int} interval
 * @param {int} maxScale
 * @constructor
 */
var SlideShow = function (container, images, interval, maxScale) {
	this.container = container;
	this.images = images;
	this.maxScale = maxScale || 1; // This should come from the configuration
	this.controls = null;
	this.imageCache = {};
	this.currentImage = null;
	this.errorLoadingImage = false;
	this.onStop = null;
	this.zoomable = null;
	this.fullScreen = null;
	this.canFullScreen = false;
	this.maxZoom = 3;
	this.smallImageDimension = 200 / window.devicePixelRatio;
	this.smallImageScale = 2;
};

SlideShow.mediaTypes = {};

SlideShow.prototype = {
	/**
	 *
	 * @param play
	 */
	init: function (play) {
		this.hideImage();
		this.bigShotSetup();

		this.controls = new SlideShowControls(this, this.container, this.images);
		this.controls.init(play);

		$(window).resize(function () {
			this.zoomDecider();
		}.bind(this));
	},

	bigShotSetup: function () {
		// Detect fullscreen capability (mobile)
		var e = this.container.get(0);
		this.canFullScreen = e.requestFullscreen !== undefined ||
		e.mozRequestFullScreen !== undefined ||
		e.webkitRequestFullscreen !== undefined ||
		e.msRequestFullscreen !== undefined;

		// makes UI controls work in mobile version. Pinch only works on iOS
		var browser = new bigshot.Browser();
		this.container.children('input').each(function (i, e) {
			browser.registerListener(e, 'click', browser.stopEventBubblingHandler(), false);
			browser.registerListener(e, 'touchstart', browser.stopEventBubblingHandler(), false);
			browser.registerListener(e, 'touchend', browser.stopEventBubblingHandler(), false);
		});
	},

	zoomDecider: function () {
		if (this.fullScreen === null && this.currentImage.mimeType !== 'image/svg+xml') {
			this.zoomToOriginal();
		} else {
			this.zoomToFit();
		}
	},

	zoomToFit: function () {
		if (this.zoomable !== null) {
			this.zoomable.flyZoomToFit();
		}
	},

	zoomToOriginal: function () {
		if (this.zoomable === null) {
			return;
		}
		if (this.currentImage.isSmallImage) {
			this.zoomable.flyTo(0, 0, this.smallImageScale, true);
		} else {
			this.zoomable.flyTo(0, 0, 0, true);
		}
	},

	resetZoom: function () {
		if (this.zoomable === null) {
			return;
		}
		if (this.currentImage.isSmallImage) {
			this.zoomable.setZoom(this.smallImageScale, true);
		} else {
			this.zoomable.setZoom(0, true);
		}
	},

	fullScreenStart: function () {
		if (!this.canFullScreen) {
			return;
		}
		this.fullScreen = new bigshot.FullScreen(this.container.get(0));
		this.fullScreen.open();
		this.fullScreen.addOnClose(function () {
			this.fullScreenExit();
		}.bind(this));
	},

	fullScreenExit: function () {
		if (this.fullScreen === null) {
			return;
		}
		this.fullScreen.close();
		this.fullScreen = null;
		this.zoomDecider();

	},

	fullScreenToggle: function () {
		if (this.zoomable === null) {
			return;
		}
		if (this.fullScreen !== null) {
			this.fullScreenExit();
		} else {
			this.fullScreenStart();
		}
	},

	/**
	 *
	 * @param index
	 *
	 * @returns {*}
	 */
	show: function (index) {
		this.hideErrorNotification();
		this.container.show();
		this.container.css('background-position', 'center');
		this.hideImage();
		var currentImageId = index;
		return this.loadImage(this.images[index]).then(function (image) {
			this.container.css('background-position', '-10000px 0');
			this.container.find('.changeBackground').show();

			// check if we moved along while we were loading
			if (currentImageId === index) {
				this.errorLoadingImage = false;
				this.currentImage = image;
				this.currentImage.mimeType = this.images[index].mimeType;
				this.container.append(image);

				image.setAttribute('alt', this.images[index].name);
				$(image).css('position', 'absolute');
				$(image).css('background-color', '#fff');
				var $border = 30 / window.devicePixelRatio;
				$(image).css('outline', $border + 'px solid #fff');

				this.startBigshot(image);

				this.setUrl(this.images[index].path);
				this.controls.show(currentImageId);
			}
		}.bind(this), function () {
			// Don't do anything if the user has moved along while we were loading as it would mess
			// up the index
			if (currentImageId === index) {
				this.errorLoadingImage = true;
				this.showErrorNotification();
				this.setUrl(this.images[index].path);
				this.images.splice(index, 1);
				this.controls.updateControls(this.images, this.errorLoadingImage);<commit_msg>Don't put a white background behind JPGs<commit_after>/* global jQuery, OC ,OCA, $, t, oc_requesttoken, SlideShowControls, bigshot */
/**
 *
 * @param {jQuery} container
 * @param {{name:string, url: string, path: string, fallBack: string}[]} images
 * @param {int} interval
 * @param {int} maxScale
 * @constructor
 */
var SlideShow = function (container, images, interval, maxScale) {
	this.container = container;
	this.images = images;
	this.maxScale = maxScale || 1; // This should come from the configuration
	this.controls = null;
	this.imageCache = {};
	this.currentImage = null;
	this.errorLoadingImage = false;
	this.onStop = null;
	this.zoomable = null;
	this.fullScreen = null;
	this.canFullScreen = false;
	this.maxZoom = 3;
	this.smallImageDimension = 200 / window.devicePixelRatio;
	this.smallImageScale = 2;
};

SlideShow.mediaTypes = {};

SlideShow.prototype = {
	/**
	 *
	 * @param play
	 */
	init: function (play) {
		this.hideImage();
		this.bigShotSetup();

		this.controls = new SlideShowControls(this, this.container, this.images);
		this.controls.init(play);

		$(window).resize(function () {
			this.zoomDecider();
		}.bind(this));
	},

	bigShotSetup: function () {
		// Detect fullscreen capability (mobile)
		var e = this.container.get(0);
		this.canFullScreen = e.requestFullscreen !== undefined ||
		e.mozRequestFullScreen !== undefined ||
		e.webkitRequestFullscreen !== undefined ||
		e.msRequestFullscreen !== undefined;

		// makes UI controls work in mobile version. Pinch only works on iOS
		var browser = new bigshot.Browser();
		this.container.children('input').each(function (i, e) {
			browser.registerListener(e, 'click', browser.stopEventBubblingHandler(), false);
			browser.registerListener(e, 'touchstart', browser.stopEventBubblingHandler(), false);
			browser.registerListener(e, 'touchend', browser.stopEventBubblingHandler(), false);
		});
	},

	zoomDecider: function () {
		if (this.fullScreen === null && this.currentImage.mimeType !== 'image/svg+xml') {
			this.zoomToOriginal();
		} else {
			this.zoomToFit();
		}
	},

	zoomToFit: function () {
		if (this.zoomable !== null) {
			this.zoomable.flyZoomToFit();
		}
	},

	zoomToOriginal: function () {
		if (this.zoomable === null) {
			return;
		}
		if (this.currentImage.isSmallImage) {
			this.zoomable.flyTo(0, 0, this.smallImageScale, true);
		} else {
			this.zoomable.flyTo(0, 0, 0, true);
		}
	},

	resetZoom: function () {
		if (this.zoomable === null) {
			return;
		}
		if (this.currentImage.isSmallImage) {
			this.zoomable.setZoom(this.smallImageScale, true);
		} else {
			this.zoomable.setZoom(0, true);
		}
	},

	fullScreenStart: function () {
		if (!this.canFullScreen) {
			return;
		}
		this.fullScreen = new bigshot.FullScreen(this.container.get(0));
		this.fullScreen.open();
		this.fullScreen.addOnClose(function () {
			this.fullScreenExit();
		}.bind(this));
	},

	fullScreenExit: function () {
		if (this.fullScreen === null) {
			return;
		}
		this.fullScreen.close();
		this.fullScreen = null;
		this.zoomDecider();

	},

	fullScreenToggle: function () {
		if (this.zoomable === null) {
			return;
		}
		if (this.fullScreen !== null) {
			this.fullScreenExit();
		} else {
			this.fullScreenStart();
		}
	},

	/**
	 *
	 * @param index
	 *
	 * @returns {*}
	 */
	show: function (index) {
		this.hideErrorNotification();
		this.container.show();
		this.container.css('background-position', 'center');
		this.hideImage();
		var currentImageId = index;
		return this.loadImage(this.images[index]).then(function (image) {
			this.container.css('background-position', '-10000px 0');
			this.container.find('.changeBackground').show();

			// check if we moved along while we were loading
			if (currentImageId === index) {
				this.errorLoadingImage = false;
				this.currentImage = image;
				this.currentImage.mimeType = this.images[index].mimeType;
				this.container.append(image);

				var extension = this.images[index].path.substr(this.images[index].path.length - 3);
				var backgroundColour = '#fff';
				if (extension.toLowerCase() === 'jpg') {
					backgroundColour = '#000';
				}
				image.setAttribute('alt', this.images[index].name);
				$(image).css('position', 'absolute');
				$(image).css('background-color', backgroundColour);
				var $border = 30 / window.devicePixelRatio;
				$(image).css('outline', $border + 'px solid ' + backgroundColour);

				this.startBigshot(image);

				this.setUrl(this.images[index].path);
				this.controls.show(currentImageId);
			}
		}.bind(this), function () {
			// Don't do anything if the user has moved along while we were loading as it would mess
			// up the index
			if (currentImageId === index) {
				this.errorLoadingImage = true;
				this.showErrorNotification();
				this.setUrl(this.images[index].path);
				this.images.splice(index, 1);
				this.controls.updateControls(this.images, this.errorLoadingImage);
{'fraction_non_alphanumeric': 0.15743654289909798, 'fraction_numerical': 0.005244388504300398, 'mean_word_length': 3.847483477376716, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '569662', 'n_tokens_mistral': 3512, 'n_tokens_neox': 3077, 'n_words': 633}