<commit_before>/*
	TemPIC - Copyright (c) PotcFdk, 2014 - 2017

	Licensed under the Apache License, Version 2.0 (the "License");
	you may not use this file except in compliance with the License.
	You may obtain a copy of the License at
	
	http://www.apache.org/licenses/LICENSE-2.0
	
	Unless required by applicable law or agreed to in writing, software
	distributed under the License is distributed on an "AS IS" BASIS,
	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
	See the License for the specific language governing permissions and
	limitations under the License.
*/

// Detect browser capabilities
function isUpToDate () {
	return Modernizr.filereader && Modernizr.flexbox && window.FormData !== undefined
}

function canUseFormData () {
	return window.FormData !== undefined
}

function tempicOnLoad () {
	if (isUpToDate ())
		document.getElementById("browser_warning_text").style.display = 'none';
}

function resetTitle () {
	if ($.type(album_name) == 'string')
		document.title = album_name + " - " + instance_name;
	else
		document.title = instance_name;
}

function initRemainingLifetime (remaining)
{	
	function updateRemainingLifetime () {
		if (remaining > 0) {
			$('#lifetime_text').html('<p><span class="label label-info">Album removal</span> Remaining time: '
				+ millisecondsToAccurateStr (remaining*1000)+'</p>');
			-- remaining;
		} else {
			$('#lifetime_text').html('<p><span class="label label-danger">Removed</span> '
				+ 'This album has been removed.</p>');
			setInterval (function() { window.location = url_base; }, 1000);
		}
	}
	updateRemainingLifetime();
	setInterval (updateRemainingLifetime, 1000);
}

function retryThumbnail (obj) {
	var src = obj.data('src');

	if (!src)
		throw new Error('Cannot retry thumbnail: Object has no src!');

	obj.data('failure', false);
	obj.attr('src', src);
}

function onThumbnailLoad (obj) {
	obj = $(obj);
	if (!obj.data('failure')) {
		obj.removeClass('no-thumbnail');
		obj.attr('alt', 'Uploaded Image');
	}
}

function onThumbnailError (obj) {
	obj = $(obj);

	if (!obj.data('src'))
		obj.data('src', obj.attr('src'));
	
	if (!obj.data('failure')) {
		obj.data('failure', true);
		obj.attr('alt', 'Thumbnail currently unavailable.');
		obj.addClass('no-thumbnail');
		obj.attr('src', 'img/ico_loading.gif');
		setTimeout(retryThumbnail, 30000, obj);
	}

	info('Some thumbnails have not yet been generated.');
}

var fileBrowse;

$(function() {
	$('#div_filelist_preview').hide();
	$('#div_albumname_input').hide();
	$('#div_albumdescription_input').hide();
	$('#div_warn_element').hide();
	$('#warn_element').hide();
	$('#div_progressbar').hide();
	$('#progressbar').hide();
	$('#div_progresstext').hide();
	$(".checksum-field").hide();
	$("#button-file-wipe").hide();
	$("#button-upload").hide();
	$("#button-abort").hide();
	
	var upload_in_progress = false;

	var base_text = $('#checksums-toggle').text();
	var is_showing_checksums = false;
	$('#checksums-toggle').on('click', function() {
		if (is_showing_checksums) {
			is_showing_checksums = false;
			$(".checksum-field").hide(300);
			$('#checksums-toggle').text(base_text);
		} else {
			is_showing_checksums = true;
			$(".checksum-field").show(300);
			$('#checksums-toggle').text(base_text.replace("Show","Hide"));
		}
	});
	
	var fileInput = $('#file');
	fileBrowse = function () {
		// fileInput show()/hide():
		//  compatibility hack (e.g. older android devices)

		if (!isUpToDate ())
			fileInput.show ();
		fileInput.click();
		if (!isUpToDate ())
			fileInput.hide ();
	}

	var upload_started = 0;
	
	function uploadProgress(evt) {
	  if (evt.lengthComputable) {
		var percentComplete = evt.loaded * 100 / evt.total;
		var percentCompleteStr = Math.round(percentComplete).toString() + " %";
		var duration = (Date.now() - upload_started);
		var speed = evt.loaded / duration;
		$('#progressbar').attr('value', percentComplete.toString());
		$('#progresstext').html("Uploading: " + percentCompleteStr + "<br />"
			+ humanFileSize(evt.loaded) + " / " + humanFileSize(evt.total) + " total"
				+ " @ " + humanFileSize((speed*1000).toFixed(2)) + " per second<br />"
			+ "Elapsed: " + millisecondsToStr(duration) + "<br />"
			+ 'ETA: ' + millisecondsToStr((evt.total - evt.loaded)/speed));
		document.title = percentCompleteStr + " - " + instance_name + " (uploading)";
	  }
	  else {
		$('#progressbar').removeAttr('value');
	  }
	}
	
	function uploadBegin() {
		upload_in_progress = true;
		
		$("#button-file-wipe").hide();
		$("#button-upload").hide();
		$("#button-abort").show();
		$('#button-browse').prop('disabled', true);
		
		$('#lifetime').prop('disabled', true);
		
		$('#div_progress').hide();
		
		$('#div_progressbar').show();
		$('#progressbar').show();
		$('#div_progresstext').show();
		
		$('#div_upload_data').slideUp(400, 'swing', function() {
			$('#div_progress').slideDown(400, 'swing');
		});
	}
	
	function uploadEnd() {
		upload_in_progress = false;<commit_msg>feature: confirm before closing while uploading<commit_after>/*
	TemPIC - Copyright (c) PotcFdk, 2014 - 2017

	Licensed under the Apache License, Version 2.0 (the "License");
	you may not use this file except in compliance with the License.
	You may obtain a copy of the License at
	
	http://www.apache.org/licenses/LICENSE-2.0
	
	Unless required by applicable law or agreed to in writing, software
	distributed under the License is distributed on an "AS IS" BASIS,
	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
	See the License for the specific language governing permissions and
	limitations under the License.
*/

// Detect browser capabilities
function isUpToDate () {
	return Modernizr.filereader && Modernizr.flexbox && window.FormData !== undefined
}

function canUseFormData () {
	return window.FormData !== undefined
}

function tempicOnLoad () {
	if (isUpToDate ())
		document.getElementById("browser_warning_text").style.display = 'none';
}

function resetTitle () {
	if ($.type(album_name) == 'string')
		document.title = album_name + " - " + instance_name;
	else
		document.title = instance_name;
}

function initRemainingLifetime (remaining)
{	
	function updateRemainingLifetime () {
		if (remaining > 0) {
			$('#lifetime_text').html('<p><span class="label label-info">Album removal</span> Remaining time: '
				+ millisecondsToAccurateStr (remaining*1000)+'</p>');
			-- remaining;
		} else {
			$('#lifetime_text').html('<p><span class="label label-danger">Removed</span> '
				+ 'This album has been removed.</p>');
			setInterval (function() { window.location = url_base; }, 1000);
		}
	}
	updateRemainingLifetime();
	setInterval (updateRemainingLifetime, 1000);
}

function retryThumbnail (obj) {
	var src = obj.data('src');

	if (!src)
		throw new Error('Cannot retry thumbnail: Object has no src!');

	obj.data('failure', false);
	obj.attr('src', src);
}

function onThumbnailLoad (obj) {
	obj = $(obj);
	if (!obj.data('failure')) {
		obj.removeClass('no-thumbnail');
		obj.attr('alt', 'Uploaded Image');
	}
}

function onThumbnailError (obj) {
	obj = $(obj);

	if (!obj.data('src'))
		obj.data('src', obj.attr('src'));
	
	if (!obj.data('failure')) {
		obj.data('failure', true);
		obj.attr('alt', 'Thumbnail currently unavailable.');
		obj.addClass('no-thumbnail');
		obj.attr('src', 'img/ico_loading.gif');
		setTimeout(retryThumbnail, 30000, obj);
	}

	info('Some thumbnails have not yet been generated.');
}

var fileBrowse;

$(function() {
	$('#div_filelist_preview').hide();
	$('#div_albumname_input').hide();
	$('#div_albumdescription_input').hide();
	$('#div_warn_element').hide();
	$('#warn_element').hide();
	$('#div_progressbar').hide();
	$('#progressbar').hide();
	$('#div_progresstext').hide();
	$(".checksum-field").hide();
	$("#button-file-wipe").hide();
	$("#button-upload").hide();
	$("#button-abort").hide();
	
	var upload_in_progress = false;

	var base_text = $('#checksums-toggle').text();
	var is_showing_checksums = false;
	$('#checksums-toggle').on('click', function() {
		if (is_showing_checksums) {
			is_showing_checksums = false;
			$(".checksum-field").hide(300);
			$('#checksums-toggle').text(base_text);
		} else {
			is_showing_checksums = true;
			$(".checksum-field").show(300);
			$('#checksums-toggle').text(base_text.replace("Show","Hide"));
		}
	});
	
	var fileInput = $('#file');
	fileBrowse = function () {
		// fileInput show()/hide():
		//  compatibility hack (e.g. older android devices)

		if (!isUpToDate ())
			fileInput.show ();
		fileInput.click();
		if (!isUpToDate ())
			fileInput.hide ();
	}

	var upload_started = 0;
	
	function uploadProgress(evt) {
	  if (evt.lengthComputable) {
		var percentComplete = evt.loaded * 100 / evt.total;
		var percentCompleteStr = Math.round(percentComplete).toString() + " %";
		var duration = (Date.now() - upload_started);
		var speed = evt.loaded / duration;
		$('#progressbar').attr('value', percentComplete.toString());
		$('#progresstext').html("Uploading: " + percentCompleteStr + "<br />"
			+ humanFileSize(evt.loaded) + " / " + humanFileSize(evt.total) + " total"
				+ " @ " + humanFileSize((speed*1000).toFixed(2)) + " per second<br />"
			+ "Elapsed: " + millisecondsToStr(duration) + "<br />"
			+ 'ETA: ' + millisecondsToStr((evt.total - evt.loaded)/speed));
		document.title = percentCompleteStr + " - " + instance_name + " (uploading)";
	  }
	  else {
		$('#progressbar').removeAttr('value');
	  }
	}
	
	function uploadBegin() {
		upload_in_progress = true;
		window.onbeforeunload = function (e) {
			e = e || window.event;
		
			// For IE and Firefox prior to version 4
			if (e) {
				e.returnValue = 'Sure?';
			}
		
			// For Safari
			return 'Sure?';
		}
		
		$("#button-file-wipe").hide();
		$("#button-upload").hide();
		$("#button-abort").show();
		$('#button-browse').prop('disabled', true);
		
		$('#lifetime').prop('disabled', true);
		
		$('#div_progress').hide();
		
		$('#div_progressbar').show();
		$('#progressbar').show();
		$('#div_progresstext').show();
		
		$('#div_upload_data').slideUp(400, 'swing', function() {
			$('#div_progress').slideDown(400, 'swing');
		});
	}
	
	function uploadEnd() {
		upload_in_progress = false;
		window.onbeforeunload = undefined;
{'fraction_non_alphanumeric': 0.1879043324838267, 'fraction_numerical': 0.010096059596157616, 'mean_word_length': 4.412732095490716, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, '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': '6236026', 'n_tokens_mistral': 3691, 'n_tokens_neox': 3371, 'n_words': 710}