Skip to content

Commit

Permalink
feat(uiSref): add target attribute behaviour
Browse files Browse the repository at this point in the history
Change the behaviour of ui-sref to match angular $location service,
ignoring any click event on an anchor with a 'target' attribute set.
  • Loading branch information
Rory Fitzpatrick committed Dec 17, 2013
1 parent c985f25 commit c12bf9a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/stateDirectives.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ function $StateRefDirective($state, $timeout) {

element.bind("click", function(e) {
var button = e.which || e.button;

if ((button === 0 || button == 1) && !e.ctrlKey && !e.metaKey && !e.shiftKey) {
if ((button === 0 || button == 1) && !e.ctrlKey && !e.metaKey && !e.shiftKey && !element.attr('target')) {
// HACK: This is to allow ng-clicks to be processed before the transition is initiated:
$timeout(function() {
scope.$apply(function() {
Expand Down
11 changes: 11 additions & 0 deletions test/stateDirectivesSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,17 @@ describe('uiStateRef', function() {
expect($state.current.name).toEqual('');
expect($stateParams).toEqual({ id: "5" });
}));

it('should not transition states when element has target specified', inject(function($state, $stateParams, $document, $q, $timeout) {
el.attr('target', '_blank');
expect($state.$current.name).toEqual('');

triggerClick(el);
$q.flush();

expect($state.current.name).toEqual('');
expect($stateParams).toEqual({ id: "5" });
}));
});

describe('forms', function() {
Expand Down

0 comments on commit c12bf9a

Please sign in to comment.