fix(tap): allow document to be tap polyfilled

Closes #9726
This commit is contained in:
Adam Bradley
2017-01-13 17:09:13 -06:00
parent d252fa49e5
commit 9168bc137b
2 changed files with 13 additions and 3 deletions

View File

@ -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;
@ -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);
@ -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);
@ -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;
}
}

View File

@ -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);
});
});
});