User:DanCherek/sandbox.js

// /** * Attribution: This script is a derivative of MediaWiki:Request-page-protection-form.js, * authored by User:Enterprisey and User:SD0001. */

$.when($.ready, mw.loader.using(['mediawiki.api', 'mediawiki.widgets', 'mediawiki.util'])).then(function(config) {   //if ((mw.config.get("wgPageName") !== "Wikipedia:WikiProject_Resource_Exchange/Resource_Request/Form")) {    //    return;    //}    var api = new mw.Api;    var previewApi = new mw.Api;

var requestsPageTitle = 'User:DanCherek/sandbox'; var template = `== $heading == $request`;

var headingInput = new OO.ui.TextInputWidget({       'required': true,    }); var requestInput = new OO.ui.MultilineTextInputWidget({       'value': `



For Example article

Thanks, ~`, 'required': 'true', 'autosize': 'true', 'classes': [ 'mw-editfont-monospace' ] });	var requestPreview = new OO.ui.LabelWidget;   var submitButton = new OO.ui.ButtonWidget({ 'label': 'Submit request', 'flags': ['progressive', 'primary'], 'accesskey': 's'   });    var fieldset = new OO.ui.FieldsetLayout;    fieldset.addItems([ new OO.ui.FieldLayout(headingInput, {           'label': 'Section heading (briefly describe your request):',            align: 'top'        }), new OO.ui.FieldLayout(requestInput, {           'label': 'Request:',            align: 'top'        }), new OO.ui.FieldLayout(requestPreview, {           'label': 'Preview:',            align: 'top'        }), new OO.ui.FieldLayout(submitButton) ]);   $("#mw-content-text").empty.append(fieldset.$element);

function makeRequestText { return template.replace(/\$heading/g, headingInput.getValue).replace(/\$request/g, requestInput.getValue); }   function updateForm { var hasHeading = headingInput.getValue.trim.length > 0; var hasRequest = requestInput.getValue.trim.length > 0; var formEnabled = hasHeading && hasRequest; submitButton.setDisabled(!formEnabled); if (!hasHeading && !hasRequest) submitButton.setLabel('Add heading and enter request'); else if (!hasHeading) submitButton.setLabel('Add heading'); else if (!hasRequest) submitButton.setLabel('Enter request'); else submitButton.setLabel('Submit request'); if (formEnabled) { previewApi.abort; previewApi.parse(makeRequestText, { 				pst: true, 				title: requestsPageTitle 			}).then(function(text) {				text = text.replace(/<script/g, '&lt;script');				requestPreview.$element.html(text);			}); }   }    headingInput.on('change', updateForm); requestInput.on('change', updateForm);

submitButton.on('click', function {       updateForm;        if (submitButton.isDisabled) {            return;        }

submitButton.setDisabled(true); submitButton.setLabel('Submitting...'); api.edit(requestsPageTitle, function {           return {                appendtext: '\n\n' + makeRequestText,                summary: '/* ' + headingInput.getValue + ' */ new section'            };        }).then(function {            window.location.href = mw.util.getUrl(requestsPageTitle);        }); }); }); //