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.attr('href', $link.data('href'));
$link.data('href', null);
return;
}, 50);
// 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 { 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',
topicBinding: 'controller.model',
userFiltersBinding: 'controller.userFilters',
@ -24,7 +24,7 @@ var TopicView = Discourse.View.extend(AddCategoryClass, AddArchetypeClass, Disco
archetype: Em.computed.alias('topic.archetype'),
_composeChanged: function() {
var composerController = Discourse.get('router.composerController');
const composerController = Discourse.get('router.composerController');
composerController.clearState();
composerController.set('topic', this.get('topic'));
}.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
// in our view set up is firing this observer with the same value. This check
// prevents scrolled from being called twice.
var enteredAt = this.get('controller.enteredAt');
const enteredAt = this.get('controller.enteredAt');
if (enteredAt && (this.get('lastEnteredAt') !== enteredAt)) {
this.scrolled();
this.set('lastEnteredAt', enteredAt);
@ -43,17 +43,18 @@ var TopicView = Discourse.View.extend(AddCategoryClass, AddArchetypeClass, Disco
_inserted: function() {
this.bindScrolling({name: 'topic-view'});
var self = this;
$(window).on('resize.discourse-on-scroll', function() {
self.scrolled();
});
$(window).on('resize.discourse-on-scroll', () => this.scrolled());
this.$().on('mouseup.discourse-redirect', '.cooked a, a.track-link', function(e) {
var selection = window.getSelection && window.getSelection();
// 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; }
return ClickTrack.trackClick(e);
@ -100,9 +101,9 @@ var TopicView = Discourse.View.extend(AddCategoryClass, AddArchetypeClass, Disco
return;
}
var offset = window.pageYOffset || $('html').scrollTop();
const offset = window.pageYOffset || $('html').scrollTop();
if (!this.get('docAt')) {
var title = $('#topic-title');
const title = $('#topic-title');
if (title && title.length === 1) {
this.set('docAt', title.offset().top);
}
@ -110,8 +111,8 @@ var TopicView = Discourse.View.extend(AddCategoryClass, AddArchetypeClass, Disco
this.set("offset", offset);
var headerController = this.get('controller.controllers.header'),
topic = this.get('controller.model');
const headerController = this.get('controller.controllers.header'),
topic = this.get('controller.model');
if (this.get('docAt')) {
headerController.set('showExtraInfo', offset >= this.get('docAt') || topic.get('postStream.firstPostNotLoaded'));
} 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>";
}
var tracking = this.get('topicTrackingState'),
unreadTopics = tracking.countUnread(),
newTopics = tracking.countNew();
const tracking = this.get('topicTrackingState'),
unreadTopics = tracking.countUnread(),
newTopics = tracking.countNew();
if (newTopics + unreadTopics > 0) {
var hasBoth = unreadTopics > 0 && newTopics > 0;
const hasBoth = unreadTopics > 0 && newTopics > 0;
return I18n.messageFormat("topic.read_more_MF", {
"BOTH": hasBoth,
@ -155,8 +156,7 @@ var TopicView = Discourse.View.extend(AddCategoryClass, AddArchetypeClass, Disco
latestLink: opts.latestLink,
catLink: opts.catLink
});
}
else if (category) {
} else if (category) {
return I18n.t("topic.read_more_in_category", opts);
} else {
return I18n.t("topic.read_more", opts);
@ -165,8 +165,8 @@ var TopicView = Discourse.View.extend(AddCategoryClass, AddArchetypeClass, Disco
});
function highlight(postNumber) {
var $contents = $('#post_' + postNumber +' .topic-body'),
origColor = $contents.data('orig-color') || $contents.css('backgroundColor');
const $contents = $('#post_' + postNumber +' .topic-body'),
origColor = $contents.data('orig-color') || $contents.css('backgroundColor');
$contents.data("orig-color", origColor)
.addClass('highlighted')