<commit_before>$(document).ready(function() {
	
	/**
	 * Show/hide activechildelements containers (necessary in order to deal with padding)
	 */
	showActiveChildElements();

	function showActiveChildElements() {
		$('#active_elements .active_child_elements').each(function() {
			if($('.element', this).length) {
				$(this).show();
			} else {
				$(this).hide();
			}
		});
	}
	
	/**
	 * Autoadjust height of textareas
	 */
	$('#event_display textarea.autosize:visible').autosize();

	/**
	 * Add all optional elements
	 */
	$('.optionals-header').delegate('.add-all', 'click', function(e) {
		if($(this).closest('.element').length) {
			$(this).closest('.element').find('.inactive_child_elements .element').each(function() {
				$(this).addClass('clicked');
				addElement(this, true, true);
			});
		}
		else {
			$('#inactive_elements .element').each(function() {
				$(this).addClass('clicked');
				addElement(this, false);
			});
		}
		e.preventDefault();
	});

	/**
	 * Add an optional element
	 */
	$('#inactive_elements').delegate('.element', 'click', function(e) {
		if (!$(this).hasClass('clicked')) {
			$(this).addClass('clicked');
			addElement(this);
		}
		e.preventDefault();
	});
	
	function addElement(element, animate, is_child, import_previous) {
		if (typeof (animate) === 'undefined')
			animate = true;
		if (typeof (is_child) === 'undefined')
			is_child = false;
		if (typeof (import_previous) === 'undefined')
			import_previous = false;
		
		var element_type_id = $(element).attr('data-element-type-id');
		var display_order = $(element).attr('data-element-display-order');
		$.get(baseUrl + "/" + moduleName + "/Default/ElementForm", {
			id : element_type_id,
			patient_id : et_patient_id,
			import_previous: (import_previous) ? 1 : 0,
		}, function(data) {
			if (is_child) {
				var container = $(element).closest('.inactive_child_elements').parent().find('.active_child_elements:first');
			} else {
				var container = $('#active_elements');
			}
			
			$(element).remove();
			var insert_before = container.find('.element').first();
			
			while (parseInt(insert_before.attr('data-element-display-order')) < parseInt(display_order)) {
				insert_before = insert_before.nextAll('div:first');
			}
			if (insert_before.length) {
				insert_before.before(data);
			} else {
				$(container).append(data);
			}
			
			$('#event_display textarea.autosize:visible').autosize();
			showActiveChildElements();
				
			var inserted = (insert_before.length) ? insert_before.prevAll('div:first') : container.find('.element:last');
			if (animate) {
				var offTop = inserted.offset().top - 50;
				var speed = (Math.abs($(window).scrollTop() - offTop)) * 1.5;
				$('body').animate({
					scrollTop : offTop
				}, speed, null, function() {
					$('.elementTypeName', inserted).effect('pulsate', {
						times : 2
					}, 600);
				});
			}
			
			var el_class = $(element).attr('data-element-type-class');
			var initFunctionName = el_class.replace('Element_', '') + '_init';
			if(typeof(window[initFunctionName]) == 'function') {
				window[initFunctionName]();
			}

			// now init any children
			$(".element." + el_class).find('.active_child_elements').find('.element').each(function() {
				var initFunctionName = $(this).attr('data-element-type-class').replace('Element_', '') + '_init';<commit_msg>+ ensure that child elements reflect the sided behaviour of their parent<commit_after>$(document).ready(function() {
	
	/**
	 * Show/hide activechildelements containers (necessary in order to deal with padding)
	 */
	showActiveChildElements();

	function showActiveChildElements() {
		$('#active_elements .active_child_elements').each(function() {
			if($('.element', this).length) {
				$(this).show();
			} else {
				$(this).hide();
			}
		});
	}
	
	/**
	 * Autoadjust height of textareas
	 */
	$('#event_display textarea.autosize:visible').autosize();

	/**
	 * Add all optional elements
	 */
	$('.optionals-header').delegate('.add-all', 'click', function(e) {
		if($(this).closest('.element').length) {
			$(this).closest('.element').find('.inactive_child_elements .element').each(function() {
				$(this).addClass('clicked');
				addElement(this, true, true);
			});
		}
		else {
			$('#inactive_elements .element').each(function() {
				$(this).addClass('clicked');
				addElement(this, false);
			});
		}
		e.preventDefault();
	});

	/**
	 * Add an optional element
	 */
	$('#inactive_elements').delegate('.element', 'click', function(e) {
		if (!$(this).hasClass('clicked')) {
			$(this).addClass('clicked');
			addElement(this);
		}
		e.preventDefault();
	});
	
	function addElement(element, animate, is_child, import_previous) {
		if (typeof (animate) === 'undefined')
			animate = true;
		if (typeof (is_child) === 'undefined')
			is_child = false;
		if (typeof (import_previous) === 'undefined')
			import_previous = false;
		
		var element_type_id = $(element).attr('data-element-type-id');
		var element_type_class = $(element).attr('data-element-type-class');
		
		var display_order = $(element).attr('data-element-display-order');
		$.get(baseUrl + "/" + moduleName + "/Default/ElementForm", {
			id : element_type_id,
			patient_id : et_patient_id,
			import_previous: (import_previous) ? 1 : 0,
		}, function(data) {
			if (is_child) {
				var container = $(element).closest('.inactive_child_elements').parent().find('.active_child_elements:first');
			} else {
				var container = $('#active_elements');
			}
			
			$(element).remove();
			var insert_before = container.find('.element').first();
			
			while (parseInt(insert_before.attr('data-element-display-order')) < parseInt(display_order)) {
				insert_before = insert_before.nextAll('div:first');
			}
			if (insert_before.length) {
				insert_before.before(data);
			} else {
				$(container).append(data);
			}
			
			if (is_child) {
				// check if this is sided
				// and match the parent active sides if it is
				var cel = $(container).find('.'+element_type_class);
				var pel = $(container).parents('.element');
				var sideField = $(cel).find('input.sideField');
				if ($(sideField).length && $(pel).find('input.sideField').length) {
					$(sideField).val($(pel).find('.sideField').val());
					
					if($(sideField).val() == '1') {
						$(cel).find('.side.left').addClass('inactive');
					}
					else if ($(sideField).val() == '2') {
						$(cel).find('.side.right').addClass('inactive');
					}
				}				
			}
			
			$('#event_display textarea.autosize:visible').autosize();
			showActiveChildElements();
				
			var inserted = (insert_before.length) ? insert_before.prevAll('div:first') : container.find('.element:last');
			if (animate) {
				var offTop = inserted.offset().top - 50;
				var speed = (Math.abs($(window).scrollTop() - offTop)) * 1.5;
				$('body').animate({
					scrollTop : offTop
				}, speed, null, function() {
					$('.elementTypeName', inserted).effect('pulsate', {
						times : 2
					}, 600);
				});
			}
			
			var el_class = $(element).attr('data-element-type-class');
			var initFunctionName = el_class.replace('Element_', '') + '_init';
			if(typeof(window[initFunctionName]) == 'function') {
				window[initFunctionName]();
			}

			// now init any children
			$(".element." + el_class).find('.active_child_elements').find('.element').each(function() {
				var initFunctionName = $(this).attr('data-element-type-class').replace('Element_', '') + '_init';
{'fraction_non_alphanumeric': 0.19438823688115472, 'fraction_numerical': 0.0029677593416970187, 'mean_word_length': 3.798705501618123, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '473440', 'n_tokens_mistral': 2794, 'n_tokens_neox': 2315, 'n_words': 398}