add option suppress_reply_directly_above to stop suppressing the reply directly above

added a bunch of debugging information to help diagnose weird positioning issues
This commit is contained in:
Sam 2013-07-08 11:13:45 +10:00
parent c6c8246399
commit d79aa917f1
5 changed files with 83 additions and 17 deletions

View File

@ -30,7 +30,10 @@ Discourse.Post = Discourse.Model.extend({
}.property('username'), }.property('username'),
showUserReplyTab: function() { showUserReplyTab: function() {
return this.get('reply_to_user') && (this.get('reply_to_post_number') < (this.get('post_number') - 1)); return this.get('reply_to_user') && (
!Discourse.SiteSettings.suppress_reply_directly_above ||
this.get('reply_to_post_number') < (this.get('post_number') - 1)
);
}.property('reply_to_user', 'reply_to_post_number', 'post_number'), }.property('reply_to_user', 'reply_to_post_number', 'post_number'),
byTopicCreator: function() { byTopicCreator: function() {

View File

@ -69,7 +69,16 @@ Discourse.PostView = Discourse.View.extend({
// Toggle visibility of parent post // Toggle visibility of parent post
toggleParent: function(e) { toggleParent: function(e) {
var postView = this; var postView = this;
var post = this.get('post');
var $parent = this.$('.parent-post'); var $parent = this.$('.parent-post');
var inReplyTo = post.get('reply_to_post_number');
if (post.get('post_number') - 1 === inReplyTo) {
// true means ... avoid scroll if possible
Discourse.TopicView.jumpToPost(post.get('topic_id'), inReplyTo, true);
return;
}
if (this.get('parentPost')) { if (this.get('parentPost')) {
$('nav', $parent).removeClass('toggled'); $('nav', $parent).removeClass('toggled');
// Don't animate on touch // Don't animate on touch
@ -80,11 +89,10 @@ Discourse.PostView = Discourse.View.extend({
$parent.slideUp(function() { postView.set('parentPost', null); }); $parent.slideUp(function() { postView.set('parentPost', null); });
} }
} else { } else {
var post = this.get('post');
this.set('loadingParent', true); this.set('loadingParent', true);
$('nav', $parent).addClass('toggled'); $('nav', $parent).addClass('toggled');
Discourse.Post.loadByPostNumber(post.get('topic_id'), post.get('reply_to_post_number')).then(function(result) { Discourse.Post.loadByPostNumber(post.get('topic_id'), inReplyTo).then(function(result) {
postView.set('loadingParent', false); postView.set('loadingParent', false);
// Give the post a reference back to the topic // Give the post a reference back to the topic
result.topic = postView.get('post.topic'); result.topic = postView.get('post.topic');
@ -159,9 +167,9 @@ Discourse.PostView = Discourse.View.extend({
showLinkCounts: function() { showLinkCounts: function() {
var postView = this; var postView = this;
var link_counts; var link_counts = this.get('post.link_counts');
if (link_counts = this.get('post.link_counts')) { if (link_counts) {
_.each(link_counts, function(lc) { _.each(link_counts, function(lc) {
if (lc.clicks > 0) { if (lc.clicks > 0) {
postView.$(".cooked a[href]").each(function() { postView.$(".cooked a[href]").each(function() {

View File

@ -329,30 +329,82 @@ Discourse.TopicView = Discourse.View.extend(Discourse.Scrolling, {
Discourse.TopicView.reopenClass({ Discourse.TopicView.reopenClass({
// Scroll to a given post, if in the DOM. Returns whether it was in the DOM or not. // Scroll to a given post, if in the DOM. Returns whether it was in the DOM or not.
jumpToPost: function(topicId, postNumber) { jumpToPost: function(topicId, postNumber, avoidScrollIfPossible) {
Em.run.scheduleOnce('afterRender', function() { Em.run.scheduleOnce('afterRender', function() {
var rows = $('.topic-post.ready');
// Make sure we're looking at the topic we want to scroll to // Make sure we're looking at the topic we want to scroll to
if (topicId !== parseInt($('#topic').data('topic-id'), 10)) { return false; } if (topicId !== parseInt($('#topic').data('topic-id'), 10)) { return false; }
var $post = $("#post_" + postNumber); var $post = $("#post_" + postNumber);
if ($post.length) { if ($post.length) {
if (postNumber === 1) {
$('html, body').scrollTop(0); var postTop = $post.offset().top;
var highlight = true;
var header = $('header');
var title = $('#topic-title');
var expectedOffset = title.height() - header.find('.contents').height();
console.log(expectedOffset);
if (expectedOffset < 0) {
expectedOffset = 0;
}
var offset = (header.outerHeight(true) + expectedOffset);
var windowScrollTop = $('html, body').scrollTop();
if (avoidScrollIfPossible && postTop > windowScrollTop + offset && postTop < windowScrollTop + $(window).height() + 100) {
// in view
} else { } else {
var header = $('header'); // not in view ... bring into view
var title = $('#topic-title'); if (postNumber === 1) {
var expectedOffset = title.height() - header.find('.contents').height(); $(window).scrollTop(0);
highlight = false;
} else {
var desired = $post.offset().top - offset;
$(window).scrollTop(desired);
if (expectedOffset < 0) { // TODO @Robin, I am seeing multiple events in chrome issued after
expectedOffset = 0; // jumpToPost if I refresh a page, sometimes I see 2, sometimes 3
//
// 1. Where are they coming from?
// 2. On refresh we should only issue a single scrollTop
// 3. If you are scrolled down in BoingBoing desired sometimes is wrong
// due to vanishing header, we should not be rendering it imho until after
// we render the posts
var first = true;
var t = new Date();
console.log("DESIRED:" + desired);
var enforceDesired = function(){
if($(window).scrollTop() !== desired) {
console.log("GOT EVENT " + $(window).scrollTop());
console.log("Time " + (new Date() - t));
console.trace();
if(first) {
$(window).scrollTop(desired);
first = false;
}
// $(document).unbind("scroll", enforceDesired);
}
};
// uncomment this line to help debug this issue.
// $(document).scroll(enforceDesired);
} }
}
$('html, body').scrollTop($post.offset().top - (header.outerHeight(true) + expectedOffset)); if(highlight) {
var $contents = $('.topic-body .contents', $post); var $contents = $('.topic-body .contents', $post);
var originalCol = $contents.css('backgroundColor'); var origColor = $contents.data('orig-color') || $contents.css('backgroundColor');
$contents.css({ backgroundColor: "#ffffcc" }).animate({ backgroundColor: originalCol }, 2500);
$contents.data("orig-color", origColor);
$contents
.css({ backgroundColor: "#ffffcc" })
.stop()
.animate({ backgroundColor: origColor }, 2500);
} }
} }
}); });

View File

@ -41,6 +41,7 @@ class SiteSetting < ActiveRecord::Base
client_setting(:min_search_term_length, 3) client_setting(:min_search_term_length, 3)
client_setting(:flush_timings_secs, 5) client_setting(:flush_timings_secs, 5)
client_setting(:suppress_reply_directly_below, true) client_setting(:suppress_reply_directly_below, true)
client_setting(:suppress_reply_directly_above, true)
client_setting(:email_domains_blacklist, 'mailinator.com') client_setting(:email_domains_blacklist, 'mailinator.com')
client_setting(:email_domains_whitelist) client_setting(:email_domains_whitelist)
client_setting(:version_checks, true) client_setting(:version_checks, true)

View File

@ -514,6 +514,8 @@ en:
system_username: "Username for the author of automated private messages sent by the forum" system_username: "Username for the author of automated private messages sent by the forum"
send_welcome_message: "Do new users get a welcome private message?" send_welcome_message: "Do new users get a welcome private message?"
suppress_reply_directly_below: "Don't show reply count on a post when there is a single reply directly below" suppress_reply_directly_below: "Don't show reply count on a post when there is a single reply directly below"
suppress_reply_directly_above: "Don't show in-reply-to on a post when there is a single reply directly above"
allow_index_in_robots_txt: "Site should be indexed by search engines (update robots.txt)" allow_index_in_robots_txt: "Site should be indexed by search engines (update robots.txt)"
email_domains_blacklist: "A pipe-delimited list of email domains that are not allowed. Example: mailinator.com|trashmail.net" email_domains_blacklist: "A pipe-delimited list of email domains that are not allowed. Example: mailinator.com|trashmail.net"
email_domains_whitelist: "A pipe-delimited list of email domains that users may register with. WARNING: Users with email domains other than those listed will not be allowed." email_domains_whitelist: "A pipe-delimited list of email domains that users may register with. WARNING: Users with email domains other than those listed will not be allowed."