|
36 | 36 | version: "@VERSION",
|
37 | 37 |
|
38 | 38 | setup: function() {
|
39 |
| - this.addEventListener( "wheel", handler, false ); |
| 39 | + // Use passive event listeners if supported |
| 40 | + var passiveSupported = false; |
| 41 | + try { |
| 42 | + var opts = Object.defineProperty({}, "passive", { |
| 43 | + get: function() { |
| 44 | + passiveSupported = true; |
| 45 | + } |
| 46 | + }); |
| 47 | + window.addEventListener("test", null, opts); |
| 48 | + } catch (e) {} |
| 49 | + this.addEventListener( |
| 50 | + "wheel", |
| 51 | + handler, |
| 52 | + passiveSupported ? { passive: true } : false |
| 53 | + ); |
40 | 54 |
|
41 | 55 | // Store the line height and page height for this particular element
|
42 | 56 | $.data( this, "mousewheel-line-height", special.getLineHeight( this ) );
|
43 | 57 | $.data( this, "mousewheel-page-height", special.getPageHeight( this ) );
|
44 | 58 | },
|
45 | 59 |
|
46 | 60 | teardown: function() {
|
47 |
| - this.removeEventListener( "wheel", handler, false ); |
| 61 | + // Remove with same passive option as setup |
| 62 | + var passiveSupported = false; |
| 63 | + try { |
| 64 | + var opts = Object.defineProperty({}, "passive", { |
| 65 | + get: function() { |
| 66 | + passiveSupported = true; |
| 67 | + } |
| 68 | + }); |
| 69 | + window.addEventListener("test", null, opts); |
| 70 | + } catch (e) {} |
| 71 | + this.removeEventListener( |
| 72 | + "wheel", |
| 73 | + handler, |
| 74 | + passiveSupported ? { passive: true } : false |
| 75 | + ); |
48 | 76 |
|
49 | 77 | // Clean up the data we added to the element
|
50 | 78 | $.removeData( this, "mousewheel-line-height" );
|
|
0 commit comments