<commit_before>define(

	[
		"rosy/base/DOMClass",
		"$",
		"$plugin!select2",
		"./WidgetEvents",
		"./WindowPopup"
	],

	function (DOMClass, $, jQuerySelect2, WidgetEvents, WindowPopup) {

		"use strict";

		return DOMClass.extend({

			dom : null,
			preview : null,
			input : null,

			count : 0,

			popup : null,

			init : function (dom) {
				this.dom = dom;
				this.input = dom.find('input');
				this.preview = dom.find('.widget-asset-preview');
				this._autoTag();
				this._initSelect2();
			},

			_initSelect2 : function () {
				this.input.select2({
					placeholder : "Choose an asset",
					//minimumInputLength : 2,
					allowClear : true,
					initSelection : this.initSelection,
					formatSelection : this.formatSelection,
					formatResult : this.formatResult,
					ajax : {
						url : this.dom.data('api'),
						quietMillis : 500,
						dataType : "json",
						data : this._ajaxData,
						results : this._ajaxResults
					}
				});

				this.input.on('change', this.onChange);

				this._tag();

				this.dom.on('click', '.button', this._openPopup);
			},

			_openPopup : function (e) {
				var dom = $(e.currentTarget),
					url = dom.attr('href'),
					options = 'menubar=no,location=no,resizable=no,scrollbars=yes,status=no,height=500,width=800';

				WindowPopup.request(url, options, this._gotDataFromPopup);

				return false;
			},

			_gotDataFromPopup : function (data) {
				this.input.select2('data', data);
			},

			_autoTag : function () {
				var tags = [];
				$('[data-auto-tag]').each(function (i, dom) {
					var data_auto_tag = $(dom).data('auto-tag');
					if (data_auto_tag) {
						var allTags = data_auto_tag.toLowerCase().split(',');
						while (allTags.length) {
							var tag = allTags.shift();
							if (tag.match(/[a-z0-9]/i) && tag.length > 3) {
								tags.push(tag);
							}
						}
						tags = tags.concat(allTags);
					}
				});
				$('#auto_tags').val(tags.join(','));
				this._auto_tags = tags;
			},

			_tag : function () {

				if (!this.dom.find('a.button').length) {
					return;
				}

				var dom = this.dom.find('a.button'),
					params = this._unparam(dom[0].search),
					tags = ($(this.dom).data('tags') || '').toLowerCase().split(',');

				tags = tags.concat(this._all_tags);
				params.tags = encodeURIComponent(tags.join(','));
				dom[0].search = this._param(params);
			},

			_param : function (obj) {
				var op = [],
					i;
				for (i in obj) {
					op.push(i + '=' + obj[i]);
				}
				return "?" + op.join('&');
			},<commit_msg>fix Task #13175, bug in the javascript that collects the auto tags<commit_after>define(

	[
		"rosy/base/DOMClass",
		"$",
		"$plugin!select2",
		"./WidgetEvents",
		"./WindowPopup"
	],

	function (DOMClass, $, jQuerySelect2, WidgetEvents, WindowPopup) {

		"use strict";

		return DOMClass.extend({

			dom : null,
			preview : null,
			input : null,

			count : 0,

			popup : null,

			init : function (dom) {
				this.dom = dom;
				this.input = dom.find('input');
				this.preview = dom.find('.widget-asset-preview');
				this._autoTag();
				this._initSelect2();
			},

			_initSelect2 : function () {
				this.input.select2({
					placeholder : "Choose an asset",
					//minimumInputLength : 2,
					allowClear : true,
					initSelection : this.initSelection,
					formatSelection : this.formatSelection,
					formatResult : this.formatResult,
					ajax : {
						url : this.dom.data('api'),
						quietMillis : 500,
						dataType : "json",
						data : this._ajaxData,
						results : this._ajaxResults
					}
				});

				this.input.on('change', this.onChange);

				this._tag();

				this.dom.on('click', '.button', this._openPopup);
			},

			_openPopup : function (e) {
				var dom = $(e.currentTarget),
					url = dom.attr('href'),
					options = 'menubar=no,location=no,resizable=no,scrollbars=yes,status=no,height=500,width=800';

				WindowPopup.request(url, options, this._gotDataFromPopup);

				return false;
			},

			_gotDataFromPopup : function (data) {
				this.input.select2('data', data);
			},

			_autoTag : function () {
				var tags = [];
				$('[data-auto-tag]').each(function (i, dom) {
					var data_auto_tag = $(dom).data('auto-tag');
					if (data_auto_tag) {
						var allTags = data_auto_tag.toLowerCase().split(',');
						while (allTags.length) {
							var tag = allTags.shift();
							if (tag.match(/[a-z0-9]/i) && tag.length > 3) {
								tags.push(tag);
							}
						}
						tags = tags.concat(allTags);
					}
				});
				$('#auto_tags').val(tags.join(','));
				this._auto_tags = tags;
			},

			_tag : function () {

				if (!this.dom.find('a.button').length) {
					return;
				}

				var dom = this.dom.find('a.button'),
					params = this._unparam(dom[0].search),
					tags = ($(this.dom).data('tags') || '').toLowerCase().split(',');

				tags = tags.concat(this._auto_tags);
				params.tags = encodeURIComponent(tags.join(','));
				dom[0].search = this._param(params);
			},

			_param : function (obj) {
				var op = [],
					i;
				for (i in obj) {
					op.push(i + '=' + obj[i]);
				}
				return "?" + op.join('&');
			},
{'fraction_non_alphanumeric': 0.18128425998433828, 'fraction_numerical': 0.009592795614722005, 'mean_word_length': 2.5727272727272728, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '934464', 'n_tokens_mistral': 2355, 'n_tokens_neox': 1760, 'n_words': 315}