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 diff
1.1 --- a/examples/common/default/html.m4.html Thu Aug 15 17:09:16 2019 +0900 1.2 +++ b/examples/common/default/html.m4.html Fri Aug 16 09:48:19 2019 +0900 1.3 @@ -8,6 +8,7 @@ 1.4 `<meta name="theme-color" content="#8ea">') 1.5 <title>_TITLE_|ifdef(`_S4NAME_',`_S4NAME_',s4)</title> 1.6 <link rel="stylesheet" type="text/css" href="templ/default/default.css"> 1.7 +<script type="text/javascript" src="s4-main.js" charset="utf-8"></script> 1.8 ifdef(`_S4CSS_', 1.9 `<link rel="stylesheet" type="text/css" href="_S4CSS_"> 1.10 ')dnl
2.1 --- a/s4-blog.sh Thu Aug 15 17:09:16 2019 +0900 2.2 +++ b/s4-blog.sh Fri Aug 16 09:48:19 2019 +0900 2.3 @@ -440,7 +440,7 @@ 2.4 <input type="checkbox" id="cmt" checked><label 2.5 accesskey="c" title="C" for="cmt">コメントする</label><div> 2.6 <table class="b"> 2.7 -<tr><td><textarea name="text" cols="72" rows="4" title="'"$help"'"> 2.8 +<tr><td><textarea id="text" name="text" cols="72" rows="4" title="'"$help"'"> 2.9 </textarea>'"$touchhelp</td></tr> 2.10 <tr><td>添付ファイル(${filesize_max_MB}以下):"' 2.11 <input type="file" name="image"'" $file_accept title=\"$filehelp\" multiple></td></tr>"'
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/s4-main.js Fri Aug 16 09:48:19 2019 +0900 3.3 @@ -0,0 +1,62 @@ 3.4 +(function (){ 3.5 + function collectElementsByNameAttr(elm, name) { 3.6 + var e = document.getElementsByTagName(elm); 3.7 + if (!e) return null; 3.8 + var list = []; 3.9 + for (var i of e) { 3.10 + if (i.getAttribute("name") == name) 3.11 + list.push(i) 3.12 + } 3.13 + return list; 3.14 + } 3.15 + function insertRedirect(e) { 3.16 + var articleId, textarea = document.getElementById("text"); 3.17 + var p = e.target, checked = p.checked; 3.18 + while (p = p.parentNode) 3.19 + if (p.nodeName.match(/^td$/i)) break; 3.20 + if (!p) return; 3.21 + while (p = p.nextSibling) 3.22 + if (p.nodeName.match(/^td$/i)) break; 3.23 + if (!p) return; 3.24 + articleId = p.getAttribute("id"); 3.25 + if (textarea && articleId) { 3.26 + var tv = textarea.value, lines; 3.27 + if (tv) 3.28 + lines = tv.split("\n"); 3.29 + else 3.30 + lines = [""]; 3.31 + var re = new RegExp("[, ]*#"+articleId+"(?![0-9])"); 3.32 + if (checked) { 3.33 + if (!lines[0].match(re)) { 3.34 + var re2 = new RegExp(/>#[#0-9, ]+[0-9]/); 3.35 + if (lines[0].match(re2)) 3.36 + lines[0] = lines[0].replace( 3.37 + re2, '$&, '+'#'+articleId); 3.38 + else { 3.39 + if (lines[0] > "") lines[0] = " "+lines[0]; 3.40 + lines[0] = ">#"+articleId+lines[0]; 3.41 + } 3.42 + } 3.43 + } else { // Remove #xxxxx 3.44 + if (lines[0].match(/^>#[0-9 ,]+#/)) // 2 or more #id's 3.45 + lines[0] = lines[0].replace( 3.46 + new RegExp("^>#"+articleId+"[ ,]*"), ">").replace( 3.47 + new RegExp("[ ,]*#"+articleId), ""); 3.48 + else { 3.49 + lines[0] = lines[0].replace( 3.50 + new RegExp(">#"+articleId+"[ ,]*"), ""); 3.51 + } 3.52 + } 3.53 + lines[0] = lines[0].replace(/^> *$/, ''); 3.54 + textarea.value = lines.join("\n"); 3.55 + } 3.56 + } 3.57 + function init(){ 3.58 + var el, check = collectElementsByNameAttr("input", "notifyto"); 3.59 + if (check) 3.60 + for (var i of check) { 3.61 + i.addEventListener("click", insertRedirect, null); 3.62 + } 3.63 + } 3.64 + document.addEventListener('DOMContentLoaded', init, null); 3.65 +})();