small fixes

This commit is contained in:
teldra 2022-06-25 05:36:48 +02:00
parent c2e3293dfb
commit 10cbba1935
2 changed files with 28 additions and 7 deletions

View File

@ -28,6 +28,7 @@
<div class="w100 {{ if .group }} visibleIf margin_left_1rem" data-visibleif-rule="{{ .group }}group == 'true' {{ end }}" style="flex-direction: column;"> <div class="w100 {{ if .group }} visibleIf margin_left_1rem" data-visibleif-rule="{{ .group }}group == 'true' {{ end }}" style="flex-direction: column;">
<label class="w100 {{ if $pageform.names }}sr-only{{ end }}" for="{{ .title }}">{{- $name -}}{{- if .required -}}{{- " *" -}}{{- end -}}</label> <label class="w100 {{ if $pageform.names }}sr-only{{ end }}" for="{{ .title }}">{{- $name -}}{{- if .required -}}{{- " *" -}}{{- end -}}</label>
<div style="display: flex; flex-wrap: wrap;"> <div style="display: flex; flex-wrap: wrap;">
<button style="background: #8e3333;" class="button" type="button" value="Clear" onclick="clearThis({{ .title }});" />Clear</button>
{{ $button_target := .title }} {{ $button_target := .title }}
{{ range split .buttons ";"}} {{ range split .buttons ";"}}
{{ $b := split . ","}} {{ $b := split . ","}}
@ -38,6 +39,9 @@
{{ end }} {{ end }}
</div> </div>
<textarea class="w100 textarea" name="{{ .title }}" id="{{ .title }}" rows="10" {{ if .placeholder }}placeholder="{{ .placeholder }}"{{ end }}></textarea> <textarea class="w100 textarea" name="{{ .title }}" id="{{ .title }}" rows="10" {{ if .placeholder }}placeholder="{{ .placeholder }}"{{ end }}></textarea>
{{ if eq .title "content" }}
<div id="added-files" style="display: flex; flex-direction: column;"></div>
{{ end }}
</div> </div>
{{ else if eq .input_type "radio" }} {{ else if eq .input_type "radio" }}
<div class="radio {{- if .group }} visibleIf margin_left_1rem" data-visibleif-rule="{{ .group }}group == 'true'{{ end }}"> <div class="radio {{- if .group }} visibleIf margin_left_1rem" data-visibleif-rule="{{ .group }}group == 'true'{{ end }}">

View File

@ -52,6 +52,12 @@ function Clear(name) {
ele[i].checked = false; ele[i].checked = false;
} }
function rm_file(fname) {
var rmid = document.getElementById(fname);
rmid.remove(); // Removes the div with the 'div-02' id
zip.remove(fname);
}
function button(str) { function button(str) {
var arr = str.split(";"); var arr = str.split(";");
let x = arr[1]; let x = arr[1];
@ -76,27 +82,30 @@ function button(str) {
var input = document.createElement('input'); var input = document.createElement('input');
var fout = document.getElementById('added-files');
input.type = 'file'; input.type = 'file';
input.multiple = 'multiple'; input.multiple = 'multiple';
input.id = 'inpic'; input.id = 'inpic';
input.click(); input.click();
input.onchange = e => { input.onchange = e => {
var files = e.target.files; var files = e.target.files;
for (var i = 0; i < files.length; i++) { for (var i = 0; i < files.length; i++) {
var p = "Desc for " + files[i].name; var name = files[i].name.trim();
var p = "Desc for " + name;
var desc = prompt(p, "Wikipedia logo"); var desc = prompt(p, "Wikipedia logo");
if (desc) { if (desc) {
zip.file(files[i].name, files[i]); zip.file(name, files[i]);
var pic = files[i].name; var pic = name;
var out = "![" + desc + "](" + pic + ") \n\n"; var out = "![" + desc + "](" + pic + ") \n\n";
typeInTextarea(out); typeInTextarea(out);
var end = id.value.length; var end = id.value.length;
id.setSelectionRange(end, end); id.setSelectionRange(end, end);
id.focus({preventScroll: true}); id.focus({preventScroll: true});
fout.innerHTML += "<div id=\"" + name + "\" style=\"display: flex; flex-direction: row;\">" + pic + "<button type=\"button\" onclick=\"rm_file('" + name + "')\" value=\"" + name + "\" id=\"" + name + "\">remove</button></div>";
} }
} }
} }
return;
} }
if (x == "bold") { if (x == "bold") {
let bold = prompt("Bold", ""); let bold = prompt("Bold", "");
@ -115,7 +124,7 @@ function button(str) {
if (x == "more") { if (x == "more") {
var out = "\n\n<!--more-->\n\n"; var out = "\n\n<!--more-->\n\n";
} }
if (out != null) { if (out != null && x != "pic") {
typeInTextarea(out); typeInTextarea(out);
var end = id.value.length; var end = id.value.length;
id.setSelectionRange(end, end); id.setSelectionRange(end, end);
@ -145,6 +154,7 @@ function showInput(e) {
var d = new Date(); var d = new Date();
var datestring = d.getFullYear() + "-" + ("0"+(d.getMonth()+1)).slice(-2) + "-" + ("0" + d.getDate()).slice(-2) + "T" + ("0" + d.getHours()).slice(-2) + ":" + ("0" + d.getMinutes()).slice(-2) + ":00+02:00"; var datestring = d.getFullYear() + "-" + ("0"+(d.getMonth()+1)).slice(-2) + "-" + ("0" + d.getDate()).slice(-2) + "T" + ("0" + d.getHours()).slice(-2) + ":" + ("0" + d.getMinutes()).slice(-2) + ":00+02:00";
var datestring_shorter = d.getFullYear() + "-" + ("0"+(d.getMonth()+1)).slice(-2) + "-" + ("0" + d.getDate()).slice(-2);
var form = document.querySelector('form[id="generatorform"]'); var form = document.querySelector('form[id="generatorform"]');
var title = form.elements['title'].value; var title = form.elements['title'].value;
@ -326,13 +336,20 @@ function showInput(e) {
// Add an top-level, arbitrary text file with contents // Add an top-level, arbitrary text file with contents
zip.file("index.de.md", output); zip.file("index.de.md", output);
var pattern = /[^a-z\d\-_\s]+$/i;
var t = title.replace(/^["'](.+(?=["']$))["']$/, '$1').toLowerCase();
var t = t.trim();
var t = t.replaceAll(/\s+/g, '-');
var t = t.replace(/[^\w.-]+/g, "");
var archive_name = datestring_shorter + "-" + t + ".zip";
// Generate the zip file asynchronously // Generate the zip file asynchronously
zip.generateAsync({type:"blob"}) zip.generateAsync({type:"blob"})
.then(function(cont) { .then(function(cont) {
// Force down of the Zip file // Force down of the Zip file
saveAs(cont, "archive.zip"); saveAs(cont, archive_name);
}); });
} }
} }