Account Creation Improvement Project/Testing content/Form to edit page (1)

The plan

edit

The plan is to have a form that's created by inserting a string inside an empty div or replacing some content for users with javascript disabled. This form is then submited to the users userpage as a preview edit. If you have any questions, please send me an email at albin.jacobsson@gmail.com.

Code

edit

Javascript (to common.js)

edit
jQuery(function(){
	var inpt = ' <input/>',
		preComment = '<!-- BELOW IS A QUESTIONNAIRE ABOUT YOU. YOU CAN FILL IT OUT COMPLETELY OR IN PARTS AND THEN COME BACK TO IT. AFTER YOU ARE DONE, SCROLL DOWN AND CLICK "SAVE PAGE".--\>{'+'{New user bar}}\n\n',
		postComment = '\n\n<!-- NOW, CLICK THE "SAVE PAGE" BUTTON. CONGRATULATIONS, YOU\'VE JUST MADE YOUR FIRST EDIT TO WIKIPEDIA. --\>',
		submitText = 'Send this to your userpage!',
		/*
		 * \n for linebreaks
		 * inpt for input-fields
		 * Escape all ' by typing \'
		 */
		preFilltemplate = [
			'This is me:',inpt,
			'\nI am interested in these topics:',inpt,
			'\nI know a lot about:',inpt,
			'\nI work as/study to be a...:',inpt,
			'\nI know how Wikipedia works / I don\'t know how Wikipedia works.',inpt,
			'\nI want to:',inpt];
		function toForm() {
			for (var x=0,ret='',pF=preFilltemplate.length;x<pF;x++){
				ret += preFilltemplate[x].replace('\n','<br/>');
			}
			return '<form id="magic333" action="'+wgServer+wgScript+'?title='+wgFormattedNamespaces[2]+':'+wgUserName+'&action=submit" method="post"><div>' + ret + '</div><textarea name="wpTextbox1" id="wpTextbox1" style="display:none;visibility:hidden;"></textarea><br/><input type="submit" value="'+submitText+'"/></form>';
		}
	jQuery('#signupuserpagefillmagic').html(function(){return toForm()})
	jQuery('#magic333').live('submit',function(e){
		e.preventDefault()
		jQuery('<div id="thishiddenelement"/>').css({display:'none'}).appendTo('#signupuserpagefillmagic')
		jQuery('#wpTextbox1').text(function(){
			jQuery('#signupuserpagefillmagic div').clone().appendTo('#thishiddenelement')
			jQuery('#thishiddenelement input').each(function(i,e){
				$(this).replaceWith($(this).val())
			})
			var ret = jQuery('#thishiddenelement div').html(),
				ret = preComment+ret+postComment,
				ret = ret.replace(/\<br\>/gi,'\n\n');
			return ret;
		})
		document.getElementById('magic333').submit();
	})
})

HTML (to wikicode)

edit
<div id="signupuserpagefillmagic"></div>