From 6991fe9edc0e1652b695f9c0b2844bb6a0842c84 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Mon, 7 Mar 2011 21:29:57 +0100 Subject: [PATCH] =?utf8?q?Add=20=E2=80=9Ctoggle=20parser=E2=80=9D=20link?= =?utf8?q?=20to=20posts=20and=20replies=20to=20deactivate=20the=20parser.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../java/net/pterodactylus/sone/web/ViewPostPage.java | 2 ++ src/main/resources/i18n/sone.en.properties | 1 + src/main/resources/static/css/sone.css | 10 +++++++++- src/main/resources/static/javascript/sone.js | 18 ++++++++++++++++++ src/main/resources/templates/include/viewPost.html | 5 ++++- src/main/resources/templates/include/viewReply.html | 5 ++++- 6 files changed, 38 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/web/ViewPostPage.java b/src/main/java/net/pterodactylus/sone/web/ViewPostPage.java index 864dc84..967b9c5 100644 --- a/src/main/java/net/pterodactylus/sone/web/ViewPostPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ViewPostPage.java @@ -52,8 +52,10 @@ public class ViewPostPage extends SoneTemplatePage { protected void processTemplate(Request request, TemplateContext templateContext) throws RedirectException { super.processTemplate(request, templateContext); String postId = request.getHttpRequest().getParam("post"); + boolean raw = request.getHttpRequest().getParam("raw").equals("true"); Post post = webInterface.getCore().getPost(postId); templateContext.set("post", post); + templateContext.set("raw", raw); } /** diff --git a/src/main/resources/i18n/sone.en.properties b/src/main/resources/i18n/sone.en.properties index 4c85ab0..4d912e9 100644 --- a/src/main/resources/i18n/sone.en.properties +++ b/src/main/resources/i18n/sone.en.properties @@ -213,6 +213,7 @@ View.Post.SendReply=Post Reply! View.Post.Reply.DeleteLink=Delete View.Post.LikeLink=Like View.Post.UnlikeLink=Unlike +View.Post.ShowSource=Toggle Parser View.UpdateStatus.Text.ChooseSenderIdentity=Choose the sender identity diff --git a/src/main/resources/static/css/sone.css b/src/main/resources/static/css/sone.css index 371a86d..8eb8449 100644 --- a/src/main/resources/static/css/sone.css +++ b/src/main/resources/static/css/sone.css @@ -239,11 +239,15 @@ textarea { font-weight: bold; } -#sone .post .text { +#sone .post .text, #sone .post .raw-text { display: inline; white-space: pre-wrap; } +#sone .post .text.hidden, #sone .post .raw-text.hidden { + display: none; +} + #sone .post .status-line { margin-top: 0.5ex; font-size: 85%; @@ -254,6 +258,10 @@ textarea { color: rgb(28, 131, 191); } +#sone .show-source, #sone .show-reply-source { + display: inline; +} + #sone .post .bookmarks { display: inline; color: rgb(28, 131, 191); diff --git a/src/main/resources/static/javascript/sone.js b/src/main/resources/static/javascript/sone.js index e99d654..9ef6812 100644 --- a/src/main/resources/static/javascript/sone.js +++ b/src/main/resources/static/javascript/sone.js @@ -702,6 +702,15 @@ function ajaxifyPost(postElement) { return false; }); + /* convert “show source” link into javascript function. */ + $(postElement).find(".show-source").each(function() { + $("a", this).click(function() { + $(".post-text.text", getPostElement(this)).toggleClass("hidden"); + $(".post-text.raw-text", getPostElement(this)).toggleClass("hidden"); + return false; + }); + }); + /* add “comment” link. */ addCommentLink(getPostId(postElement), postElement, $(postElement).find(".post-status-line .time")); @@ -762,6 +771,15 @@ function ajaxifyReply(replyElement) { })(replyElement); addCommentLink(getPostId(replyElement), replyElement, $(replyElement).find(".reply-status-line .time")); + /* convert “show source” link into javascript function. */ + $(replyElement).find(".show-reply-source").each(function() { + $("a", this).click(function() { + $(".reply-text.text", getReplyElement(this)).toggleClass("hidden"); + $(".reply-text.raw-text", getReplyElement(this)).toggleClass("hidden"); + return false; + }); + }); + /* convert trust control buttons to javascript functions. */ $(replyElement).find(".reply-trust").submit(function() { trustSone(getReplyAuthor(this)); diff --git a/src/main/resources/templates/include/viewPost.html b/src/main/resources/templates/include/viewPost.html index fd5846c..3023566 100644 --- a/src/main/resources/templates/include/viewPost.html +++ b/src/main/resources/templates/include/viewPost.html @@ -16,7 +16,8 @@ <%/if> <%/if> -
<% post.text|parse sone=post.sone>
+
<% post.text|html>
+
<% post.text|parse sone=post.sone>
@@ -35,6 +36,8 @@
· + · +
· ↑ diff --git a/src/main/resources/templates/include/viewReply.html b/src/main/resources/templates/include/viewReply.html index cfe15f1..cdb837c 100644 --- a/src/main/resources/templates/include/viewReply.html +++ b/src/main/resources/templates/include/viewReply.html @@ -8,10 +8,13 @@
-
<% reply.text|parse sone=reply.sone>
+
<% reply.text|html>
+
<% reply.text|parse sone=reply.sone>
<% reply.time|date format="MMM d, yyyy, HH:mm:ss">
+ · +
· ↑ -- 2.7.4