Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make ripple touch events passive #964

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion addon/components/paper-tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { getOwner } from '@ember/application';
import layout from '../templates/components/paper-tooltip';
import $ from 'jquery';
import getParent from 'ember-paper/utils/get-parent';
import { supportsPassiveEventListeners } from 'ember-paper/utils/browser-features';

export default Component.extend({
tagName: '',
Expand Down Expand Up @@ -93,8 +94,10 @@ export default Component.extend({
};

anchorElement.addEventListener('focus', enterEventHandler);
anchorElement.addEventListener('touchstart', enterEventHandler);
anchorElement.addEventListener('mouseenter', enterEventHandler);
anchorElement.addEventListener('touchstart',
enterEventHandler,
supportsPassiveEventListeners ? { passive: true } : false);

window.addEventListener('scroll', leaveHandler);
window.addEventListener('blur', leaveHandler);
Expand Down
16 changes: 12 additions & 4 deletions addon/mixins/ripple-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ import { computed } from '@ember/object';
import Mixin from '@ember/object/mixin';
import { run } from '@ember/runloop';
import $ from 'jquery';
import { supportsPassiveEventListeners } from 'ember-paper/utils/browser-features';

/* global window */

const DURATION = 400;


/**
* @class RippleMixin
* @extends Ember.Mixin
Expand Down Expand Up @@ -129,11 +132,16 @@ export default Mixin.create({

},
bindEvents() {
this.rippleElement.on('mousedown', run.bind(this, this.handleMousedown));
this.rippleElement.on('mouseup touchend', run.bind(this, this.handleMouseup));
this.rippleElement.on('mouseleave', run.bind(this, this.handleMouseup));
this.rippleElement.on('touchmove', run.bind(this, this.handleTouchmove));
let re = this.rippleElement.get(0);
re.addEventListener('mousedown', run.bind(this, this.handleMousedown));
re.addEventListener('mouseup', run.bind(this, this.handleMouseup));
re.addEventListener('mouseleave', run.bind(this, this.handleMouseup));

let options = supportsPassiveEventListeners ? { passive: true } : false;
re.addEventListener('touchend', run.bind(this, this.handleMouseup), options);
re.addEventListener('touchmove', run.bind(this, this.handleTouchmove), options);
},

handleMousedown(event) {
if (this.mousedown) {
return;
Expand Down
14 changes: 14 additions & 0 deletions addon/utils/browser-features.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Taken from https://github.com/Modernizr/Modernizr/blob/master/feature-detects/dom/passiveeventlisteners.js
export const supportsPassiveEventListeners = (function() {
let supportsPassiveOption = false;
try {
const opts = Object.defineProperty({}, 'passive', {
get: function() {
supportsPassiveOption = true;
}
});
window.addEventListener('test', null, opts);
// eslint-disable-next-line
} catch (e) {};
return supportsPassiveOption;
})();