s4
changeset 1035:e8f73df7ed5d
Add "sort by uid" button to blog table
author | HIROSE Yuuji <yuuji@gentei.org> |
---|---|
date | Wed, 06 Mar 2024 09:37:52 +0900 |
parents | 17e21e7dcfaa |
children | 9c392ddb4d8a |
files | s4-main.js |
diffstat | 1 files changed, 55 insertions(+), 6 deletions(-) [+] |
line diff
1.1 --- a/s4-main.js Wed Mar 06 09:32:51 2024 +0900 1.2 +++ b/s4-main.js Wed Mar 06 09:37:52 2024 +0900 1.3 @@ -894,8 +894,11 @@ 1.4 } 1.5 } 1.6 function initBlogs() { 1.7 - // Auto-complete #xxxx 1.8 + // (1)Auto-complete #xxxx, (2)Prepare sort 1.9 + 1.10 + // (1)Complete #xxxx 1.11 let i, check = collectElementsByAttr("input", "name", "notifyto"); 1.12 + let blogheadtd = document.querySelector("table.bloghead tr td"); 1.13 if (check) 1.14 for (i of check) { 1.15 i.addEventListener("click", insertRedirect, false); 1.16 @@ -924,8 +927,7 @@ 1.17 i = document.getElementById("reload"); 1.18 if (i) i.addEventListener("click", ajaxPost, false); 1.19 // Add CSV download button 1.20 - let td = document.querySelector("table.bloghead tr td"); 1.21 - if (td) { 1.22 + if (blogheadtd) { 1.23 let btn = document.createElement("button"); 1.24 btn.innerText = "CSVget"; 1.25 btn.type = "button"; 1.26 @@ -936,7 +938,7 @@ 1.27 Excelで利用する場合は Ctrl を押しながらクリックして下さい。 1.28 Get seen TEXT content as CSV.`; 1.29 btn.addEventListener("click", getTextContentCSV, false); 1.30 - let artlink = td.querySelector('a[accesskey="f"]'); 1.31 + let artlink = blogheadtd.querySelector('a[accesskey="f"]'); 1.32 let spacer = document.createElement("span"); 1.33 if (artlink) { 1.34 spacer.innerText = "|"; 1.35 @@ -944,8 +946,8 @@ 1.36 artlink.insertAdjacentElement('beforebegin', spacer); 1.37 } else { 1.38 spacer.innerText = " "; 1.39 - td.appendChild(spacer); 1.40 - td.appendChild(btn); 1.41 + blogheadtd.appendChild(spacer); 1.42 + blogheadtd.appendChild(btn); 1.43 } 1.44 } 1.45 } 1.46 @@ -960,6 +962,53 @@ 1.47 // Hack article_m links 1.48 registPjaxViewers(document.querySelectorAll("a[href]")); 1.49 atMarkView(document); 1.50 + /*****************************************************************/ 1.51 + //(2) Prepare sort 1.52 + let warn = document.querySelector("tr.warn span.warn"); 1.53 + if (blogheadtd && warn==null) { 1.54 + let umode = "UserSORT", amode = "ArticleSort"; 1.55 + let sbtn = document.createElement("button"); 1.56 + sbtn.textContent = umode; 1.57 + sbtn.type = 'button'; 1.58 + let spacer = document.createElement("span"); 1.59 + spacer.textContent = " "; 1.60 + let hide = document.getElementById("hideauth"); 1.61 + if (hide) { 1.62 + hide.insertAdjacentElement('afterend', sbtn); 1.63 + hide.insertAdjacentElement('afterend', spacer); 1.64 + } else { 1.65 + blogheadtd.appendChild(spacer); 1.66 + blogheadtd.appendChild(sbtn); 1.67 + } 1.68 + function compareRowsByUid(a, b) { 1.69 + if (a.key1 < b.key1) return -1; 1.70 + if (a.key1 > b.key1) return 1; 1.71 + if (a.key2 < b.key2) return -1; 1.72 + if (a.key2 > b.key2) return 1; 1.73 + return 0; 1.74 + } 1.75 + function compareRowsByAid(a, b) { 1.76 + if (a.key2 < b.key2) return -1; 1.77 + if (a.key2 > b.key2) return 1; 1.78 + return 0; 1.79 + } 1.80 + sbtn.addEventListener("click", (e)=>{ 1.81 + let uidsort = (sbtn.textContent.indexOf(umode) >= 0); 1.82 + let rows = [], elm, 1.83 + tbl = document.querySelector("table.blog_replies"); 1.84 + for (let tr of tbl.rows) { 1.85 + elm = {}; 1.86 + elm.tr = tr; 1.87 + elm.key1 = tr.querySelector("a.author").title; // userid 1.88 + tr.innerHTML.match(/<a href="(#[0-9]+)">\1</); // ArticleID 1.89 + elm.key2 = RegExp.$1; 1.90 + rows.push(elm); 1.91 + } 1.92 + rows.sort(uidsort ? compareRowsByUid : compareRowsByAid); 1.93 + for (let r of rows) tbl.appendChild(r.tr); 1.94 + sbtn.textContent = uidsort ? amode : umode; 1.95 + }); 1.96 + } 1.97 } 1.98 function initGrpAction() { 1.99 var rev = document.getElementById("reverse");