|
43 | 43 | var toString = Object.prototype.toString;
|
44 | 44 | var isTouchAvailable = 'ontouchstart' in window;
|
45 | 45 |
|
| 46 | + /* Feature detection */ |
| 47 | + var passiveIfSupported = false; |
| 48 | + try { |
| 49 | + window.addEventListener("test", null, |
| 50 | + Object.defineProperty({}, "passive", { |
| 51 | + get: function() { passiveIfSupported = { passive: false }; } |
| 52 | + } |
| 53 | + )); |
| 54 | + } catch(err) {} |
46 | 55 |
|
47 | 56 | // Find exact position of element
|
48 | 57 | function isWindow(obj) {
|
|
446 | 455 | removeListeners();
|
447 | 456 | };
|
448 | 457 |
|
449 |
| - element.addEventListener('touchmove', touchMove, { capture:false, passive: true }); |
450 |
| - element.addEventListener('touchend', hideEffect, { capture:false, passive: true }); |
451 |
| - element.addEventListener('touchcancel', hideEffect, { capture:false, passive: true }); |
| 458 | + element.addEventListener('touchmove', touchMove, passiveIfSupported); |
| 459 | + element.addEventListener('touchend', hideEffect, passiveIfSupported); |
| 460 | + element.addEventListener('touchcancel', hideEffect, passiveIfSupported); |
452 | 461 |
|
453 | 462 | var removeListeners = function() {
|
454 | 463 | element.removeEventListener('touchmove', touchMove);
|
|
460 | 469 | Effect.show(e, element);
|
461 | 470 |
|
462 | 471 | if (isTouchAvailable) {
|
463 |
| - element.addEventListener('touchend', Effect.hide, { capture:false, passive: true }); |
464 |
| - element.addEventListener('touchcancel', Effect.hide, { capture:false, passive: true }); |
| 472 | + element.addEventListener('touchend', Effect.hide, passiveIfSupported); |
| 473 | + element.addEventListener('touchcancel', Effect.hide, passiveIfSupported); |
465 | 474 | }
|
466 | 475 |
|
467 |
| - element.addEventListener('mouseup', Effect.hide, { capture:false, passive: true }); |
468 |
| - element.addEventListener('mouseleave', Effect.hide, { capture:false, passive: true }); |
| 476 | + element.addEventListener('mouseup', Effect.hide, passiveIfSupported); |
| 477 | + element.addEventListener('mouseleave', Effect.hide, passiveIfSupported); |
469 | 478 | }
|
470 | 479 | }
|
471 | 480 | }
|
|
484 | 493 | }
|
485 | 494 |
|
486 | 495 | if (isTouchAvailable) {
|
487 |
| - body.addEventListener('touchstart', showEffect, { capture:false, passive: true }); |
488 |
| - body.addEventListener('touchcancel', TouchHandler.registerEvent, { capture:false, passive: true }); |
489 |
| - body.addEventListener('touchend', TouchHandler.registerEvent, { capture:false, passive: true }); |
| 496 | + body.addEventListener('touchstart', showEffect, passiveIfSupported); |
| 497 | + body.addEventListener('touchcancel', TouchHandler.registerEvent, passiveIfSupported); |
| 498 | + body.addEventListener('touchend', TouchHandler.registerEvent, passiveIfSupported); |
490 | 499 | }
|
491 | 500 |
|
492 |
| - body.addEventListener('mousedown', showEffect, { capture:false, passive: true }); |
| 501 | + body.addEventListener('mousedown', showEffect, passiveIfSupported); |
493 | 502 | };
|
494 | 503 |
|
495 | 504 |
|
|
0 commit comments