expand/collapse comments with animation; added collapse link on bottom
This commit is contained in:
parent
64113eb8f2
commit
f34f0ce5fb
5 changed files with 46 additions and 34 deletions
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
= form_tag( post_comments_path(post_id), :id => "new_comment_on_#{post_id}", :class => 'new_comment', :autocomplete => "off") do
|
= form_tag( post_comments_path(post_id), :id => "new_comment_on_#{post_id}", :class => 'new_comment', :autocomplete => "off") do
|
||||||
= hidden_field_tag :post_id, post_id, :id => "post_id_on_#{post_id}"
|
= hidden_field_tag :post_id, post_id, :id => "post_id_on_#{post_id}"
|
||||||
= text_area_tag :text, nil, :rows => 2, :class => "comment_box",:id => "comment_text_on_#{post_id}", :placeholder => t('.comment')
|
= text_area_tag :text, nil, :rows => 2, :class => "comment_box",:id => "comment_text_on_#{post_id}", :placeholder => t('.comment'), :autofocus => true
|
||||||
|
|
||||||
.actions
|
.actions
|
||||||
= link_to "Cancel", post_path(post_id), :class => "cancel_new_comment btn"
|
= link_to "Cancel", post_path(post_id), :class => "cancel_new_comment btn"
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@
|
||||||
.post_stats
|
.post_stats
|
||||||
%span.comment_count
|
%span.comment_count
|
||||||
= @post.comments.size
|
= @post.comments.size
|
||||||
|
|
||||||
%span.like_count
|
%span.like_count
|
||||||
= @post.likes.size
|
= @post.likes.size
|
||||||
|
|
||||||
|
|
@ -10,4 +9,6 @@
|
||||||
= render :partial => 'comments/comment', :collection => @comments, :locals => {:post => @post}
|
= render :partial => 'comments/comment', :collection => @comments, :locals => {:post => @post}
|
||||||
|
|
||||||
%li.comment.add_comment_bottom_link_container
|
%li.comment.add_comment_bottom_link_container
|
||||||
|
= link_to "#", :class => "show_comments bottom_collapse active" do
|
||||||
|
= image_tag 'icons/arrow_up_small.png'
|
||||||
= link_to "Add a comment", new_post_comment_path(@post), :class => 'add_comment_bottom_link btn comment_action inactive'
|
= link_to "Add a comment", new_post_comment_path(@post), :class => 'add_comment_bottom_link btn comment_action inactive'
|
||||||
|
|
|
||||||
|
|
@ -50,11 +50,6 @@
|
||||||
- if user_signed_in?
|
- if user_signed_in?
|
||||||
= link_to(image_tag('icons/compose_mobile2.png', :height => 28, :width => 28), new_status_message_path, :class => 'compose_icon')
|
= link_to(image_tag('icons/compose_mobile2.png', :height => 28, :width => 28), new_status_message_path, :class => 'compose_icon')
|
||||||
|
|
||||||
- if flash.present?
|
|
||||||
%p
|
|
||||||
- flash.each do |name, msg|
|
|
||||||
= content_tag :div, msg, :id => "flash_#{name}"
|
|
||||||
|
|
||||||
#main{:role => "main"}
|
#main{:role => "main"}
|
||||||
= yield
|
= yield
|
||||||
|
|
||||||
|
|
@ -64,9 +59,6 @@
|
||||||
/ javascripts at the bottom
|
/ javascripts at the bottom
|
||||||
= include_javascripts :mobile
|
= include_javascripts :mobile
|
||||||
|
|
||||||
/-if current_user
|
|
||||||
/ :javascript
|
|
||||||
/ Diaspora.I18n.loadLocale(#{get_javascript_strings_for(current_user.language).to_json}, "#{current_user.language}");
|
|
||||||
:javascript
|
:javascript
|
||||||
MBP.hideUrlBar();
|
MBP.hideUrlBar();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -52,27 +52,37 @@ $(document).ready(function(){
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
$("a.show_comments").bind("tap click", function(evt){
|
$(".stream").delegate(".show_comments", "tap click", function(evt){
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
var link = $(this),
|
var link = $(this),
|
||||||
parent = link.closest(".bottom_bar").first(),
|
parent = link.closest(".bottom_bar").first(),
|
||||||
commentsContainer = parent.find(".comment_container");
|
commentsContainer = function(){ return parent.find(".comment_container").first(); }
|
||||||
|
existingCommentsContainer = commentsContainer();
|
||||||
|
|
||||||
if( link.hasClass('active') ) {
|
if( link.hasClass('active') ) {
|
||||||
commentsContainer.first().hide();
|
existingCommentsContainer.hide();
|
||||||
link.removeClass('active');
|
if(!link.hasClass('bottom_collapse')){
|
||||||
|
link.removeClass('active');
|
||||||
|
} else {
|
||||||
|
parent.find(".show_comments").first().removeClass('active');
|
||||||
|
}
|
||||||
|
|
||||||
} else if( commentsContainer.length > 0) {
|
$('html,body').scrollTop(parent.offset().top - parent.closest(".stream_element").height() - 8);
|
||||||
commentsContainer.first().show();
|
|
||||||
|
|
||||||
if(!commentsContainer.hasClass('noComments')) {
|
} else if( existingCommentsContainer.length > 0) {
|
||||||
|
|
||||||
|
if(!existingCommentsContainer.hasClass('noComments')) {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: link.attr('href'),
|
url: link.attr('href'),
|
||||||
success: function(data){
|
success: function(data){
|
||||||
parent.append($(data).find('.comments_container').html());
|
parent.append($(data).find('.comments_container').html());
|
||||||
link.addClass('active');
|
link.addClass('active');
|
||||||
|
existingCommentsContainer.show();
|
||||||
|
scrollToOffset(parent, commentsContainer());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
existingCommentsContainer.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
link.addClass('active');
|
link.addClass('active');
|
||||||
|
|
@ -83,18 +93,30 @@ $(document).ready(function(){
|
||||||
success: function(data){
|
success: function(data){
|
||||||
parent.append(data);
|
parent.append(data);
|
||||||
link.addClass('active');
|
link.addClass('active');
|
||||||
|
scrollToOffset(parent, commentsContainer());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var scrollToOffset = function(parent, commentsContainer){
|
||||||
|
var commentCount = commentsContainer.find("li.comment").length;
|
||||||
|
if( commentCount > 3 ) {
|
||||||
|
var lastComment = commentsContainer.find("li:nth-child("+(commentCount-4)+")");
|
||||||
|
$('html,body').animate({
|
||||||
|
scrollTop: lastComment.offset().top
|
||||||
|
}, 1000);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
$(".stream").delegate("a.comment_action", "tap click", function(evt){
|
$(".stream").delegate("a.comment_action", "tap click", function(evt){
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
var link = $(this);
|
var link = $(this);
|
||||||
|
|
||||||
if(link.hasClass('inactive')) {
|
if(link.hasClass('inactive')) {
|
||||||
var parent = link.closest(".bottom_bar").first(),
|
var parent = link.closest(".bottom_bar").first(),
|
||||||
container = link.closest('.bottom_bar').find('.add_comment_bottom_link_container');
|
container = link.closest('.bottom_bar').find('.add_comment_bottom_link_container').first();
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: link.attr('href'),
|
url: link.attr('href'),
|
||||||
|
|
@ -111,12 +133,9 @@ $(document).ready(function(){
|
||||||
link.removeClass('inactive');
|
link.removeClass('inactive');
|
||||||
}
|
}
|
||||||
|
|
||||||
container.first().hide();
|
container.hide();
|
||||||
|
|
||||||
parent.append(data);
|
parent.append(data);
|
||||||
|
new MBP.autogrow(textarea);
|
||||||
textarea.focus();
|
|
||||||
new MBP.autogrow(textarea, lineHeight);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -145,7 +164,7 @@ $(document).ready(function(){
|
||||||
var bottomBar = form.closest('.bottom_bar').first(),
|
var bottomBar = form.closest('.bottom_bar').first(),
|
||||||
container = bottomBar.find('.add_comment_bottom_link_container'),
|
container = bottomBar.find('.add_comment_bottom_link_container'),
|
||||||
commentActionLink = bottomBar.find("a.comment_action").first();
|
commentActionLink = bottomBar.find("a.comment_action").first();
|
||||||
reactionLink = bottomBar.find(".show_comments"),
|
reactionLink = bottomBar.find("a.show_comments").first(),
|
||||||
commentCount = bottomBar.find(".comment_count");
|
commentCount = bottomBar.find(".comment_count");
|
||||||
|
|
||||||
if(container.length > 0) {
|
if(container.length > 0) {
|
||||||
|
|
@ -154,7 +173,7 @@ $(document).ready(function(){
|
||||||
container.show();
|
container.show();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
var container = $("<div class='comments_container '></div>"),
|
var container = $("<div class='comments_container not_all_present'></div>"),
|
||||||
comments = $("<ul class='comments'></ul>");
|
comments = $("<ul class='comments'></ul>");
|
||||||
|
|
||||||
comments.html(data);
|
comments.html(data);
|
||||||
|
|
@ -163,8 +182,6 @@ $(document).ready(function(){
|
||||||
container.appendTo(bottomBar)
|
container.appendTo(bottomBar)
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(reactionLink.text());
|
|
||||||
|
|
||||||
reactionLink.text(reactionLink.text().replace(/(\d+)/, function(match){ return parseInt(match) + 1; }));
|
reactionLink.text(reactionLink.text().replace(/(\d+)/, function(match){ return parseInt(match) + 1; }));
|
||||||
commentCount.text(commentCount.text().replace(/(\d+)/, function(match){ return parseInt(match) + 1; }));
|
commentCount.text(commentCount.text().replace(/(\d+)/, function(match){ return parseInt(match) + 1; }));
|
||||||
commentActionLink.addClass("inactive");
|
commentActionLink.addClass("inactive");
|
||||||
|
|
|
||||||
|
|
@ -265,8 +265,6 @@ header {
|
||||||
z-index: 10;
|
z-index: 10;
|
||||||
top: 0;
|
top: 0;
|
||||||
|
|
||||||
-webkit-transform: translate3d(0,0,0);
|
|
||||||
|
|
||||||
border: {
|
border: {
|
||||||
bottom: 1px solid #222;
|
bottom: 1px solid #222;
|
||||||
}
|
}
|
||||||
|
|
@ -317,7 +315,7 @@ footer {
|
||||||
a.show_comments {
|
a.show_comments {
|
||||||
color: #999;
|
color: #999;
|
||||||
|
|
||||||
&.active {
|
&.active:not(.bottom_collapse) {
|
||||||
color: #444;
|
color: #444;
|
||||||
padding: {
|
padding: {
|
||||||
right: 14px;
|
right: 14px;
|
||||||
|
|
@ -330,6 +328,13 @@ footer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.show_comments.bottom_collapse {
|
||||||
|
position: absolute;
|
||||||
|
right: 10px;
|
||||||
|
top: 14px;
|
||||||
|
padding: 5px 10px;
|
||||||
|
}
|
||||||
|
|
||||||
#bottom_bar_tabs {
|
#bottom_bar_tabs {
|
||||||
display: table;
|
display: table;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
|
@ -364,10 +369,6 @@ footer {
|
||||||
.floater {
|
.floater {
|
||||||
float: right; }
|
float: right; }
|
||||||
|
|
||||||
.stream_element {
|
|
||||||
-webkit-transform: translate3d(0,0,0);
|
|
||||||
}
|
|
||||||
|
|
||||||
.stream_element .photo_attachments {
|
.stream_element .photo_attachments {
|
||||||
background: {
|
background: {
|
||||||
color: #999;
|
color: #999;
|
||||||
|
|
@ -507,6 +508,7 @@ select {
|
||||||
}
|
}
|
||||||
|
|
||||||
.comment.add_comment_bottom_link_container {
|
.comment.add_comment_bottom_link_container {
|
||||||
|
position: relative;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
padding: 25px !important;
|
padding: 25px !important;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue