Skip to content

Commit

Permalink
fix($location): right button click in firefox
Browse files Browse the repository at this point in the history
When user click right mouse button on links in firefox, browser goes to
link. See http://jsfiddle.net/kromxr/76fKM/12/

Closes angular#7984
  • Loading branch information
krom-xr authored and lgalfaso committed Jan 12, 2015
1 parent 5a60302 commit aa798f1
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ng/location.js
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,7 @@ function $LocationProvider() {
// TODO(vojta): rewrite link when opening in new tab/window (in legacy browser)
// currently we open nice url link and redirect then

if (!html5Mode.rewriteLinks || event.ctrlKey || event.metaKey || event.which == 2) return;
if (!html5Mode.rewriteLinks || event.ctrlKey || event.metaKey || event.which == 2 || event.button == 2) return;

var elm = jqLite(event.target);

Expand Down
34 changes: 34 additions & 0 deletions test/ng/locationSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1504,6 +1504,40 @@ describe('$location', function() {
);
});

it('should not rewrite when right click pressed', function() {
configureService({linkHref: '/a?b=c', html5Mode: true, supportHist: true});
inject(
initBrowser(),
initLocation(),
function($browser) {
var rightClick;
if (document.createEvent) {
rightClick = document.createEvent('MouseEvents');
rightClick.initMouseEvent('click', true, true, window, 1, 10, 10, 10, 10, false,
false, false, false, 2, null);

link.dispatchEvent(rightClick);
} else if (document.createEventObject) { // for IE
rightClick = document.createEventObject();
rightClick.type = 'click';
rightClick.cancelBubble = true;
rightClick.detail = 1;
rightClick.screenX = 10;
rightClick.screenY = 10;
rightClick.clientX = 10;
rightClick.clientY = 10;
rightClick.ctrlKey = false;
rightClick.altKey = false;
rightClick.shiftKey = false;
rightClick.metaKey = false;
rightClick.button = 2;
link.fireEvent('onclick', rightClick);
}
expectNoRewrite($browser);
}
);
});


it('should not mess up hash urls when clicking on links in hashbang mode', function() {
var base;
Expand Down

0 comments on commit aa798f1

Please sign in to comment.