<commit_before>/**
 * Pure JS XHR2 upload with jQuery Plugin
 * 
 * Allows to bind an XHR2 upload to any DOM element event without a form
 * Works only with IE >= 10, because IE 9 does not support XHR2 objects
 * Tested on Chrome, IE10 and Firefox
 *
 * @author by <NAME>
 * @version 0.1
 * @link https://github.com/cvelazquez/javascript.uploader
 */
var uploader = uploader || {};
(function(o){
	"use strict";

	var randomId = Math.ceil(Math.random()*100000);

	var _createForm = function(options){
		if ( !document.getElementById("uploadForm"+randomId+"Input") ) {
			var _input = document.createElement("input");
			_input.setAttribute("type", "file");
			_input.setAttribute("id", "uploadForm"+randomId+"Input");
			_input.setAttribute("multiple", "multiple");
			_input.style.position = "fixed"; // Hidden inputs can not trigger click events in a few browsers / versions
			_input.style.top = "-100px";
			options.files = _input;
			delete options.useGlobalForm;
			_input.addEventListener("change", function(){
				o.send(options);
			});
			if ( document.body ) {
				document.body.appendChild(_input);
			}
		} else {
			var _input = document.getElementById("uploadForm"+randomId+"Input");
		}
		var e = document.createEvent("MouseEvents");
		e.initEvent("click", true, true);
		_input.dispatchEvent(e, true);
	};

	var _getFormData = function(options){
		var f = new FormData();
		for ( var i = 0; i < options.files.files.length; i++ ) {
			f.append("data[files][]", options.files.files[i]); // CakePHP $this->request->data['files'], Mormal PHP $_POST["data"]["files"];
		}
		options.formData = f;
		return options;
	};

	var _upload = function(options){
		var ajax = new XMLHttpRequest();
		ajax.upload.addEventListener("progress", function(e){
			if ( e.lengthComputable === true ) {
				if ( typeof options.progress == "function" ) {
					options.progress(Math.round(e.loaded/e.total*100));
				}
			}
		});

		ajax.addEventListener("readystatechange", function(){
			if ( this.readyState == 4 ) {
				if ( this.status == 200 ) {
					if ( typeof options.finished == "function" ) {
						options.finished(JSON.parse(this.response));
					}
				} else {
					if ( typeof options.error == "function" ) {
						options.error(this.status);
					}
				}
			}
		});

		ajax.open("post",options.url);
		ajax.send(options.formData);
	};

	o.send = function(options){
		if ( o.supported ) {
			if ( options.files && !options.useGlobalForm ) {
				if ( options.files.files.length ) {
					_upload(_getFormData(options));
				}
			} else {
				_createForm(options);
			}
		}
	};

	o.supported = 'upload' in new XMLHttpRequest;

})(uploader);

/** jQuery Plugin **/
if ( typeof jQuery != "undefined" ) {
	(function ($) {
		$.fn.autoupload = function(options) {
			if ( typeof options == "object" ) {
				$.each(this, function(i, obj){
					if ( obj.tagName.toLowerCase() == "input" && obj.hasAttribute("type") && obj.getAttribute("type") == "file" ) {
						options.files = obj;
						$(obj).on({
							change: function(e){
								uploader.send(options);
							}
						});
					} else {
						options.useGlobalForm = true;
						$(obj).on({
							click: function(e){
								uploader.send(options);
							}
						});
					}
				})
			}
		};
	}( jQuery ));
}<commit_msg>Updated to v0.2<commit_after>/**
 * Pure JS XHR2 upload with jQuery Plugin
 * 
 * Allows to bind an XHR2 upload to any DOM element event without a form
 * Works only with IE >= 10, because IE 9 does not support XHR2 objects
 * Tested on Chrome, IE10 and Firefox
 *
 * @author by <NAME>
 * @version 0.2
 * @link https://github.com/cvelazquez/javascript.uploader
 */
var uploader = uploader || {};
(function(o){
	"use strict";

	var randomId = Math.ceil(Math.random()*100000);
	var binded = false;

	o.createInput = function(options){
		if ( !document.getElementById("uploadForm"+randomId+"Input") ) {
			var _input = document.createElement("input");
			_input.setAttribute("type", "file");
			_input.setAttribute("id", "uploadForm"+randomId+"Input");
			_input.setAttribute("multiple", "multiple");
			_input.style.position = "fixed"; // Hidden inputs can not trigger click events in a few browsers / versions
			_input.style.top = "-100px";
			options.files = _input;
			binded = true;
			_input.addEventListener("change", function(){
				o.send(options);
			});
			if ( document.body ) {
				document.body.appendChild(_input);
			}
		} else {
			var _input = document.getElementById("uploadForm"+randomId+"Input");
		}
		var e = document.createEvent("MouseEvents");
		e.initEvent("click", true, true);
		_input.dispatchEvent(e, true);
	};

	var _getFormData = function(options){
		var f = new FormData();
		for ( var i = 0; i < options.files.files.length; i++ ) {
			f.append("data[files][]", options.files.files[i]); // CakePHP $this->request->data['files'], Normal PHP $_POST["data"]["files"];
		}
		options.formData = f;
		return options;
	};

	var _upload = function(options){
		var ajax = new XMLHttpRequest();
		ajax.upload.addEventListener("progress", function(e){
			if ( e.lengthComputable === true ) {
				if ( typeof options.progress == "function" ) {
					options.progress(Math.round(e.loaded/e.total*100));
				}
			}
		});

		ajax.addEventListener("readystatechange", function(){
			if ( this.readyState == 4 ) {
				options.files.value = '';
				if ( this.status == 200 ) {
					if ( typeof options.finished == "function" ) {
						options.finished(JSON.parse(this.response));
					}
				} else {
					if ( typeof options.error == "function" ) {
						options.error(this.status);
					}
				}
			}
		});

		ajax.open("post",options.url);
		ajax.send(options.formData);
	};

	o.send = function(options){
		if ( o.supported ) {
			if ( options.files && binded ) {
				console.log('_getFormData')
				if ( options.files.files.length ) {
					_upload(_getFormData(options));
				}
			}
		}
	};

	o.supported = 'upload' in new XMLHttpRequest;

})(uploader);

/** jQuery Plugin **/
if ( typeof jQuery != "undefined" ) {
	(function ($) {
		$.fn.autoupload = function(options) {
			var options = $.extend({}, options);
			if ( typeof options == "object" ) {
				$.each(this, function(i, obj){
					if ( obj.tagName.toLowerCase() == "input" && obj.hasAttribute("type") && obj.getAttribute("type") == "file" ) {
						options.files = obj;
						$(obj).off('change').on({
							change: function(e){
								uploader.send(options);
							}
						});
					} else {
						$(obj).off('click').on({
							click: function(e){
								uploader.createInput(options);
							}
						});
					}
				})
			}
		};
	}( jQuery ));
}
{'fraction_non_alphanumeric': 0.1706060606060606, 'fraction_numerical': 0.008484848484848486, 'mean_word_length': 3.1594202898550723, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, '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': '445511', 'n_tokens_mistral': 2608, 'n_tokens_neox': 2110, 'n_words': 458}