User:Abelmoschus Esculentus/SATG.js

//Written by Abelmoschus Esculentus //Date: 12 January 2019 // function screen2(number) { var source = ["placeholder"], ind = ["placeholder"], ind_just = ["placeholder"], rel = ["placeholder"], rel_just = ["placeholder"], sig = ["placeholder"], sig_just = ["placeholder"]; $('.SATG-source').each(function {		source.push(this.value);  }); $('.SATG-selecti').each(function {		ind.push(this.value);  }); $('.SATG-justi').each(function {		ind_just.push(this.value);  }); $('.SATG-selectr').each(function {		rel.push(this.value);  }); $('.SATG-justr').each(function {		rel_just.push(this.value);  }); $('.SATG-selects').each(function {		sig.push(this.value);  }); $('.SATG-justs').each(function {		sig_just.push(this.value);  }); var output = ""; $("#SATG-interface-content").css({     "min-height": "7em",      "width" : "875px",      "height" : "400px",      "overflow-y": "hidden"    }); $("#SATG-interface-content").empty; $("#SATG-interface-content").text('Generating...'); $('.SATG-tip').remove; $("#SATG-interface-content").empty; $("#SATG-interface-content").append(		$(' ').attr('id','SATG-copy').text('Copy'),		$(' ').attr('id','SATG-copied').text(''),		$(' ').css({'resize':'none'}).attr({'id':'SATG-output','readonly':'true','rows':'20','cols':'35'}).text(output)	); $('#SATG-copy').click(function {		var copy = document.getElementById("SATG-output");		copy.select;		document.execCommand("copy");		$('#SATG-copied').text(' Copied to your clipboard!');	}); } function screen1(number) { if ($("#SATG-interface-content").text == "Loading form...") { $("#SATG-interface-content").empty; }   $("#SATG-interface-footer").append(    	$(' ').attr('id', 'SATG-back').css('margin-left','1em').text('Back')	); $("#SATG-interface-footer").prepend(		$(' ').attr('class','SATG-tip').text('**Only available for options "Yes", "No", "Partially" and "Unknown"'),		$(' ').attr('class','SATG-tip')	); $('#SATG-back').click(function {        $('#SATG-back').remove;        $("#SATG-interface-content").css({ "min-height": "7em", "width" : "875px", "height" : "400px", "overflow-y": "scroll" });       screen0;    }); /*var arr = [ {val : 1, text: 'Yes'}, {val : 2, text: 'No'}, {val : 3, text: 'Partially'}, {val : 4, text: 'Unknown'}, {val : 5, text: 'None'} ];*/   for (var i = 1; i <= number; i++) { if (i != 1) { $("#SATG-interface-content").append(' '); }   	$("#SATG-interface-content").append(    		$(' ').css('margin-bottom','0.5em').append( $(' ').text('Source '+i+': '), $(' ').attr({'type':'text','class':'SATG-source'}) ),         $(' ').css('margin-bottom','0.5em').append( $(' ').text('Independent? '), $(' ').attr('class','SATG-selecti') .append($(" ").attr('value','y').text('Yes')) .append($(" ").attr('value','n').text('No')) .append($(" ").attr('value','-').text('Partially')) .append($(" ").attr('value','?').text('Unknown')) .append($(" ").attr({'value':'','selected':'true'}).text('None')), $(' ').text(' **Justification: '), $(' ').attr({'type':'text','class':'SATG-justi'}) ),         $(' ').css('margin-bottom','0.5em').append( $(' ').text('Reliable? '), $(' ').attr('class','SATG-selectr') .append($(" ").attr('value','y').text('Yes')) .append($(" ").attr('value','n').text('No')) .append($(" ").attr('value','-').text('Partially')) .append($(" ").attr('value','?').text('Unknown')) .append($(" ").attr({'value':'','selected':'true'}).text('None')), $(' ').text(' **Justification: '), $(' ').attr({'type':'text','class':'SATG-justr'}) ),        $(' ').css('margin-bottom','0.5em').append( $(' ').attr('id','SATG-labels-'+i).text('Significant coverage? '), $(' ').attr('class','SATG-selects') .append($(" ").attr('value','y').text('Yes')) .append($(" ").attr('value','n').text('No')) .append($(" ").attr('value','-').text('Partially')) .append($(" ").attr('value','?').text('Unknown')) .append($(" ").attr({'value':'','selected':'true'}).text('None')), $(' ').text(' **Justification: '), $(' ').attr({'type':'text','class':'SATG-justs'}) )       );    }    $("#SATG-interface-content").append(    	$(' ').attr('id','SATG-generate').text('Generate!')    ); $('#SATG-generate').click(function {   	screen2(number);    }); } function satg_init { mw.util.addPortletLink('p-tb', 'javascript:void(0)', 'SA Table Generator', 'aca-satg', null, null); $('#aca-satg').on('click', function {   $('body').prepend(' '+ ' '+       ' '+ ' '+       ' '+        ' '+        ' '+      ' '+    ' ');    $("#SATG-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)" });   $("#SATG-interface").css({ "background-color": "#e8f0ff", "margin": "15% auto", "padding": "2px 20px", "border": "1px solid #888", "width": "80%", "max-width": "60em", "font-size": "90%" });   $("#SATG-interface-content").css({ "min-height": "7em", "width" : "875px", "height" : "400px", "overflow-y": "scroll" });   $("#SATG-interface-footor").css("min-height", "3em");    screen0;  }); } var screen0 = function { $("#SATG-interface-header, #SATG-interface-content, #SATG-interface-footer").empty; $("#SATG-interface-header").text("Source Assess Table Generator"); $("#SATG-interface-content").append(   $(' ').css('margin-bottom','0.5em').append( $(' ').attr({'for':'SATG-userinput-label', 'id':'SATG-userinput-label'}).text('How many sources do you want to assess? '), $(' ').attr({'type':'number', 'name':'SATG-userinput','id':'SATG-userinput','min':'1','max':'100','value':'1'}) //set limits ),   $(' ').css('margin-bottom','0.5em').append( $(' ').attr({'name':'SATG-userinput-button', 'id':'SATG-userinput-button'}).text('Load') ) );  $("#SATG-interface-footer").append(    $(' ').attr('id', 'SATG-cancel').text('Close')  ); $('#SATG-cancel').click(function {   $('#SATG-modal').remove;  }); $('#SATG-userinput-button').click(function { 	var temp = $('#SATG-userinput').val;  	if (temp > 100 || temp < 1) {  		alert('Invalid value');  	}  	else {  		$('#SATG-interface-content').empty;  		$('#SATG-interface-content').text('Loading form...');  		screen1(temp);  	}  }); }; mw.loader.using(['mediawiki.util', 'mediawiki.api', 'mediawiki.Title', 'mediawiki.RegExp'], function { satg_init; }); //