<commit_before>/*!
 * file upload
 * xiewulong <<EMAIL>>
 * create: 2015/2/27
 * version: 0.0.1
 */

(function($, window, document, undefined){
	var fileupload	= function(input, fn, prop){
			prop = prop || {};
			this.input = input;
			this.name = input.name;
			this.$input = $(input);
			this.$parent = this.$input.parent();
			this.action = prop.action || this.$input.attr('data-action');
			this.min = prop.min || this.$input.attr('data-min');
			this.max = prop.max || this.$input.attr('data-max');
			this.type = prop.type || this.$input.attr('data-type');
			this.sizes = prop.sizes || this.$input.attr('data-sizes');
			this.oss = prop.oss || this.$input.attr('data-oss');
			this.csrf = prop.csrf || this.$input.attr('data-csrf');
			this.pre = prop.pre || 'xFileupload';
			this.before = prop.before || function(){};
			this.fn = fn;

			this.input.value && this.action && this.fn && this.upload();
		};
	
	fileupload.prototype = {
		upload: function(){
			var _this = this;
			this.before && this.before.call(this.input);
			this.setName();
			this.createElements();
			window[_this.input.name] = function(d){_this.callback(d);};
			this.$form.submit();
		},
		createElements: function(){
			this.$iframe = $('<iframe style="display:none;" name="' + this.input.name + '"></iframe>').appendTo('body');
			this.$form = $('<form style="display:none;" action="' + this.action + '" target="' + this.input.name + '" method="post" enctype="multipart/form-data"></form>').appendTo('body');
			this.min && this.$form.append('<input type="hidden" name="min" value="' + this.min + '" />');
			this.max && this.$form.append('<input type="hidden" name="max" value="' + this.max + '" />');
			this.type && this.$form.append('<input type="hidden" name="type" value="' + this.type + '" />');
			this.sizes && this.$form.append('<input type="hidden" name="sizes" value="' + this.sizes + '" />');
			this.oss && this.$form.append('<input type="hidden" name="oss" value="' + this.oss + '" />');
			this.csrf && this.$form.append('<input type="hidden" name="_csrf" value="' + this.csrf + '" />');
			this.$form.append('<input type="hidden" name="name" value="' + this.input.name + '" />');
			this.$form.append(this.input);
		},
		setName: function(){
			var random = (+ new Date()).toString() + Math.floor(Math.random() * 899 + 100).toString();
			this.input.name = this.pre + random;
		},
		callback: function(d){
			this.input.name = this.name;
			this.input.value = '';
			this.$parent.append(this.input);
			this.$form.remove();
			this.$iframe.remove();
			this.fn.call(this.input, d);
		}
	}

	$(document).on('change', '[data-fileupload]', function(){
		new fileupload(this, function(d){
			$(this).trigger('uploaded.x.file', d);
		}, {'before': function(){
			$(this).trigger('upload.x.file');
		}});
	});

	$.fn.fileupload = function(fn, prop){
		return this.on('change', function(){
			new fileupload(this, fn, prop);
		});
	};

	window.xFileupload = fileupload;
})(jQuery, window, document);<commit_msg>fileupload<commit_after>/*!
 * file upload
 * xiewulong <<EMAIL>>
 * create: 2015/2/27
 * version: 0.0.1
 */

(function($, window, document, undefined) {
	var fileupload	= function(input, fn, prop) {
			prop = prop || {};
			this.input = input;
			this.name = input.name;
			this.$input = $(input);
			this.$parent = this.$input.parent();
			this.action = prop.action || this.$input.attr('data-action');
			this.min = prop.min || this.$input.attr('data-min');
			this.max = prop.max || this.$input.attr('data-max');
			this.type = prop.type || this.$input.attr('data-type');
			this.sizes = prop.sizes || this.$input.attr('data-sizes');
			this.oss = prop.oss || this.$input.attr('data-oss');
			this.csrf = prop.csrf || this.$input.attr('data-csrf');
			this.pre = prop.pre || 'xFileupload';
			this.before = prop.before || function() {};
			this.fn = fn;

			this.input.value && this.action && this.fn && this.upload();
		};
	
	fileupload.prototype = {
		upload: function() {
			var _this = this;
			this.before && this.before.call(this.input);
			this.setName();
			this.createElements();
			window[_this.input.name] = function(d) {_this.callback(d);};
			this.$form.submit();
		},
		createElements: function() {
			this.$iframe = $('<iframe style="display:none;" name="' + this.input.name + '"></iframe>').appendTo('body');
			this.$form = $('<form style="display:none;" action="' + this.action + '" target="' + this.input.name + '" method="post" enctype="multipart/form-data"></form>').appendTo('body');
			this.min && this.$form.append('<input type="hidden" name="min" value="' + this.min + '" />');
			this.max && this.$form.append('<input type="hidden" name="max" value="' + this.max + '" />');
			this.type && this.$form.append('<input type="hidden" name="type" value="' + this.type + '" />');
			this.sizes && this.$form.append('<input type="hidden" name="sizes" value="' + this.sizes + '" />');
			this.oss && this.$form.append('<input type="hidden" name="oss" value="' + this.oss + '" />');
			this.csrf && this.$form.append('<input type="hidden" name="_csrf" value="' + this.csrf + '" />');
			this.$form.append('<input type="hidden" name="name" value="' + this.input.name + '" />');
			this.$form.append(this.input);
		},
		setName: function() {
			var random = (+ new Date()).toString() + Math.floor(Math.random() * 899 + 100).toString();
			this.input.name = this.pre + random;
		},
		callback: function(d) {
			this.input.name = this.name;
			this.input.value = '';
			this.$parent.append(this.input);
			this.$form.remove();
			this.$iframe.remove();
			this.fn.call(this.input, d);
		}
	}

	$(document).on('change', '[data-fileupload]', function() {
		new fileupload(this, function(d) {
			$(this).trigger('uploaded.x.file', d);
		}, {'before': function() {
			$(this).trigger('upload.x.file');
		}});
	});

	$.fn.fileupload = function(fn, prop) {
		return this.on('change', function() {
			new fileupload(this, fn, prop);
		});
	};

	window.xFileupload = fileupload;
})(jQuery, window, document);
{'fraction_non_alphanumeric': 0.2361341746927931, 'fraction_numerical': 0.005313849219528396, 'mean_word_length': 3.810702875399361, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 0, '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': '5289853', 'n_tokens_mistral': 2288, 'n_tokens_neox': 2021, 'n_words': 362}