Skip to content

Commit

Permalink
Merge pull request #767 from angular-ui/sref-mock-click
Browse files Browse the repository at this point in the history
refactor(ui-sref): support mock-clicks/events with no data
  • Loading branch information
nateabele committed Jan 16, 2014
2 parents aa03555 + 717d3ff commit e3f3522
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/stateDirectives.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +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 && !element.attr('target')) {
if ( !(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() {
$state.go(ref.state, params, { relative: base });
Expand Down
19 changes: 18 additions & 1 deletion test/stateDirectivesSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,23 @@ describe('uiStateRef', function() {
expect($stateParams).toEqual({ id: "5" });
}));

it('should transition when given a click that contains no data (fake-click)', inject(function($state, $stateParams, $document, $q, $timeout) {
expect($state.current.name).toEqual('');

triggerClick(el, {
metaKey: undefined,
ctrlKey: undefined,
shiftKey: undefined,
altKey: undefined,
button: undefined
});
$timeout.flush();
$q.flush();

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

it('should not transition states when ctrl-clicked', inject(function($state, $stateParams, $document, $q) {
expect($state.$current.name).toEqual('');
triggerClick(el, { ctrlKey: true });
Expand Down Expand Up @@ -316,4 +333,4 @@ describe('uiSrefActive', function() {
$q.flush();
expect(angular.element(template[0].querySelector('a')).attr('class')).toBe('ng-scope');
}));
});
});

0 comments on commit e3f3522

Please sign in to comment.