diff --git a/main.go b/main.go index 95e0f3d..d778a8b 100644 --- a/main.go +++ b/main.go @@ -56,7 +56,7 @@ func init() { )) templates = make(map[string]*template.Template) if !*watch { - for _, name := range []string{"index.html", "login.html", "frontpage.html", "root.html", "settings.html", "xhr.html", "create_comment.html"} { + for _, name := range []string{"index.html", "login.html", "frontpage.html", "root.html", "settings.html", "xhr.html", "create_comment.html", "block.html"} { t := template.New(name).Funcs(funcMap) glob, err := t.ParseGlob("templates/*") if err != nil { diff --git a/public/style.css b/public/style.css index 7522f61..6de8ae4 100644 --- a/public/style.css +++ b/public/style.css @@ -408,9 +408,12 @@ form.nsfw div { .gray { color: #808080; } -.loading { +.morecomments .loading { color: red !important; } +.blockpopup .loading { + padding: 2px; +} .error { color: red; font-size: 13px; @@ -462,7 +465,7 @@ form.nsfw div { .buttons li { display: inline; } -.buttons, .buttons input { +.buttons, .buttons > form input, .buttons li form input { font-weight: bold; font-size: 10px; padding: 0; @@ -481,20 +484,32 @@ form.nsfw div { border-left: 2px solid #c5c1ad; padding: 0 8px; } -.buttons a, .buttons form input, .comment .buttons form input { +.buttons a, .buttons > form input, .comment .buttons form input { text-decoration: none; color: #888; display: inline-block; margin-right: 5px !important; } -.buttons a:hover, .title a:hover, .buttons form input:hover, .comment .buttons form input:hover { +.buttons a:hover, .title a:hover, .buttons > form input:hover, .comment .buttons form input:hover { text-decoration: underline; } .entry { - overflow: hidden; color: #888; + overflow:hidden; +} +.entry .buttons .blockpopup { + display: inline-block; + position: absolute; + border: 1px solid #888; + z-index: 100; + background-color: white; +} +form.blockpost { + margin: 2px; +} +.blockpost div:last-child input { + margin: 4px 2px 4px 4px; } - .expando-button { width: 23px; height: 23px; @@ -816,7 +831,7 @@ h1, h2 { .dark .moderators a { color: #6a98af; } -.community { +main > .community { margin: 20px 50px; max-width: 840px; position: relative; diff --git a/public/utils.js b/public/utils.js index df8c22a..a07028b 100644 --- a/public/utils.js +++ b/public/utils.js @@ -51,13 +51,23 @@ function commentClick(e) { if (e.target.value == "preview") { targ = form } - console.log("ok") } else if (("c"+data.get("parentid")) == targ.id) { targ = form } else { return } e.target.disabled = "disabled" request(targ.action || "", data, function(res){ + if (data.get("op") == "block_user") { + var submitter = targ.getElementsByClassName("creator")[0].href + var comments = Array.prototype.slice.call(document.getElementsByClassName("comment")) + for (var i = 0; i < comments.length; i++) { + var submitter2 = comments[i].getElementsByClassName("creator")[0].href + if (submitter2 == submitter) { + comments[i].remove() + } + } + return + } targ.outerHTML = res setup() }, @@ -223,6 +233,10 @@ function formSubmit(e) { var data = new FormData(targ) data.set(e.submitter.name, e.submitter.value) data.set("xhr", "1") + if (data.get("submit") == "cancel") { + targ.remove() + return + } e.submitter.disabled = "disabled" request(targ.target, data, function(res){ @@ -230,6 +244,24 @@ function formSubmit(e) { document.getElementById("p"+data.get("postid")).remove() return } + if (data.get("op") == "block_post") { + var post = document.getElementById("p"+data.get("postid")) + var user = post.getElementsByClassName("submitter")[0].href + var community = post.getElementsByClassName("community")[0].href + var posts = Array.prototype.slice.call(document.getElementsByClassName("post")) + for (var i = 0; i < posts.length; i++) { + var user2 = posts[i].getElementsByClassName("submitter")[0].href + var community2 = posts[i].getElementsByClassName("community")[0].href + if (data.get("blockcommunity") != null && community2 == community) { + posts[i].remove() + } + if (data.get("blockuser") != null && user2 == user) { + posts[i].remove() + } + } + targ.remove() + return + } targ.outerHTML = res setup() }, @@ -388,7 +420,7 @@ function setup() { var posts = document.getElementsByClassName("post") for (var i = 0; i < posts.length; i++) { posts[i].addEventListener("click", postClick) - var forms = posts[i].getElementsByClassName("link-btn") + var forms = posts[i].getElementsByTagName("form") for (var f = 0; f < forms.length; f++) { forms[f].addEventListener("submit", formSubmit) } @@ -406,6 +438,34 @@ function setup() { for (var i = 0; i < comments.length; i++) { comments[i].addEventListener("click", commentClick) } + var links = document.getElementsByTagName("a") + for (var i = 0; i < links.length; i++) { + if (links[i].rel == "xhr") { + links[i].addEventListener("click", xhrLink) + } + } +} +function xhrLink(e) { + e = e || window.event; + e.preventDefault(); + var targ = e.currentTarget || e.srcElement || e; + var t = [] + if (targ.target != "") { + t = document.getElementsByName(targ.target) + } + if (t.length) { + t[0].innerHTML = '