Add “toggle parser” link to posts and replies to deactivate the parser.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Mon, 7 Mar 2011 20:29:57 +0000 (21:29 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Mon, 7 Mar 2011 20:29:57 +0000 (21:29 +0100)
src/main/java/net/pterodactylus/sone/web/ViewPostPage.java
src/main/resources/i18n/sone.en.properties
src/main/resources/static/css/sone.css
src/main/resources/static/javascript/sone.js
src/main/resources/templates/include/viewPost.html
src/main/resources/templates/include/viewReply.html

index 864dc84..967b9c5 100644 (file)
@@ -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);
        }
 
        /**
index 4c85ab0..4d912e9 100644 (file)
@@ -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
 
index 371a86d..8eb8449 100644 (file)
@@ -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);
index e99d654..9ef6812 100644 (file)
@@ -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));
index fd5846c..3023566 100644 (file)
@@ -16,7 +16,8 @@
                                        <div class="recipient profile-link"><a href="viewSone.html?sone=<% post.recipient.id|html>"><% post.recipient.niceName|html></a></div>
                                <%/if>
                        <%/if>
-                       <div class="text"><% post.text|parse sone=post.sone></div>
+                       <div class="post-text raw-text<%if !raw> hidden<%/if>"><% post.text|html></div>
+                       <div class="post-text text<%if raw> hidden<%/if>"><% post.text|parse sone=post.sone></div>
                </div>
                <div class="post-status-line status-line">
                        <div class="bookmarks">
@@ -35,6 +36,8 @@
                        </div>
                        <span class='separator'>·</span>
                        <div class="time"><a href="viewPost.html?post=<% post.id|html>"><% post.time|date format="MMM d, yyyy, HH:mm:ss"></a></div>
+                       <span class='separator'>·</span>
+                       <div class="show-source"><a href="viewPost.html?post=<% post.id|html>&amp;raw=<%if raw>false<%else>true<%/if>"><%= View.Post.ShowSource|l10n|html></a></div>
                        <div class="likes<%if post.likes.size|match value=0> hidden<%/if>">
                                <span class='separator'>·</span>
                                <span title="<% post.likes.soneNames|html>">↑<span class="like-count"><% post.likes.size></span></span>
index cfe15f1..cdb837c 100644 (file)
@@ -8,10 +8,13 @@
        <div class="inner-part">
                <div>
                        <div class="author profile-link"><a href="viewSone.html?sone=<% reply.sone.id|html>"><% reply.sone.niceName|html></a></div>
-                       <div class="text"><% reply.text|parse sone=reply.sone></div>
+                       <div class="reply-text raw-text<%if !raw> hidden<%/if>"><% reply.text|html></div>
+                       <div class="reply-text text<%if raw> hidden<%/if>"><% reply.text|parse sone=reply.sone></div>
                </div>
                <div class="reply-status-line status-line">
                        <div class="time"><% reply.time|date format="MMM d, yyyy, HH:mm:ss"></div>
+                       <span class='separator'>·</span>
+                       <div class="show-reply-source"><a href="viewPost.html?post=<% post.id|html>&amp;raw=<%if raw>false<%else>true<%/if>"><%= View.Post.ShowSource|l10n|html></a></div>
                        <div class="likes<%if reply.likes.size|match value=0> hidden<%/if>">
                                <span class='separator'>·</span>
                                <span title="<% reply.likes.soneNames|html>">↑<span class="like-count"><% reply.likes.size></span></span>