From 7b70330e85ede3a97ccf2071af5134d7003a63f9 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Wed, 5 Jun 2013 20:53:09 -0400 Subject: [PATCH] FIX: Javascript errors when navigating to some topics --- .../discourse/templates/topic.js.handlebars | 2 +- .../javascripts/discourse/views/topic_view.js | 21 +++++++++++++------ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/app/assets/javascripts/discourse/templates/topic.js.handlebars b/app/assets/javascripts/discourse/templates/topic.js.handlebars index ff179c83f..1a09bc300 100644 --- a/app/assets/javascripts/discourse/templates/topic.js.handlebars +++ b/app/assets/javascripts/discourse/templates/topic.js.handlebars @@ -27,7 +27,7 @@ {{i18n topic.loading}} {{/if}} {{/if}} - {{boundCategoryLink category}} + {{categoryLink category}} {{#if view.topic.can_edit}} diff --git a/app/assets/javascripts/discourse/views/topic_view.js b/app/assets/javascripts/discourse/views/topic_view.js index dc29b84ac..9e9778484 100644 --- a/app/assets/javascripts/discourse/views/topic_view.js +++ b/app/assets/javascripts/discourse/views/topic_view.js @@ -175,7 +175,6 @@ Discourse.TopicView = Discourse.View.extend(Discourse.Scrolling, { // Triggered whenever any posts are rendered, debounced to save over calling postsRendered: Discourse.debounce(function() { - this.set('renderedPosts', $('.topic-post')); this.updatePosition(false); }, 50), @@ -421,7 +420,7 @@ Discourse.TopicView = Discourse.View.extend(Discourse.Scrolling, { title, info, rows, screenTrack, _this, currentPost; _this = this; - rows = this.get('renderedPosts'); + rows = $('.topic-post'); if (!rows || rows.length === 0) { return; } info = Discourse.Eyeline.analyze(rows); @@ -449,10 +448,20 @@ Discourse.TopicView = Discourse.View.extend(Discourse.Scrolling, { currentPost = currentPost || seen; }); - this.nonUrgentPositionUpdate({ - userActive: userActive, - currentPost: currentPost || this.getPost($(rows[info.bottom])).get('post_number') - }); + var currentForPositionUpdate = currentPost; + if (!currentForPositionUpdate) { + var postView = this.getPost($(rows[info.bottom])); + if (postView) { currentForPositionUpdate = postView.get('post_number'); } + } + + if (currentForPositionUpdate) { + this.nonUrgentPositionUpdate({ + userActive: userActive, + currentPost: currentPost || currentForPositionUpdate + }); + } else { + console.error("can't update position "); + } offset = window.pageYOffset || $('html').scrollTop(); firstLoaded = this.get('firstPostLoaded');