Mercurial > hgrepos > hgweb.cgi > s4
changeset 586:a03bfd5d242a
First trial of js interaction.
Reply checkbox inserts/removes redirection mark.
author | HIROSE Yuuji <yuuji@gentei.org> |
---|---|
date | Fri, 16 Aug 2019 09:48:19 +0900 |
parents | dfa90fbc05bd |
children | 1e40019d1bb1 |
files | examples/common/default/html.m4.html s4-blog.sh s4-main.js |
diffstat | 3 files changed, 64 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/examples/common/default/html.m4.html Thu Aug 15 17:09:16 2019 +0900 +++ b/examples/common/default/html.m4.html Fri Aug 16 09:48:19 2019 +0900 @@ -8,6 +8,7 @@ `<meta name="theme-color" content="#8ea">') <title>_TITLE_|ifdef(`_S4NAME_',`_S4NAME_',s4)</title> <link rel="stylesheet" type="text/css" href="templ/default/default.css"> +<script type="text/javascript" src="s4-main.js" charset="utf-8"></script> ifdef(`_S4CSS_', `<link rel="stylesheet" type="text/css" href="_S4CSS_"> ')dnl
--- a/s4-blog.sh Thu Aug 15 17:09:16 2019 +0900 +++ b/s4-blog.sh Fri Aug 16 09:48:19 2019 +0900 @@ -440,7 +440,7 @@ <input type="checkbox" id="cmt" checked><label accesskey="c" title="C" for="cmt">コメントする</label><div> <table class="b"> -<tr><td><textarea name="text" cols="72" rows="4" title="'"$help"'"> +<tr><td><textarea id="text" name="text" cols="72" rows="4" title="'"$help"'"> </textarea>'"$touchhelp</td></tr> <tr><td>添付ファイル(${filesize_max_MB}以下):"' <input type="file" name="image"'" $file_accept title=\"$filehelp\" multiple></td></tr>"'
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/s4-main.js Fri Aug 16 09:48:19 2019 +0900 @@ -0,0 +1,62 @@ +(function (){ + function collectElementsByNameAttr(elm, name) { + var e = document.getElementsByTagName(elm); + if (!e) return null; + var list = []; + for (var i of e) { + if (i.getAttribute("name") == name) + list.push(i) + } + return list; + } + function insertRedirect(e) { + var articleId, textarea = document.getElementById("text"); + var p = e.target, checked = p.checked; + while (p = p.parentNode) + if (p.nodeName.match(/^td$/i)) break; + if (!p) return; + while (p = p.nextSibling) + if (p.nodeName.match(/^td$/i)) break; + if (!p) return; + articleId = p.getAttribute("id"); + if (textarea && articleId) { + var tv = textarea.value, lines; + if (tv) + lines = tv.split("\n"); + else + lines = [""]; + var re = new RegExp("[, ]*#"+articleId+"(?![0-9])"); + if (checked) { + if (!lines[0].match(re)) { + var re2 = new RegExp(/>#[#0-9, ]+[0-9]/); + if (lines[0].match(re2)) + lines[0] = lines[0].replace( + re2, '$&, '+'#'+articleId); + else { + if (lines[0] > "") lines[0] = " "+lines[0]; + lines[0] = ">#"+articleId+lines[0]; + } + } + } else { // Remove #xxxxx + if (lines[0].match(/^>#[0-9 ,]+#/)) // 2 or more #id's + lines[0] = lines[0].replace( + new RegExp("^>#"+articleId+"[ ,]*"), ">").replace( + new RegExp("[ ,]*#"+articleId), ""); + else { + lines[0] = lines[0].replace( + new RegExp(">#"+articleId+"[ ,]*"), ""); + } + } + lines[0] = lines[0].replace(/^> *$/, ''); + textarea.value = lines.join("\n"); + } + } + function init(){ + var el, check = collectElementsByNameAttr("input", "notifyto"); + if (check) + for (var i of check) { + i.addEventListener("click", insertRedirect, null); + } + } + document.addEventListener('DOMContentLoaded', init, null); +})();