Fix the links in table rows bug

Click events were greedily redirecting to the resource pages instead
of first yielding to the anchor tag clicked if an anchor tag was in
fact clicked.
This commit is contained in:
Michael Lange 2017-09-26 11:57:46 -07:00
parent 819fceeac5
commit 491f4ff27d
6 changed files with 30 additions and 5 deletions

View file

@ -1,4 +1,5 @@
import Ember from 'ember'; import Ember from 'ember';
import { lazyClick } from '../helpers/lazy-click';
const { Component } = Ember; const { Component } = Ember;
@ -15,6 +16,6 @@ export default Component.extend({
onClick() {}, onClick() {},
click(event) { click(event) {
this.get('onClick')(event); lazyClick([this.get('onClick'), event]);
}, },
}); });

View file

@ -1,4 +1,5 @@
import Ember from 'ember'; import Ember from 'ember';
import { lazyClick } from '../helpers/lazy-click';
const { Component } = Ember; const { Component } = Ember;
@ -11,7 +12,7 @@ export default Component.extend({
onClick() {}, onClick() {},
click(event) { click(event) {
this.get('onClick')(event); lazyClick([this.get('onClick'), event]);
}, },
didReceiveAttrs() { didReceiveAttrs() {

View file

@ -1,4 +1,5 @@
import Ember from 'ember'; import Ember from 'ember';
import { lazyClick } from '../helpers/lazy-click';
const { Component } = Ember; const { Component } = Ember;
@ -11,7 +12,7 @@ export default Component.extend({
onClick() {}, onClick() {},
click(event) { click(event) {
this.get('onClick')(event); lazyClick([this.get('onClick'), event]);
}, },
didReceiveAttrs() { didReceiveAttrs() {

View file

@ -1,4 +1,5 @@
import Ember from 'ember'; import Ember from 'ember';
import { lazyClick } from '../helpers/lazy-click';
const { Component, inject, computed } = Ember; const { Component, inject, computed } = Ember;
@ -28,6 +29,7 @@ export default Component.extend({
}), }),
click() { click() {
this.get('router').transitionTo('servers.server', this.get('agent')); const transition = () => this.get('router').transitionTo('servers.server', this.get('agent'));
lazyClick([transition, event]);
}, },
}); });

View file

@ -1,4 +1,5 @@
import Ember from 'ember'; import Ember from 'ember';
import { lazyClick } from '../helpers/lazy-click';
const { Component } = Ember; const { Component } = Ember;
@ -12,6 +13,6 @@ export default Component.extend({
onClick() {}, onClick() {},
click(event) { click(event) {
this.get('onClick')(event); lazyClick([this.get('onClick'), event]);
}, },
}); });

View file

@ -0,0 +1,19 @@
import Ember from 'ember';
const { Helper, $ } = Ember;
/**
* Lazy Click Event
*
* Usage: {{lazy-click action}}
*
* Calls the provided action only if the target isn't an anchor
* that should be handled instead.
*/
export function lazyClick([onClick, event]) {
if (!$(event.target).is('a')) {
onClick(event);
}
}
export default Helper.helper(lazyClick);