Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Implement 'Reply to this comment' button

  • Loading branch information...
commit 830ae5e64d2fb28a2e4cee68bfa18d91db6cec6e 1 parent 64cd7b5
@FooBarWidget FooBarWidget authored
View
19 app/assets/stylesheets/api.css.scss
@@ -13,6 +13,21 @@
}
}
+.juvia-container blockquote {
+ font-size: 100%;
+ font-style: italic;
+ font-family: Georgia, Serif;
+ border-left: #dddddd 2px solid;
+ margin: 0.5em;
+ padding: 0 0 0 1em;
+ color: #888888;
+
+ p {
+ margin-top: 0.5em;
+ margin-bottom: 0.5em;
+ }
+}
+
.juvia-comment {
min-height: 64px;
margin-bottom: 30px;
@@ -61,6 +76,10 @@
font-style: italic;
}
+.juvia-reply-to-comment {
+ font-size: 80%;
+}
+
.juvia-comment-content,
.juvia-preview-conten {
@include CommentContent;
View
3  app/views/api/_comment.html.erb
@@ -32,7 +32,8 @@
administrator.
</p>
<% end %>
- <%= render_markdown(comment.content) %>
+ <div class="juvia-comment-pure-content"><%= render_markdown(comment.content) %></div>
+ <p class="juvia-reply-to-comment"><a href="javascript:void(0)">Reply to this comment</a></p>
</div>
</div>
</div>
View
32 app/views/api/base.js.erb
@@ -58,7 +58,7 @@ if (!Juvia) {
});
content.show();
});
-
+
var textarea = $('.juvia-textarea-field textarea', addCommentForm);
textarea.delayedObserver(function() {
self.previewComment(this);
@@ -73,6 +73,15 @@ if (!Juvia) {
}, 1);
});
});
+
+ $('.juvia-reply-to-comment a:not(.juvia-installed-behavior)').each(function() {
+ var $this = $(this);
+ $this.addClass('juvia-installed-behavior');
+ $this.bind('click', function() {
+ var comment = $(this).closest('.juvia-comment');
+ self.replyToComment(comment);
+ });
+ });
}
Juvia.findContainer = function(options) {
@@ -245,6 +254,27 @@ if (!Juvia) {
}
}
+ Juvia.replyToComment = function($comment) {
+ var $container = $comment.closest('.juvia-container');
+ var text = $('.juvia-comment-pure-content', $comment).text();
+ var lines = text.split("\n");
+ var i;
+ for (i = 0; i < lines.length; i++) {
+ lines[i] = '> ' +lines[i];
+ }
+
+ var $textarea = $('textarea', $container);
+ var authorName = $.trim($('.juvia-author', $comment).text());
+ var newContent = "*" + authorName + " wrote:*\n" + lines.join("\n");
+ if ($textarea.val() != '') {
+ newContent += "\n\n";
+ newContent += $textarea.val();
+ }
+ $textarea.val(newContent);
+ this.smoothlyScrollTo($textarea.offset().top);
+ $textarea.focus();
+ }
+
/* The browser does not save the content of the Juvia comments box when
* the user reloads the page. In order to prevent data loss we implement
* our own saving capabilities. The text box is saved into sessionStorage
Please sign in to comment.
Something went wrong with that request. Please try again.