Mercurial > hgrepos > hgweb.cgi > s4
diff s4-main.js @ 837:a6462eea48be
Multiple files upload for tablets added and file renaming fixed
author | HIROSE Yuuji <yuuji@gentei.org> |
---|---|
date | Thu, 25 Jun 2020 15:50:16 +0900 |
parents | cd6f0badcff4 |
children | 9c4e16c173db |
line wrap: on
line diff
--- a/s4-main.js Tue Jun 23 12:58:31 2020 +0900 +++ b/s4-main.js Thu Jun 25 15:50:16 2020 +0900 @@ -72,8 +72,49 @@ u.checked = !u.checked; } } + function addFileInput() { + var inpfile = collectElementsByAttr("input", "name", "image"); + if (!inpfile) return; + var filled = true; + var i, ih; + for (i of inpfile) { + if (! i.value) filled=false; + } + if (filled) { + ih = i.parentNode.innerHTML; + if (ih) { + var inpf = ih.substring(ih.indexOf("<input")), + newi = "<br>"+inpf.substring(0, inpf.indexOf(">")+1); + i.insertAdjacentHTML("afterend", newi) + // alert(newi); + } + } + } + function initFileInput() { // Multiplies "input type=file" + var el, morefile = document.getElementById("morefile"); + if (morefile) { + for (el of collectElementsByAttr("input", "name", "image")) { + el.addEventListener("change", function(ev) { + if (ev.target.value > "" && ev.target.files.length == 1) + morefile.style.visibility = "visible"; + // No need to hide again, sure? + }); + } + morefile.addEventListener("click", addFileInput, null); + } + // When renaming, select basename part + for (el of collectElementsByAttr("input", "class", "mv")) { + el.addEventListener("focus", function(ev) { + var i = ev.target; + if (i) { + i.setSelectionRange(0, i.value.lastIndexOf(".")); + } + }); + } + } function initBlogs() { - var el, check = collectElementsByAttr("input", "name", "notifyto"); + // Auto-complete #xxxx + var check = collectElementsByAttr("input", "name", "notifyto"); if (check) for (let i of check) { i.addEventListener("click", insertRedirect, null); @@ -138,6 +179,7 @@ function init() { initGrpAction(); initBlogs(); + initFileInput(); } document.addEventListener('DOMContentLoaded', init, null); })();