User:קיפודנחש/searchPersistence.js

Source: Wikipedia, the free encyclopedia.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
// teach s&r form in advance toolbar to remember its content
$(function() {
		var controls = '#wikieditor-toolbar-replace-search, #wikieditor-toolbar-replace-replace, #wikieditor-toolbar-replace-case, #wikieditor-toolbar-replace-regex';
		$('body').on('change', controls, function() {
			$this = $(this);
			$.cookie($this.attr('id'), 
					 $(this).attr('type') == 'checkbox' ? ($this.prop('checked') ? 'checked' : '') : $(this).val(), 
					 {path: '/', expires: 30})
			});
		$('body').on('dialogopen', '#wikieditor-toolbar-replace-dialog', function() {
			$.each(controls.split(/,\s*/), function(ind, name) {
				control = $(name); val = $.cookie(name.replace('#',''));
				if (control.attr('type') == 'checkbox')
					control.prop('checked', val);
				else
					control.val(val);
			});
		});
});