<commit_before>// --------------------------------------------------
// Helps with the search
// --------------------------------------------------
define(function (require) {
	
	// Dependencies
	var $ = require('jquery'),
		_ = require('underscore'),
		Backbone = require('backbone'),
		storage = require('decoy/plugins/kizzy')('decoy.search');

	// Make the key used to save the state
	var state_key = 'state-'+location.pathname;

	// Public view module
	var Search = Backbone.View.extend({
		
		// Properties
		visible: false,
				
		// Init
		initialize: function () {
			_.bindAll(this);
			
			// Set the initial state
			this.visible = storage.get('visible') ? true : false;
			if (this.visible) this.$el.show();
			
			// Cache selectors
			this.schema = this.$el.data('schema');
			this.title = this.$el.data('title');
			this.$conditions = this.$('.conditions');
			this.$submit = this.$conditions.find('button[type="submit"]');
			this.$search_actions = $('h1 .search-toggle').closest('.btn-group');
			
			// Make the add and substract buttons
			this.$add = $('<button type="button" class="btn add"><i class="icon-plus">');
			this.$subtract = $('<button type="button" class="btn subtract"><i class="icon-minus">');
			
			// Listen for the clicks on the open/close and clear buttons
			this.$search_actions.find('.search-toggle').click(this.toggle);
			this.$search_actions.find('.search-clear').click(this.clear);
			
			// Add an initial row
			if (this.defrost() === false) this.add();
			
			// Defer animation of the clear button
			_.defer(_.bind(function() {
				this.$search_actions.addClass('initialized');
			}, this));
			
			// Redirect the page to apply the filter if there is no query in the
			// url but there is at state.
			// Not currently applied cause it was weird UX
			// this.applyState();
			
		},
		
		// Events
		events: {
			'change .fields': 'change',
			'click .add': 'add',
			'click .subtract': 'subtract',
			'change .comparisons': 'freeze',
			'change .input-field': 'freeze',
			'input .input-field': 'freeze',
			'submit': 'submit'
		},
		
		//----------------------------------------------------------------
		// Render the UI
		//----------------------------------------------------------------
		
		// Toggle the search open and close
		toggle: function(e) {
			e.preventDefault();
			
			// Remember the state
			this.visible = !this.visible;
			storage.set('visible', this.visible);
			
			// Animate
			this.$el.slideToggle();
			this.toggleClear();
			
		},
		
		// The user has changed a condition to a different field
		change: function(e) {
			if (e) e.preventDefault();
			
			// Get the condition
			var $condition;
			if (e) $condition = $(e.target).closest('.condition');
			else $condition = this.$conditions.find('.condition').last();
			
			// Get the type
			var $fields = $condition.find('.fields'),
				field = $fields.val();
			
			// Add comparison options
			this.removeComparisons($condition);
			$condition.find('.fields').after(this.addComparisons(this.schema[field]));
			
			// Remember the form
			this.freeze();

		},
		
		// Return type specific comparison options
		addComparisons: function(meta) {
			switch(meta.type) {
				
				// Text input
				case 'text':
					return '<select class="comparisons">'+
							'<option value="%*%">contains</option>'+
							'<option value="=">is exactly</option>'+
							'<option value="*%">begins with</option>'+
							'<option value="%*">ends with</option>'+
							'<option value="!%*%">doesn\'t contain</option>'+
						'</select>'+
						'<input type="text" class="input input-field"/>';
				
				// Date selector
				case 'date':
					return $('<select class="comparisons">'+
							'<option value=">">is after</option>'+
							'<option value="<">is before</option>'+
							'<option value="=">is on</option>'+
						'</select>'+
						'<div class="input-append input date">'+
							'<input class="date input-field" maxlength="10" placeholder="mm/dd/yyyy" type="text">'+
							'<span class="add-on"><i class="icon-calendar"></i></span>'+
						'</div>').datepicker();
				
				// Number selector
				case 'number':
					return '<select class="comparisons">'+
							'<option value="=">is</option>'+
							'<option value="!=">is not</option>'+
							'<option value="<">is less than</option>'+
							'<option value=">">is greater than</option>'+
						'</select>'+
						'<input type="number" class="input input-field">';
				
				// Select menu
				case 'select':
					var comparisons = '<select class="comparisons">'+
							'<option value="=">is</option>'+
							'<option value="!=">is not</option>'+
						'</select>';
					var $select = $('<select class="input input-field">');
					_.each(meta.options, function(label, value) {
						$select.append($('<option>').text(label).val(value));
					});
					return comparisons + $select[0].outerHTML;
			}
		},
		
		// Remove any existing comparisons on a condition
		removeComparisons: function($condition) {
			$condition.find('.comparisons,.input').remove();
		},<commit_msg>Fixing the date selector being applied to the comparison select menu<commit_after>// --------------------------------------------------
// Helps with the search
// --------------------------------------------------
define(function (require) {
	
	// Dependencies
	var $ = require('jquery'),
		_ = require('underscore'),
		Backbone = require('backbone'),
		storage = require('decoy/plugins/kizzy')('decoy.search');

	// Make the key used to save the state
	var state_key = 'state-'+location.pathname;

	// Public view module
	var Search = Backbone.View.extend({
		
		// Properties
		visible: false,
				
		// Init
		initialize: function () {
			_.bindAll(this);
			
			// Set the initial state
			this.visible = storage.get('visible') ? true : false;
			if (this.visible) this.$el.show();
			
			// Cache selectors
			this.schema = this.$el.data('schema');
			this.title = this.$el.data('title');
			this.$conditions = this.$('.conditions');
			this.$submit = this.$conditions.find('button[type="submit"]');
			this.$search_actions = $('h1 .search-toggle').closest('.btn-group');
			
			// Make the add and substract buttons
			this.$add = $('<button type="button" class="btn add"><i class="icon-plus">');
			this.$subtract = $('<button type="button" class="btn subtract"><i class="icon-minus">');
			
			// Listen for the clicks on the open/close and clear buttons
			this.$search_actions.find('.search-toggle').click(this.toggle);
			this.$search_actions.find('.search-clear').click(this.clear);
			
			// Add an initial row
			if (this.defrost() === false) this.add();
			
			// Defer animation of the clear button
			_.defer(_.bind(function() {
				this.$search_actions.addClass('initialized');
			}, this));
			
			// Redirect the page to apply the filter if there is no query in the
			// url but there is at state.
			// Not currently applied cause it was weird UX
			// this.applyState();
			
		},
		
		// Events
		events: {
			'change .fields': 'change',
			'click .add': 'add',
			'click .subtract': 'subtract',
			'change .comparisons': 'freeze',
			'change .input-field': 'freeze',
			'input .input-field': 'freeze',
			'submit': 'submit'
		},
		
		//----------------------------------------------------------------
		// Render the UI
		//----------------------------------------------------------------
		
		// Toggle the search open and close
		toggle: function(e) {
			e.preventDefault();
			
			// Remember the state
			this.visible = !this.visible;
			storage.set('visible', this.visible);
			
			// Animate
			this.$el.slideToggle();
			this.toggleClear();
			
		},
		
		// The user has changed a condition to a different field
		change: function(e) {
			if (e) e.preventDefault();
			
			// Get the condition
			var $condition;
			if (e) $condition = $(e.target).closest('.condition');
			else $condition = this.$conditions.find('.condition').last();
			
			// Get the type
			var $fields = $condition.find('.fields'),
				field = $fields.val();
			
			// Add comparison options
			this.removeComparisons($condition);
			$condition.find('.fields').after(this.addComparisons(this.schema[field]));
			
			// Remember the form
			this.freeze();

		},
		
		// Return type specific comparison options
		addComparisons: function(meta) {
			switch(meta.type) {
				
				// Text input
				case 'text':
					return '<select class="comparisons">'+
							'<option value="%*%">contains</option>'+
							'<option value="=">is exactly</option>'+
							'<option value="*%">begins with</option>'+
							'<option value="%*">ends with</option>'+
							'<option value="!%*%">doesn\'t contain</option>'+
						'</select>'+
						'<input type="text" class="input input-field"/>';
				
				// Date selector
				case 'date':
					return $('<select class="comparisons">'+
							'<option value=">">is after</option>'+
							'<option value="<">is before</option>'+
							'<option value="=">is on</option>'+
						'</select>').add($(''+
						'<div class="input-append input date">'+
							'<input class="date input-field" maxlength="10" placeholder="mm/dd/yyyy" type="text">'+
							'<span class="add-on"><i class="icon-calendar"></i></span>'+
						'</div>').datepicker());
				
				// Number selector
				case 'number':
					return '<select class="comparisons">'+
							'<option value="=">is</option>'+
							'<option value="!=">is not</option>'+
							'<option value="<">is less than</option>'+
							'<option value=">">is greater than</option>'+
						'</select>'+
						'<input type="number" class="input input-field">';
				
				// Select menu
				case 'select':
					var comparisons = '<select class="comparisons">'+
							'<option value="=">is</option>'+
							'<option value="!=">is not</option>'+
						'</select>';
					var $select = $('<select class="input input-field">');
					_.each(meta.options, function(label, value) {
						$select.append($('<option>').text(label).val(value));
					});
					return comparisons + $select[0].outerHTML;
			}
		},
		
		// Remove any existing comparisons on a condition
		removeComparisons: function($condition) {
			$condition.find('.comparisons,.input').remove();
		},
{'fraction_non_alphanumeric': 0.22560376988022776, 'fraction_numerical': 0.0007853917141174161, 'mean_word_length': 2.5055058499655884, 'pattern_counts': {'":': 0, '<': 109, '<?xml version=': 0, '>': 109, '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': '7117714', 'n_tokens_mistral': 3826, 'n_tokens_neox': 2965, 'n_words': 716}