Skip to content

Commit

Permalink
fix(tap): allow document to be tap polyfilled
Browse files Browse the repository at this point in the history
Closes #9726
  • Loading branch information
adamdbradley committed Jan 13, 2017
1 parent d252fa4 commit 9168bc1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/tap-click/tap-click.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ export class TapClick {
this.lastTouchEnd = 0;
this.dispatchClick = true;

if (this.plt.doc() === ev.target) {
this.startCoord = pointerCoord(ev);
return true;
}

let activatableEle = getActivatableTarget(ev.target);
if (!activatableEle) {
this.startCoord = null;
Expand All @@ -97,7 +102,7 @@ export class TapClick {
if (!this.startCoord) {
return;
}
if (this.activator) {
if (this.activator && ev.target !== this.plt.doc()) {
let activatableEle = getActivatableTarget(ev.target);
if (activatableEle) {
this.activator.upAction(ev, activatableEle, this.startCoord);
Expand Down Expand Up @@ -133,7 +138,7 @@ export class TapClick {
return;
}

if (this.activator) {
if (this.activator && this.plt.doc() !== ev.target) {
// cool, a click is gonna happen, let's tell the activator
// so the element can get the given "active" style
const activatableEle = getActivatableTarget(ev.target);
Expand Down Expand Up @@ -235,7 +240,7 @@ export const isActivatable = function (ele: HTMLElement) {
}

for (let i = 0, l = ACTIVATABLE_ATTRIBUTES.length; i < l; i++) {
if (ele.hasAttribute(ACTIVATABLE_ATTRIBUTES[i])) {
if (ele.hasAttribute && ele.hasAttribute(ACTIVATABLE_ATTRIBUTES[i])) {
return true;
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/tap-click/test/tap-click.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ describe('TapClick', () => {
expect( isActivatable(ele) ).toBe(true);
});

it('should be not activatable on element without "hasAttribute" function', () => {
let doc = document.createDocumentFragment();
expect( isActivatable(<any>doc) ).toBe(false);
});

});

});

0 comments on commit 9168bc1

Please sign in to comment.