mirror of
https://github.com/discourse/discourse.git
synced 2025-02-16 08:15:00 +00:00
Do not call preventDefault on right and middle-click/Ctrl+click.
This should fix the middle click popup blocker issue on Firefox.
This commit is contained in:
parent
9eb3958374
commit
e798705aec
@ -17,21 +17,7 @@ Discourse.ClickTrack = {
|
|||||||
var $link = $(e.currentTarget);
|
var $link = $(e.currentTarget);
|
||||||
if ($link.hasClass('lightbox')) return true;
|
if ($link.hasClass('lightbox')) return true;
|
||||||
|
|
||||||
e.preventDefault();
|
var href = $link.attr('href') || $link.data('href'),
|
||||||
|
|
||||||
// We don't track clicks on quote back buttons
|
|
||||||
if ($link.hasClass('back') || $link.hasClass('quote-other-topic')) return true;
|
|
||||||
|
|
||||||
// Remove the href, put it as a data attribute
|
|
||||||
if (!$link.data('href')) {
|
|
||||||
$link.addClass('no-href');
|
|
||||||
$link.data('href', $link.attr('href'));
|
|
||||||
$link.attr('href', null);
|
|
||||||
// Don't route to this URL
|
|
||||||
$link.data('auto-route', true);
|
|
||||||
}
|
|
||||||
|
|
||||||
var href = $link.data('href'),
|
|
||||||
$article = $link.closest('article'),
|
$article = $link.closest('article'),
|
||||||
postId = $article.data('post-id'),
|
postId = $article.data('post-id'),
|
||||||
topicId = $('#topic').data('topic-id'),
|
topicId = $('#topic').data('topic-id'),
|
||||||
@ -83,8 +69,21 @@ Discourse.ClickTrack = {
|
|||||||
},
|
},
|
||||||
dataType: 'html'
|
dataType: 'html'
|
||||||
});
|
});
|
||||||
window.open(href, '_blank');
|
return true;
|
||||||
return false;
|
}
|
||||||
|
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
// We don't track clicks on quote back buttons
|
||||||
|
if ($link.hasClass('back') || $link.hasClass('quote-other-topic')) return true;
|
||||||
|
|
||||||
|
// Remove the href, put it as a data attribute
|
||||||
|
if (!$link.data('href')) {
|
||||||
|
$link.addClass('no-href');
|
||||||
|
$link.data('href', $link.attr('href'));
|
||||||
|
$link.attr('href', null);
|
||||||
|
// Don't route to this URL
|
||||||
|
$link.data('auto-route', true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we're on the same site, use the router and track via AJAX
|
// If we're on the same site, use the router and track via AJAX
|
||||||
|
@ -114,35 +114,39 @@ test("right clicks are tracked", function() {
|
|||||||
equal(fixture('a').first().attr('href'), "/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=42");
|
equal(fixture('a').first().attr('href'), "/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=42");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("preventDefault is not called for right clicks", function() {
|
||||||
|
var clickEvent = generateClickEventOn('a');
|
||||||
|
clickEvent.which = 3;
|
||||||
|
this.stub(clickEvent, "preventDefault");
|
||||||
|
ok(track(clickEvent));
|
||||||
|
ok(!clickEvent.preventDefault.calledOnce);
|
||||||
|
});
|
||||||
|
|
||||||
var expectToOpenInANewTab = function(clickEvent) {
|
var testOpenInANewTab = function(description, clickEventModifier) {
|
||||||
ok(!track(clickEvent));
|
test(description, function() {
|
||||||
ok(Discourse.ajax.calledOnce);
|
var clickEvent = generateClickEventOn('a');
|
||||||
ok(window.open.calledOnce);
|
clickEventModifier(clickEvent);
|
||||||
|
this.stub(clickEvent, "preventDefault");
|
||||||
|
ok(track(clickEvent));
|
||||||
|
ok(Discourse.ajax.calledOnce);
|
||||||
|
ok(!clickEvent.preventDefault.calledOnce);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
test("it opens in a new tab when pressing shift", function() {
|
testOpenInANewTab("it opens in a new tab when pressing shift", function(clickEvent) {
|
||||||
var clickEvent = generateClickEventOn('a');
|
|
||||||
clickEvent.shiftKey = true;
|
clickEvent.shiftKey = true;
|
||||||
expectToOpenInANewTab(clickEvent);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("it opens in a new tab when pressing meta", function() {
|
testOpenInANewTab("it opens in a new tab when pressing meta", function(clickEvent) {
|
||||||
var clickEvent = generateClickEventOn('a');
|
|
||||||
clickEvent.metaKey = true;
|
clickEvent.metaKey = true;
|
||||||
expectToOpenInANewTab(clickEvent);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("it opens in a new tab when pressing meta", function() {
|
testOpenInANewTab("it opens in a new tab when pressing ctrl", function(clickEvent) {
|
||||||
var clickEvent = generateClickEventOn('a');
|
|
||||||
clickEvent.ctrlKey = true;
|
clickEvent.ctrlKey = true;
|
||||||
expectToOpenInANewTab(clickEvent);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("it opens in a new tab when pressing meta", function() {
|
testOpenInANewTab("it opens in a new tab on middle click", function(clickEvent) {
|
||||||
var clickEvent = generateClickEventOn('a');
|
|
||||||
clickEvent.which = 2;
|
clickEvent.which = 2;
|
||||||
expectToOpenInANewTab(clickEvent);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("tracks via AJAX if we're on the same site", function() {
|
test("tracks via AJAX if we're on the same site", function() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user