<commit_before>// Copyright (c) 2003 - 2008 <NAME>, L<EMAIL>. All rights reserved.
// Copying and reuse is strictly prohibited.

EditForm = Base.extend({
	initialize: function(id, target, parent) {
		this.id = id;
		this.target = target;
		this.targetId = target.getId();
		this.parent = parent;
		// Mark as empty until it gets set, so empty editforms can be skipped
		// in close()
		this.empty = true;
		if (EditForm.mode == 'inline') {
			this.container = target.injectAfter('div', { id: 'edit-container-' + id });
			// Pass on style and class settings
			if (parent) {
				this.container.setStyle(parent.container.getStyle());
				this.container.addClass(parent.container.getClass());
			}
		}
	},

	setup: function(obj) {
		// On Safari, there is a very odd bug that very rarely mixes all the
		// buttons on one page, as if they were all thrown into one container,
		// and redistributed by picking blindy. The workaround is to not produce
		// buttons in edit forms, but use <a> tags, and replace them with buttons
		// here, if buttons.convert is set to true:
		if (EditSettings.buttons.convert) {
			$$('a.edit-button', obj).each(function(el, index) {
				var id = el.getId();
				// el.removeClass('button'); // For getClass bellow
				el.replaceWith('input', {
					type: 'button',
					id: id, name: id,
					value: el.getText(),
					className: el.getClass(),
					onclick: el.getProperty('onclick')
				});
			});
		}
		var that = this;
		// Remember focused elements and their last selection and scroll position,
		// so they can be restored after previewing pages.
		// Do not store direct references since the elements are replaced when
		// saving before preview, therefore use ids instead.
		var fields = $$('input[type=text],input[type=password],textarea', obj);
		function store() {
			if (that.focus && this.getId() == that.focus.id) {
				that.focus.selection = this.getSelection();
				that.focus.offset = this.getScrollOffset();
			}
		}
		fields.addEvents({
			focus: function() {
				that.focus = { id: this.getId() };
			},
			// Since we cannot store getSelection in blur on IE (it relies on
			// focus() which cannot be called in blur), store status in all of these
			// occasions:
			keyup: store,
			mouseup: store,
			change: store
		});
		// We're asking inputs and textareas to be a certain size, but they grow
		// bigger due to their border and padding settings that differ from browser
		// to browser.
		// This can be fixed by calculating these widths now and subtracting them
		// from  their resulting size. Since we're using getWidth(), this needs
		// to happen after this.show(true). Also, it needs to happen before
		// TabPane.setup(), since that would hide tabs again, for which the fix
		// won't work...
		fields.each(function(field) {
			function width(val) {
				return field.getStyle('border-' + val + '-width').toInt()
						+ field.getStyle('padding-' + val).toInt();
			}
			var width = field.getWidth() - 2 * (width('left') + width('right')) + 'px';
			field.setStyles({
				width: width,
				// Prevent textareas from resizing horizontally. 
				// Setting maxWidth instead of max-width breaks Firefox. Why?
				'max-width': width
			});
		});
		// Initialize word counts
		$$('textarea.edit-text-count', obj).each(function(text) {
			this.handle('text_count', text);
		}, this);
	},

	set: function(values) {
		if (values.applied)
			this.applied = true;
		this.html = values.html;
		// On Safari, remove buttons before setting of new html, to prevent
		// the odd bug described bellow from happening.
		if (EditSettings.buttons.convert && Browser.WEBKIT)
			$$('input[type=button]', this.container).remove();
		this.container.setHtml(this.html);
		this.form = $('form', this.container);
		if (this.form) {
			this.show(true);
			this.setup(this.form);
			TabPane.setup();
			this.empty = false;
			this.url = this.form.getAction();
			var tab = $('div.tab-pane', this.form);
			this.tab = tab && tab.tabPane;
			// Set a reference to the editForm so TabPane can call autoSize
			// if needed (on Lineto)
			if (this.tab)
				this.tab.editForm = this;

		}
	},

	reportError: function(error) {
		this.setSelectedTab(error.tab);
		var field = $('#' + error.name, this.form);
		if (field && field.focus) {
			field.setValue(error.value);
			field.setCaret(0);
		}
		$('#edit-label-' + error.name + ' > .edit-error', this.form)
			.setHtml('<div>' + error.message + '</div>')
			.removeClass('hidden')
			.addEvent('click', function() {
				this.addClass('hidden');
				if (field && field.focus)
					field.setCaret(0);
			});
	},<commit_msg>Improved focusing of error fields.<commit_after>// Copyright (c) 2003 - 2008 <NAME>, Lineto.com. All rights reserved.
// Copying and reuse is strictly prohibited.

EditForm = Base.extend({
	initialize: function(id, target, parent) {
		this.id = id;
		this.target = target;
		this.targetId = target.getId();
		this.parent = parent;
		// Mark as empty until it gets set, so empty editforms can be skipped
		// in close()
		this.empty = true;
		if (EditForm.mode == 'inline') {
			this.container = target.injectAfter('div', { id: 'edit-container-' + id });
			// Pass on style and class settings
			if (parent) {
				this.container.setStyle(parent.container.getStyle());
				this.container.addClass(parent.container.getClass());
			}
		}
	},

	setup: function(obj) {
		// On Safari, there is a very odd bug that very rarely mixes all the
		// buttons on one page, as if they were all thrown into one container,
		// and redistributed by picking blindy. The workaround is to not produce
		// buttons in edit forms, but use <a> tags, and replace them with buttons
		// here, if buttons.convert is set to true:
		if (EditSettings.buttons.convert) {
			$$('a.edit-button', obj).each(function(el, index) {
				var id = el.getId();
				// el.removeClass('button'); // For getClass bellow
				el.replaceWith('input', {
					type: 'button',
					id: id, name: id,
					value: el.getText(),
					className: el.getClass(),
					onclick: el.getProperty('onclick')
				});
			});
		}
		var that = this;
		// Remember focused elements and their last selection and scroll position,
		// so they can be restored after previewing pages.
		// Do not store direct references since the elements are replaced when
		// saving before preview, therefore use ids instead.
		var fields = $$('input[type=text],input[type=password],textarea', obj);
		function store() {
			if (that.focus && this.getId() == that.focus.id) {
				that.focus.selection = this.getSelection();
				that.focus.offset = this.getScrollOffset();
			}
		}
		fields.addEvents({
			focus: function() {
				that.focus = { id: this.getId() };
			},
			// Since we cannot store getSelection in blur on IE (it relies on
			// focus() which cannot be called in blur), store status in all of these
			// occasions:
			keyup: store,
			mouseup: store,
			change: store
		});
		// We're asking inputs and textareas to be a certain size, but they grow
		// bigger due to their border and padding settings that differ from browser
		// to browser.
		// This can be fixed by calculating these widths now and subtracting them
		// from  their resulting size. Since we're using getWidth(), this needs
		// to happen after this.show(true). Also, it needs to happen before
		// TabPane.setup(), since that would hide tabs again, for which the fix
		// won't work...
		fields.each(function(field) {
			function width(val) {
				return field.getStyle('border-' + val + '-width').toInt()
						+ field.getStyle('padding-' + val).toInt();
			}
			var width = field.getWidth() - 2 * (width('left') + width('right')) + 'px';
			field.setStyles({
				width: width,
				// Prevent textareas from resizing horizontally. 
				// Setting maxWidth instead of max-width breaks Firefox. Why?
				'max-width': width
			});
		});
		// Initialize word counts
		$$('textarea.edit-text-count', obj).each(function(text) {
			this.handle('text_count', text);
		}, this);
	},

	set: function(values) {
		if (values.applied)
			this.applied = true;
		this.html = values.html;
		// On Safari, remove buttons before setting of new html, to prevent
		// the odd bug described bellow from happening.
		if (EditSettings.buttons.convert && Browser.WEBKIT)
			$$('input[type=button]', this.container).remove();
		this.container.setHtml(this.html);
		this.form = $('form', this.container);
		if (this.form) {
			this.show(true);
			this.setup(this.form);
			TabPane.setup();
			this.empty = false;
			this.url = this.form.getAction();
			var tab = $('div.tab-pane', this.form);
			this.tab = tab && tab.tabPane;
			// Set a reference to the editForm so TabPane can call autoSize
			// if needed (on Lineto)
			if (this.tab)
				this.tab.editForm = this;

		}
	},

	reportError: function(error) {
		this.setSelectedTab(error.tab);
		var field = $('#' + error.name, this.form);
		if (field && field.setCaret) {
			var value = error.value || '';
			field.setValue(value);
			field.setCaret(value.length);
		}
		$('#edit-label-' + error.name + ' > .edit-error', this.form)
			.setHtml('<div>' + error.message + '</div>')
			.removeClass('hidden')
			.addEvent('click', function() {
				this.addClass('hidden');
				if (field && field.focus)
					field.focus();
			});
	},
{'fraction_non_alphanumeric': 0.1458175930922828, 'fraction_numerical': 0.0021586616297895305, 'mean_word_length': 3.1018149623727314, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 14, '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': '1034720', 'n_tokens_mistral': 3335, 'n_tokens_neox': 2838, 'n_words': 915}