Skip to content

Commit

Permalink
Make touch* event handlers explicitly passive: false in renderer #…
Browse files Browse the repository at this point in the history
…1702

- Test for passive event / options object for `addEventListener()` support
- Supported browsers have all options set explicitly in the object
- Unsupported browsers just use the `useCapture` boolean
  • Loading branch information
maxkfranz committed Feb 1, 2017
1 parent 4f06ba3 commit 84b4505
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions src/extensions/renderer/base/load-listeners.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,35 @@ BRp.registerBinding = function( target, event, handler, useCapture ){
BRp.binder = function( tgt ){
var r = this;

var on = function(){
var args = arguments;
var tgtIsDom = tgt === window || tgt === document || tgt === document.body || is.domElement( tgt );

if( r.supportsPassiveEvents == null ){

// from https://github.com/WICG/EventListenerOptions/blob/gh-pages/explainer.md#feature-detection
var supportsPassive = false;
try {
var opts = Object.defineProperty( {}, 'passive', {
get: function(){
supportsPassive = true;
}
} );

window.addEventListener( 'test', null, opts );
} catch( err ){}

r.supportsPassiveEvents = supportsPassive;
}

var on = function( event, handler, useCapture ){
var args = Array.prototype.slice.call( arguments );

if( tgtIsDom && r.supportsPassiveEvents ){ // replace useCapture w/ opts obj
args[2] = {
capture: useCapture != null ? useCapture : false,
passive: false,
once: false
};
}

r.bindings.push({
target: tgt,
Expand Down

0 comments on commit 84b4505

Please sign in to comment.