Jump to content

User:DannyS712 test/itn.js

From 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.
//<nowiki>
function screen2(number) {
	var article = ["placeholder"], image = ["placeholder"], blurb = ["placeholder"], rd = ["placeholder"], ong = ["placeholder"], src = ["placeholder"], up = ["placeholder"], creator = ["placeholder"], updater = ["placeholder"], ITNR = ["placeholder"];
	$('.ITN-article').each(function () {article.push(this.value);});
	$('.ITN-image').each(function () {image.push(this.value);});
	$('.ITN-label-rd').each(function () {rd.push(this.value);});
	$('.ITN-label-ong').each(function () {ong.push(this.value);});
	$('.ITN-src').each(function () {src.push(this.value);});
	$('.ITN-label-up').each(function () {up.push(this.value);});
	$('.ITN-creator').each(function () {creator.push(this.value);});
	$('.ITN-updater').each(function () {updater.push(this.value);});
	$('.ITN-label-ITNR').each(function () {ITNR.push(this.value);});

	var output = "";
	for (var i = 1; i <= number; i++) {
	    output = "==== " + article[i] + " ====\n";
	    output += "{{ITN candidate\n";
	    output += "| article		=	" + article[i] + "\n";
	    output += "| image			=	" + image[i] + "\n";
	    output += "| recent deaths  	=	" + rd[i] + "\n";
	    output += "| ongoing		=	" + ong[i] + "\n";
	    output += "| sources		=	" + src[i] + "\n";
	    output += "| updated		=	" + up[i] + "\n";
	    output += "| nominator		=	{{subst:REVISIONUSER}}\n";
	    output += "| creator		=	" + creator[i] + "\n";
	    output += "| updater		=	" + updater[i] + "\n";
	    output += "| ITNR			=	" + ITNR[i] + "\n";
	    output += "| sign			=	~~~~\n";
	    output += "}}\n";
	}
	$("#ITN-interface-content").css({
      "min-height": "7em",
      "width" : "875px",
      "height" : "400px",
      "overflow-y": "hidden"
    });
	$("#ITN-interface-content").empty();
	$("#ITN-interface-content").text('Generating...');
	$('.ITN-tip').remove();
	$("#ITN-interface-content").empty();
	$("#ITN-interface-content").append(
		$('<button>').attr('id','ITN-copy').text('Copy'),
		$('<label>').attr('id','ITN-copied').text(''),
		$('<textarea>').css({'resize':'none'}).attr({'id':'ITN-output','readonly':'true','rows':'20','cols':'35'}).text(output)
	);
	$("#ITN-interface-footer").append(
		$('<button>').attr('id', 'ITN-back').css('margin-left','1em').text('Back')
	);
	$('#ITN-copy').click(function() {
		var copy = document.getElementById("ITN-output");
		copy.select();
		document.execCommand("copy");
		$('#ITN-copied').text(' Copied to your clipboard!');
	});
	$('#ITN-back').click(function () {
        $('#ITN-back').remove();
        $("#ITN-interface-content").css({
    		"min-height": "7em",
		    "width" : "875px",
		    "height" : "400px",
		    "overflow-y": "scroll"
	    });
        screen1();
    });
}
function screen1() {
	var number = 1;
	$("#ITN-interface-header, #ITN-interface-content, #ITN-interface-footer").empty();
	$("#ITN-interface-header").text("Source Assess Table Generator");
	$("#ITN-interface-footer").append($('<button>').attr('id', 'ITN-cancel').text('Close'));
	$('#ITN-cancel').click(function() {$('#ITN-modal').remove();});
	$("#ITN-interface-footer").prepend(
		$('<small>').attr('class','ITN-tip').text('**Leave blank if you aren\'t sure"'),
		$('<br>').attr('class','ITN-tip')
	);
	$("#ITN-interface-content").append(
		$('<div>').css('margin-bottom','0.5em').append(
			$('<label>').text('Article: '),
			$('<input>').attr({'type':'text','class':'ITN-article'})
    	),
		$('<div>').css('margin-bottom','0.5em').append(
			$('<label>').text('Image: '),
			$('<input>').attr({'type':'text','class':'ITN-image'})
    	),
		$('<div>').css('margin-bottom','0.5em').append(
			$('<label>').text('Blurb: '),
			$('<input>').attr({'type':'text','class':'ITN-blurb'})
    	),
    	$('<div>').css('margin-bottom','0.5em').append(
	        $('<label>').text( 'Recent deaths?'),
	        $('<select>').attr('class','ITN-label-rd')
	         .append($("<option>").attr('value','yes').text('Yes'))
	         .append($("<option>").attr({'value':'no','selected':'true'}).text('No'))
    	),
    	$('<div>').css('margin-bottom','0.5em').append(
    		$('<label>').attr('id','ITN-label-ong').text( 'Ongoing?'),
        	$('<select>').attr('class','ITN-label-ong')
        	.append($("<option>").attr('value','yes').text('Yes'))
        	.append($("<option>").attr('value','rem').text('Remove'))
    		.append($("<option>").attr({'value':'no','selected':'true'}).text('No'))
    	),
		$('<div>').css('margin-bottom','0.5em').append(
			$('<label>').text('Sources: '),
			$('<input>').attr({'type':'text','class':'ITN-src'})
    	),
    	$('<div>').css('margin-bottom','0.5em').append(
	        $('<label>').text( 'Updated?'),
	        $('<select>').attr('class','ITN-label-up')
	         .append($("<option>").attr('value','yes').text('Yes'))
	         .append($("<option>").attr({'value':'no','selected':'true'}).text('No'))
    	),
		$('<div>').css('margin-bottom','0.5em').append(
			$('<label>').text('Creator: '),
			$('<input>').attr({'type':'text','class':'ITN-creator'})
    	),
		$('<div>').css('margin-bottom','0.5em').append(
			$('<label>').text('Updater: '),
			$('<input>').attr({'type':'text','class':'ITN-updater'})
    	),
    	$('<div>').css('margin-bottom','0.5em').append(
	        $('<label>').text( 'ITNR?'),
	        $('<select>').attr('class','ITN-label-ITNR')
	         .append($("<option>").attr('value','yes').text('Yes'))
	         .append($("<option>").attr({'value':'no','selected':'true'}).text('No'))
    	)
    );
    $("#ITN-interface-content").append($('<button>').attr('id','ITN-generate').text('Generate!'));
    $('#ITN-generate').click(function() {screen2(number);});
}
function ITN_init() {
  mw.util.addPortletLink('p-cactions', 'javascript:void(0)', 'ITN Generator', 'aca-ITN', 'Easily create an ITN nomination', null);
  $('#aca-ITN').on('click', function() {
    $('body').prepend('<div id="ITN-modal">'+
      '<div id="ITN-interface">'+
        '<h4 id="ITN-interface-header"></h4>'+
        '<hr>'+
        '<div id="ITN-interface-content"></div>'+
        '<hr>'+
        '<div id="ITN-interface-footer"></div>'+
      '</div>'+
    '</div>');
    $("#ITN-modal").css({
      "position": "fixed",
      "z-index": "1",
      "left": "0",
      "top": "0",
      "width": "100%",
      "height": "100%",
      "overflow": "hidden",
      "background-color": "rgba(0,0,0,0.4)"
    });
    $("#ITN-interface").css({
      "background-color": "#e8f0ff",
      "margin": "15% auto",
      "padding": "2px 20px",
      "border": "1px solid #888",
      "width": "80%",
      "max-width": "60em",
      "font-size": "90%"
    });
    $("#ITN-interface-content").css({
      "min-height": "7em",
      "width" : "875px",
      "height" : "400px",
      "overflow-y": "scroll"
    });
    $("#ITN-interface-footor").css("min-height", "3em");
    screen1();
  });
}
mw.loader.using(['mediawiki.util', 'mediawiki.api', 'mediawiki.Title', 'mediawiki.RegExp'], function() {
  ITN_init();
});
//</nowiki>