mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 22:43:33 +08:00
FIX: youtube preview video title link doesn't work
This commit is contained in:
@ -1,23 +1,10 @@
|
|||||||
/**
|
export default {
|
||||||
Used for tracking when the user clicks on a link
|
trackClick(e) {
|
||||||
|
// cancel click if triggered as part of selection.
|
||||||
|
if (Discourse.Utilities.selectedText() !== "") { return false; }
|
||||||
|
|
||||||
@class ClickTrack
|
|
||||||
@namespace Discourse
|
|
||||||
@module Discourse
|
|
||||||
**/
|
|
||||||
|
|
||||||
Discourse.ClickTrack = {
|
|
||||||
|
|
||||||
/**
|
|
||||||
Track a click on a link
|
|
||||||
|
|
||||||
@method trackClick
|
|
||||||
@param {jQuery.Event} e The click event that occurred
|
|
||||||
**/
|
|
||||||
trackClick: function(e) {
|
|
||||||
if (Discourse.Utilities.selectedText()!=="") return false; //cancle click if triggered as part of selection.
|
|
||||||
var $link = $(e.currentTarget);
|
var $link = $(e.currentTarget);
|
||||||
if ($link.hasClass('lightbox')) return true;
|
if ($link.hasClass('lightbox')) { return true; }
|
||||||
|
|
||||||
var href = $link.attr('href') || $link.data('href'),
|
var href = $link.attr('href') || $link.data('href'),
|
||||||
$article = $link.closest('article'),
|
$article = $link.closest('article'),
|
||||||
@ -25,9 +12,7 @@ Discourse.ClickTrack = {
|
|||||||
topicId = $('#topic').data('topic-id'),
|
topicId = $('#topic').data('topic-id'),
|
||||||
userId = $link.data('user-id');
|
userId = $link.data('user-id');
|
||||||
|
|
||||||
if (!href || href.trim().length === 0){
|
if (!href || href.trim().length === 0) { return; }
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!userId) userId = $article.data('user-id');
|
if (!userId) userId = $article.data('user-id');
|
||||||
|
|
@ -1,5 +1,6 @@
|
|||||||
import AddCategoryClass from 'discourse/mixins/add-category-class';
|
import AddCategoryClass from 'discourse/mixins/add-category-class';
|
||||||
import AddArchetypeClass from 'discourse/mixins/add-archetype-class';
|
import AddArchetypeClass from 'discourse/mixins/add-archetype-class';
|
||||||
|
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';
|
||||||
|
|
||||||
@ -55,7 +56,7 @@ var TopicView = Discourse.View.extend(AddCategoryClass, AddArchetypeClass, Disco
|
|||||||
var $target = $(e.target);
|
var $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 Discourse.ClickTrack.trackClick(e);
|
return ClickTrack.trackClick(e);
|
||||||
});
|
});
|
||||||
|
|
||||||
}.on('didInsertElement'),
|
}.on('didInsertElement'),
|
||||||
|
@ -52,7 +52,7 @@ class TopicLinkClick < ActiveRecord::Base
|
|||||||
# If we have it somewhere else on the site, just allow the redirect.
|
# If we have it somewhere else on the site, just allow the redirect.
|
||||||
# This is likely due to a onebox of another topic.
|
# This is likely due to a onebox of another topic.
|
||||||
link = TopicLink.find_by(url: url)
|
link = TopicLink.find_by(url: url)
|
||||||
return link.present? ? link.url : nil
|
return link.present? ? link.url : url
|
||||||
end
|
end
|
||||||
|
|
||||||
return url if args[:user_id] && link.user_id == args[:user_id]
|
return url if args[:user_id] && link.user_id == args[:user_id]
|
||||||
|
@ -8,7 +8,7 @@ describe DirectoryItem do
|
|||||||
DirectoryItem.refresh!
|
DirectoryItem.refresh!
|
||||||
expect(DirectoryItem.where(period_type: DirectoryItem.period_types[:all])
|
expect(DirectoryItem.where(period_type: DirectoryItem.period_types[:all])
|
||||||
.where(user_id: post.user.id)
|
.where(user_id: post.user.id)
|
||||||
.exists?).to be_true
|
.exists?).to be_truthy
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -47,8 +47,8 @@ describe TopicLinkClick do
|
|||||||
context 'without a url' do
|
context 'without a url' do
|
||||||
let(:click) { TopicLinkClick.create_from(url: "url that doesn't exist", post_id: @post.id, ip: '127.0.0.1') }
|
let(:click) { TopicLinkClick.create_from(url: "url that doesn't exist", post_id: @post.id, ip: '127.0.0.1') }
|
||||||
|
|
||||||
it "returns nil" do
|
it "returns the url" do
|
||||||
expect(click).to eq(nil)
|
expect(click).to eq("url that doesn't exist")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
|
import ClickTrack from "discourse/lib/click-track";
|
||||||
|
|
||||||
var windowOpen,
|
var windowOpen,
|
||||||
win,
|
win,
|
||||||
redirectTo;
|
redirectTo;
|
||||||
|
|
||||||
module("Discourse.ClickTrack", {
|
module("ClickTrack", {
|
||||||
setup: function() {
|
setup: function() {
|
||||||
|
|
||||||
// Prevent any of these tests from navigating away
|
// Prevent any of these tests from navigating away
|
||||||
@ -30,7 +32,7 @@ module("Discourse.ClickTrack", {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var track = Discourse.ClickTrack.trackClick;
|
var track = ClickTrack.trackClick;
|
||||||
|
|
||||||
// test
|
// test
|
||||||
var generateClickEventOn = function(selector) {
|
var generateClickEventOn = function(selector) {
|
||||||
|
Reference in New Issue
Block a user