Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

Commit

Permalink
fix(ripple): remove array.find() and enhance foundation code
Browse files Browse the repository at this point in the history
- IE11 doesn't support array.prototype.find() so manually code loop
- no need to override existing activation - just allow touch to re-activate

Fixes #1328
  • Loading branch information
Spetnik committed Oct 23, 2017
1 parent 967a524 commit 5aa2b6b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
14 changes: 6 additions & 8 deletions packages/mdc-ripple/foundation.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,14 +243,12 @@ class MDCRippleFoundation extends MDCFoundation {
}

const {activationState_: activationState} = this;
if (activationState.isActivated) {
// Even when using touch, the effect can be activated by a
// 'mousedown'. But if the finger slides off, then there is
// no 'mouseup'. So we overwrite the event with 'touchstart',
// ifand when one occurs.
if (e.type === 'touchstart' && e.type !== activationState.activationEvent.type) {
activationState.activationEvent = e;
}
// We don't want to re-activate the ripple if it is already active -
// UNLESS there is a touch event - because even though 'mousedown' or 'pointerdown' will
// fire on a touch event, 'mouseup' or 'pointerup' will not fire if the finger moves off of the element
// before being removed, so we need the 'touchend' to be able to deactivate the
// state triggered by 'touchstart'.
if (activationState.isActivated && !(e.type === 'touchstart' && e.type !== activationState.activationEvent.type)) {
return;
}

Expand Down
18 changes: 10 additions & 8 deletions packages/mdc-ripple/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,26 +67,28 @@ class MDCRipple extends MDCComponent {
registerInteractionHandler: (evtType, handler) => {
// If this is an 'up event' (the event name exists in the UP_EVENTS array),
// add the listener at the window level. Otherwise, add it to the element.
if (!UP_EVENTS.find( (type) => {
// NOTE: IE11 precludes us from using Array.prototype.find
for (let i = 0, type; (type = UP_EVENTS[i]); i ++) {
if ( type === evtType) {
window.addEventListener(evtType, handler, util.applyPassive());
return true;
return;
}
})) {
instance.root_.addEventListener(evtType, handler, util.applyPassive());
}

instance.root_.addEventListener(evtType, handler, util.applyPassive());
},
deregisterInteractionHandler: (evtType, handler) => {
// If this is an 'up event' (the event name exists in the UP_EVENTS array),
// remove the listener from the window level. Otherwise, remove it from the element.
if (!UP_EVENTS.find( (type) => {
// NOTE: IE11 precludes us from using Array.prototype.find
for (let i = 0, type; (type = UP_EVENTS[i]); i ++) {
if ( type === evtType) {
window.removeEventListener(evtType, handler, util.applyPassive());
return true;
return;
}
})) {
instance.root_.removeEventListener(evtType, handler, util.applyPassive());
}

instance.root_.removeEventListener(evtType, handler, util.applyPassive());
},
registerResizeHandler: (handler) => window.addEventListener('resize', handler),
deregisterResizeHandler: (handler) => window.removeEventListener('resize', handler),
Expand Down

0 comments on commit 5aa2b6b

Please sign in to comment.