User:Writ Keeper/Scripts/afcDialog.js

$(document).ready(function{	afcDialogButtonText = "Make a selection";	if($("#afcSubmissionButton").length > 0)	{		$("#afcSubmissionButton").first.append(' Wait! Have you included citations to independent, reliable sources in your article? A. No, I forgot. I\'ll submit my page later. B. No. What are citations? How do I add them? C. No. There aren\'t any; I\'m writing about a subject that is new and/or not well known. D. No. I looked, but I am a new editor and need some help to find them. E. No, because this is a disambiguation page, template, or redirect, not an article. F. Yes, I have included citations to reliable sources in my article. ');

$("#afcOptionA").click(function{$('div[aria-labelledby="ui-dialog-title-afcDialog"] .ui-button-text').first.text("Never mind");afcDialogButtonText ="Never mind";}); $("#afcOptionB").click(function{$('div[aria-labelledby="ui-dialog-title-afcDialog"] .ui-button-text').first.text("Get help");afcDialogButtonText ="Get help";}); $("#afcOptionC").click(function{$('div[aria-labelledby="ui-dialog-title-afcDialog"] .ui-button-text').first.text("Get help");afcDialogButtonText ="Get help";}); $("#afcOptionD").click(function{$('div[aria-labelledby="ui-dialog-title-afcDialog"] .ui-button-text').first.text("Get help");afcDialogButtonText ="Get help";}); $("#afcOptionE").click(function{$('div[aria-labelledby="ui-dialog-title-afcDialog"] .ui-button-text').first.text("Submit");afcDialogButtonText ="Submit";}); $("#afcOptionF").click(function{$('div[aria-labelledby="ui-dialog-title-afcDialog"] .ui-button-text').first.text("Submit");afcDialogButtonText ="Submit";});

$("#afcSubmissionButton, #afcSubmissionButton > a").click(function{			$( "#afcDialog" ).dialog( { buttons: [ { text: afcDialogButtonText, click: function { var checkedInput = $('input[name=afcOptions]:checked'); var apiPath = mw.config.get('wgScriptPath') + "/api.php"; if(checkedInput.length > 0) {							switch(checkedInput.attr("id")) {								case "afcOptionB": var catData={action:"query", prop:"categories", clcategories: "Category:Articles not submitted at AfC", pageids: mw.config.get( 'wgArticleId' ), format: "json"}; $.post(apiPath, catData, function(response)									{										if(typeof response.query.pages[wgArticleId].categories == "undefined")										{											var data = {action: "edit", title: mw.config.get( 'wgPageName' ), summary: "Article not submitted, automatically adding category", minor: "true", appendtext: "\n\nCategory:Articles not submitted at AfC", token: mw.user.tokens.get( 'csrfToken' )};											$.post(apiPath, data, function{window.open(mw.util.getUrl("WP:Referencing for beginners"), "_self");});										}										else										{											window.open(mw.util.getUrl("WP:Referencing for beginners"), "_self");										}									}); break; case "afcOptionC": var catData={action:"query", prop:"categories", clcategories: "Category:Articles not submitted at AfC", pageids: mw.config.get( 'wgArticleId' ), format: "json"}; $.post(apiPath, catData, function(response)									{										if(typeof response.query.pages[wgArticleId].categories == "undefined")										{											var data = {action: "edit", title: mw.config.get( 'wgPageName' ), summary: "\nArticle not submitted, automatically adding category", minor: "true", appendtext: "\n\nCategory:Articles not submitted at AfC", token: mw.user.tokens.get( 'csrfToken' )};											$.post(apiPath, data, function{window.open(mw.util.getUrl("WP:42"), "_self");});										}										else										{											window.open(mw.util.getUrl("WP:42"), "_self");										}									}); break; case "afcOptionD": var catData={action:"query", prop:"categories", clcategories: "Category:Articles not submitted at AfC", pageids: mw.config.get( 'wgArticleId' ), format: "json"}; $.post(apiPath, catData, function(response)									{										if(typeof response.query.pages[wgArticleId].categories == "undefined")										{											var data = {action: "edit", title: mw.config.get( 'wgPageName' ), summary: "\nArticle not submitted, automatically adding category", minor: "true", appendtext: "\n\nCategory:Articles not submitted at AfC", token: mw.user.tokens.get( 'csrfToken' )};											$.post(apiPath, data, function{window.open(mw.util.getUrl("WP:Teahouse/Questions"), "_self");});										}										else										{											window.open(mw.util.getUrl("WP:Teahouse/Questions"), "_self");										}									}); break; case "afcOptionE": case "afcOptionF": window.open(mw.config.get("wgScript") + "?title="+ mw.util.wikiUrlencode( mw.config.get( 'wgPageName' ) ) +"&action=edit&section=new&preload=Template:AFC_submission/Subst&editintro=Template:AFC_submission/Subst/Editintro", "_self"); break; case "afcOptionA": default: alert("Your article has not been submitted."); $( this ).dialog( "close" ); break; }						}						return false; } },					{ text: "Cancel", click: function { $( this ).dialog( "close" ); return false; } }				], 				minWidth:500 }			);			return false;		}); } });