mirror of
https://github.com/discourse/discourse.git
synced 2025-05-24 03:36:18 +08:00
FIX: shift+click on links
Default browser's behavior when shift+clicking was messed up. This adds the shift key modifier to the list of click modifiers in both `click_track` and `discourse`. Also updated & refactored a bit the `click_track_spec`.
This commit is contained in:
@ -129,7 +129,7 @@ Discourse = Ember.Application.createWithMixins({
|
|||||||
});
|
});
|
||||||
|
|
||||||
$('#main').on('click.discourse', 'a', function(e) {
|
$('#main').on('click.discourse', 'a', function(e) {
|
||||||
if (e.isDefaultPrevented() || e.metaKey || e.ctrlKey) return;
|
if (e.isDefaultPrevented() || e.shiftKey || e.metaKey || e.ctrlKey) return;
|
||||||
|
|
||||||
var $currentTarget = $(e.currentTarget);
|
var $currentTarget = $(e.currentTarget);
|
||||||
var href = $currentTarget.attr('href');
|
var href = $currentTarget.attr('href');
|
||||||
|
@ -68,7 +68,7 @@ Discourse.ClickTrack = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// if they want to open in a new tab, do an AJAX request
|
// if they want to open in a new tab, do an AJAX request
|
||||||
if (e.metaKey || e.ctrlKey || e.which === 2) {
|
if (e.shiftKey || e.metaKey || e.ctrlKey || e.which === 2) {
|
||||||
Discourse.ajax(Discourse.getURL("/clicks/track"), {
|
Discourse.ajax(Discourse.getURL("/clicks/track"), {
|
||||||
data: {
|
data: {
|
||||||
url: href,
|
url: href,
|
||||||
|
@ -152,25 +152,30 @@ describe("Discourse.ClickTrack", function() {
|
|||||||
spyOn(window, 'open');
|
spyOn(window, 'open');
|
||||||
});
|
});
|
||||||
|
|
||||||
it("opens in a new tab when pressing alt", function() {
|
var expectItOpensInANewTab = function() {
|
||||||
clickEvent.metaKey = true;
|
|
||||||
expect(track(clickEvent)).toBe(false);
|
expect(track(clickEvent)).toBe(false);
|
||||||
expect(Discourse.ajax).toHaveBeenCalled();
|
expect(Discourse.ajax).toHaveBeenCalled();
|
||||||
expect(window.open).toHaveBeenCalledWith('http://www.google.com', '_blank');
|
expect(window.open).toHaveBeenCalledWith('http://www.google.com', '_blank');
|
||||||
|
};
|
||||||
|
|
||||||
|
it("opens in a new tab when pressing shift", function() {
|
||||||
|
clickEvent.shiftKey = true;
|
||||||
|
expectItOpensInANewTab();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("opens in a new tab when pressing meta", function() {
|
||||||
|
clickEvent.metaKey = true;
|
||||||
|
expectItOpensInANewTab();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("opens in a new tab when pressing ctrl", function() {
|
it("opens in a new tab when pressing ctrl", function() {
|
||||||
clickEvent.ctrlKey = true;
|
clickEvent.ctrlKey = true;
|
||||||
expect(track(clickEvent)).toBe(false);
|
expectItOpensInANewTab();
|
||||||
expect(Discourse.ajax).toHaveBeenCalled();
|
|
||||||
expect(window.open).toHaveBeenCalledWith('http://www.google.com', '_blank');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("opens in a new tab when middle clicking", function() {
|
it("opens in a new tab when middle clicking", function() {
|
||||||
clickEvent.which = 2;
|
clickEvent.which = 2;
|
||||||
expect(track(clickEvent)).toBe(false);
|
expectItOpensInANewTab();
|
||||||
expect(Discourse.ajax).toHaveBeenCalled();
|
|
||||||
expect(window.open).toHaveBeenCalledWith('http://www.google.com', '_blank');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user