Utente:Alex brollo/formMake.js

Da Wikisource.

Nota: dopo aver pubblicato, potrebbe essere necessario pulire la cache del proprio browser per vedere i cambiamenti.

  • Firefox / Safari: tieni premuto il tasto delle maiuscole Shift e fai clic su Ricarica, oppure premi Ctrl-F5 o Ctrl-R (⌘-R su Mac)
  • Google Chrome: premi Ctrl-Shift-R (⌘-Shift-R su un Mac)
  • Internet Explorer / Edge: tieni premuto il tasto Ctrl e fai clic su Aggiorna, oppure premi Ctrl-F5
  • Opera: premi Ctrl-F5.
function formMake(template) {
	// metto wpTextbox1 in readonly
	$("#wpTextbox1").attr("readonly", "").attr("title", "Il testo non è editabile direttamente; usare il form a destra");
	$(".wikiEditor-ui-left").css("display", "inline").css("width", "50%");
	$(".wikiEditor-ui-right").css("display", "inline").css("width", "50%").css("height", $(".wikiEditor-ui-left").css("height"));
	t = parseTemplate(template, leggiBox());
	button1 = $('<input type="button" value="Salva la pagina" onclick="rewTempl(&quot;' + template + '&quot;);$(&quot;#wpSave&quot;).click();">');
	button2 = $('<input type="button" value="Salva nel box testo" onclick="rewTempl(&quot;' + template + '&quot;);">');
	$(".wikiEditor-ui-right").append(button1);
	$(".wikiEditor-ui-right").append(button2);
	$(".wikiEditor-ui-right").append($("<br />"));


	// crea una serie di campi input
	$(".wikiEditor-ui-right").append($("<table></table>"));
	for (i = 1; i < t[1].length; i += 1) {
		if (t[1][i] == "description") {
			input = $('<textarea rows="6" cols="50" ></textarea>').attr("name", t[1][i]).val(t[0][t[1][i]]);
		} else {
			input = $("<input />").attr("name", t[1][i]).attr("type", "text").attr("value", t[0][t[1][i]]);
			size = t[0][t[1][i]].length + 10;
			if (size > 40) size = 40;
			input.attr("size", size);
		}

		td1 = $("<td valign='top'></td>").html(t[1][i]);
		td2 = $("<td valign='top'></td>").append(input);
		tr = $("<tr></tr>").append(td1).append(td2);
		$(".wikiEditor-ui-right table").append(tr);
	}
}

function rewTempl(template) {
	var templ = "{" + "{" + template + "\n";
	$(".wikiEditor-ui-right input[type='text'], .wikiEditor-ui-right textarea").each(function () {
		templ += "| " + $(this).attr("name") + " = " + $(this).val() + "\n";
	});
	templ += "}}";
	var oldTemplate = find_stringa(leggiBox(), "{" + "{" + template, "}}", 1, "{{");
	scriviBox(leggiBox().replace(oldTemplate, templ));
}