FIX: Erratic behaviour when clicking an attachment link - Take 2

This commit is contained in:
Régis Hanol 2015-04-28 20:05:41 +02:00
parent 2cbcd15789
commit 5783e908ea
2 changed files with 22 additions and 23 deletions

View File

@ -78,7 +78,6 @@ export default {
$link.removeClass('no-href'); $link.removeClass('no-href');
$link.attr('href', $link.data('href')); $link.attr('href', $link.data('href'));
$link.data('href', null); $link.data('href', null);
return;
}, 50); }, 50);
// warn the user if they can't download the file // warn the user if they can't download the file

View File

@ -4,7 +4,7 @@ import ClickTrack from 'discourse/lib/click-track';
import { listenForViewEvent } from 'discourse/lib/app-events'; import { listenForViewEvent } from 'discourse/lib/app-events';
import { categoryBadgeHTML } from 'discourse/helpers/category-link'; import { categoryBadgeHTML } from 'discourse/helpers/category-link';
var TopicView = Discourse.View.extend(AddCategoryClass, AddArchetypeClass, Discourse.Scrolling, { const TopicView = Discourse.View.extend(AddCategoryClass, AddArchetypeClass, Discourse.Scrolling, {
templateName: 'topic', templateName: 'topic',
topicBinding: 'controller.model', topicBinding: 'controller.model',
userFiltersBinding: 'controller.userFilters', userFiltersBinding: 'controller.userFilters',
@ -24,7 +24,7 @@ var TopicView = Discourse.View.extend(AddCategoryClass, AddArchetypeClass, Disco
archetype: Em.computed.alias('topic.archetype'), archetype: Em.computed.alias('topic.archetype'),
_composeChanged: function() { _composeChanged: function() {
var composerController = Discourse.get('router.composerController'); const composerController = Discourse.get('router.composerController');
composerController.clearState(); composerController.clearState();
composerController.set('topic', this.get('topic')); composerController.set('topic', this.get('topic'));
}.observes('composer'), }.observes('composer'),
@ -33,7 +33,7 @@ var TopicView = Discourse.View.extend(AddCategoryClass, AddArchetypeClass, Disco
// Ember is supposed to only call observers when values change but something // Ember is supposed to only call observers when values change but something
// in our view set up is firing this observer with the same value. This check // in our view set up is firing this observer with the same value. This check
// prevents scrolled from being called twice. // prevents scrolled from being called twice.
var enteredAt = this.get('controller.enteredAt'); const enteredAt = this.get('controller.enteredAt');
if (enteredAt && (this.get('lastEnteredAt') !== enteredAt)) { if (enteredAt && (this.get('lastEnteredAt') !== enteredAt)) {
this.scrolled(); this.scrolled();
this.set('lastEnteredAt', enteredAt); this.set('lastEnteredAt', enteredAt);
@ -43,17 +43,18 @@ var TopicView = Discourse.View.extend(AddCategoryClass, AddArchetypeClass, Disco
_inserted: function() { _inserted: function() {
this.bindScrolling({name: 'topic-view'}); this.bindScrolling({name: 'topic-view'});
var self = this; $(window).on('resize.discourse-on-scroll', () => this.scrolled());
$(window).on('resize.discourse-on-scroll', function() {
self.scrolled();
});
this.$().on('mouseup.discourse-redirect', '.cooked a, a.track-link', function(e) { this.$().on('mouseup.discourse-redirect', '.cooked a, a.track-link', function(e) {
var selection = window.getSelection && window.getSelection();
// bypass if we are selecting stuff // bypass if we are selecting stuff
if (selection.type === "Range" || selection.rangeCount > 0) { return true; } const selection = window.getSelection && window.getSelection();
if (selection.type === "Range" || selection.rangeCount > 0) {
if (Discourse.Utilities.selectedText() !== "") {
return true;
}
}
var $target = $(e.target); const $target = $(e.target);
if ($target.hasClass('mention') || $target.parents('.expanded-embed').length) { return false; } if ($target.hasClass('mention') || $target.parents('.expanded-embed').length) { return false; }
return ClickTrack.trackClick(e); return ClickTrack.trackClick(e);
@ -100,9 +101,9 @@ var TopicView = Discourse.View.extend(AddCategoryClass, AddArchetypeClass, Disco
return; return;
} }
var offset = window.pageYOffset || $('html').scrollTop(); const offset = window.pageYOffset || $('html').scrollTop();
if (!this.get('docAt')) { if (!this.get('docAt')) {
var title = $('#topic-title'); const title = $('#topic-title');
if (title && title.length === 1) { if (title && title.length === 1) {
this.set('docAt', title.offset().top); this.set('docAt', title.offset().top);
} }
@ -110,8 +111,8 @@ var TopicView = Discourse.View.extend(AddCategoryClass, AddArchetypeClass, Disco
this.set("offset", offset); this.set("offset", offset);
var headerController = this.get('controller.controllers.header'), const headerController = this.get('controller.controllers.header'),
topic = this.get('controller.model'); topic = this.get('controller.model');
if (this.get('docAt')) { if (this.get('docAt')) {
headerController.set('showExtraInfo', offset >= this.get('docAt') || topic.get('postStream.firstPostNotLoaded')); headerController.set('showExtraInfo', offset >= this.get('docAt') || topic.get('postStream.firstPostNotLoaded'));
} else { } else {
@ -140,12 +141,12 @@ var TopicView = Discourse.View.extend(AddCategoryClass, AddArchetypeClass, Disco
opts.catLink = "<a href=\"" + Discourse.getURL("/categories") + "\">" + I18n.t("topic.browse_all_categories") + "</a>"; opts.catLink = "<a href=\"" + Discourse.getURL("/categories") + "\">" + I18n.t("topic.browse_all_categories") + "</a>";
} }
var tracking = this.get('topicTrackingState'), const tracking = this.get('topicTrackingState'),
unreadTopics = tracking.countUnread(), unreadTopics = tracking.countUnread(),
newTopics = tracking.countNew(); newTopics = tracking.countNew();
if (newTopics + unreadTopics > 0) { if (newTopics + unreadTopics > 0) {
var hasBoth = unreadTopics > 0 && newTopics > 0; const hasBoth = unreadTopics > 0 && newTopics > 0;
return I18n.messageFormat("topic.read_more_MF", { return I18n.messageFormat("topic.read_more_MF", {
"BOTH": hasBoth, "BOTH": hasBoth,
@ -155,8 +156,7 @@ var TopicView = Discourse.View.extend(AddCategoryClass, AddArchetypeClass, Disco
latestLink: opts.latestLink, latestLink: opts.latestLink,
catLink: opts.catLink catLink: opts.catLink
}); });
} } else if (category) {
else if (category) {
return I18n.t("topic.read_more_in_category", opts); return I18n.t("topic.read_more_in_category", opts);
} else { } else {
return I18n.t("topic.read_more", opts); return I18n.t("topic.read_more", opts);
@ -165,8 +165,8 @@ var TopicView = Discourse.View.extend(AddCategoryClass, AddArchetypeClass, Disco
}); });
function highlight(postNumber) { function highlight(postNumber) {
var $contents = $('#post_' + postNumber +' .topic-body'), const $contents = $('#post_' + postNumber +' .topic-body'),
origColor = $contents.data('orig-color') || $contents.css('backgroundColor'); origColor = $contents.data('orig-color') || $contents.css('backgroundColor');
$contents.data("orig-color", origColor) $contents.data("orig-color", origColor)
.addClass('highlighted') .addClass('highlighted')