OLD | NEW |
1 <!-- | 1 <!-- |
2 @license | 2 @license |
3 Copyright (c) 2015 The Polymer Project Authors. All rights reserved. | 3 Copyright (c) 2015 The Polymer Project Authors. All rights reserved. |
4 This code may only be used under the BSD style license found at http://polymer.g
ithub.io/LICENSE.txt | 4 This code may only be used under the BSD style license found at http://polymer.g
ithub.io/LICENSE.txt |
5 The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt | 5 The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt |
6 The complete set of contributors may be found at http://polymer.github.io/CONTRI
BUTORS.txt | 6 The complete set of contributors may be found at http://polymer.github.io/CONTRI
BUTORS.txt |
7 Code distributed by Google as part of the polymer project is also | 7 Code distributed by Google as part of the polymer project is also |
8 subject to an additional IP rights grant found at http://polymer.github.io/PATEN
TS.txt | 8 subject to an additional IP rights grant found at http://polymer.github.io/PATEN
TS.txt |
9 --> | 9 --> |
10 | 10 |
(...skipping 13 matching lines...) Expand all Loading... |
24 /** | 24 /** |
25 * Used to avoid computing event.path and filter scrollable nodes (better pe
rf). | 25 * Used to avoid computing event.path and filter scrollable nodes (better pe
rf). |
26 * @type {?EventTarget} | 26 * @type {?EventTarget} |
27 */ | 27 */ |
28 var lastRootTarget = null; | 28 var lastRootTarget = null; |
29 /** | 29 /** |
30 * @type {!Array<Node>} | 30 * @type {!Array<Node>} |
31 */ | 31 */ |
32 var lastScrollableNodes = []; | 32 var lastScrollableNodes = []; |
33 | 33 |
| 34 var scrollEvents = [ |
| 35 // Modern `wheel` event for mouse wheel scrolling: |
| 36 'wheel', |
| 37 // Older, non-standard `mousewheel` event for some FF: |
| 38 'mousewheel', |
| 39 // IE: |
| 40 'DOMMouseScroll', |
| 41 // Touch enabled devices |
| 42 'touchstart', |
| 43 'touchmove' |
| 44 ]; |
| 45 |
34 /** | 46 /** |
35 * The IronDropdownScrollManager is intended to provide a central source | 47 * The IronDropdownScrollManager is intended to provide a central source |
36 * of authority and control over which elements in a document are currently | 48 * of authority and control over which elements in a document are currently |
37 * allowed to scroll. | 49 * allowed to scroll. |
38 */ | 50 */ |
39 | 51 |
40 Polymer.IronDropdownScrollManager = { | 52 Polymer.IronDropdownScrollManager = { |
41 | 53 |
42 /** | 54 /** |
43 * The current element that defines the DOM boundaries of the | 55 * The current element that defines the DOM boundaries of the |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 if (event.targetTouches) { | 204 if (event.targetTouches) { |
193 var touch = event.targetTouches[0]; | 205 var touch = event.targetTouches[0]; |
194 lastTouchPosition.pageX = touch.pageX; | 206 lastTouchPosition.pageX = touch.pageX; |
195 lastTouchPosition.pageY = touch.pageY; | 207 lastTouchPosition.pageY = touch.pageY; |
196 } | 208 } |
197 }, | 209 }, |
198 | 210 |
199 _lockScrollInteractions: function() { | 211 _lockScrollInteractions: function() { |
200 this._boundScrollHandler = this._boundScrollHandler || | 212 this._boundScrollHandler = this._boundScrollHandler || |
201 this._scrollInteractionHandler.bind(this); | 213 this._scrollInteractionHandler.bind(this); |
202 // Modern `wheel` event for mouse wheel scrolling: | 214 for (var i = 0, l = scrollEvents.length; i < l; i++) { |
203 document.addEventListener('wheel', this._boundScrollHandler, true); | 215 // NOTE: browsers that don't support objects as third arg will |
204 // Older, non-standard `mousewheel` event for some FF: | 216 // interpret it as boolean, hence useCapture = true in this case. |
205 document.addEventListener('mousewheel', this._boundScrollHandler, true); | 217 document.addEventListener(scrollEvents[i], this._boundScrollHandler, { |
206 // IE: | 218 capture: true, |
207 document.addEventListener('DOMMouseScroll', this._boundScrollHandler, tr
ue); | 219 passive: false |
208 // Save the lastScrollableNodes on touchstart, to be used on touchmove. | 220 }); |
209 document.addEventListener('touchstart', this._boundScrollHandler, true); | 221 } |
210 // Mobile devices can scroll on touch move: | |
211 document.addEventListener('touchmove', this._boundScrollHandler, true); | |
212 }, | 222 }, |
213 | 223 |
214 _unlockScrollInteractions: function() { | 224 _unlockScrollInteractions: function() { |
215 document.removeEventListener('wheel', this._boundScrollHandler, true); | 225 for (var i = 0, l = scrollEvents.length; i < l; i++) { |
216 document.removeEventListener('mousewheel', this._boundScrollHandler, tru
e); | 226 // NOTE: browsers that don't support objects as third arg will |
217 document.removeEventListener('DOMMouseScroll', this._boundScrollHandler,
true); | 227 // interpret it as boolean, hence useCapture = true in this case. |
218 document.removeEventListener('touchstart', this._boundScrollHandler, tru
e); | 228 document.removeEventListener(scrollEvents[i], this._boundScrollHandler
, { |
219 document.removeEventListener('touchmove', this._boundScrollHandler, true
); | 229 capture: true, |
| 230 passive: false |
| 231 }); |
| 232 } |
220 }, | 233 }, |
221 | 234 |
222 /** | 235 /** |
223 * Returns true if the event causes scroll outside the current locking | 236 * Returns true if the event causes scroll outside the current locking |
224 * element, e.g. pointer/keyboard interactions, or scroll "leaking" | 237 * element, e.g. pointer/keyboard interactions, or scroll "leaking" |
225 * outside the locking element when it is already at its scroll boundaries
. | 238 * outside the locking element when it is already at its scroll boundaries
. |
226 * @param {!Event} event | 239 * @param {!Event} event |
227 * @return {boolean} | 240 * @return {boolean} |
228 * @private | 241 * @private |
229 */ | 242 */ |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 // Touch moves from right to left => scrolling goes right. | 363 // Touch moves from right to left => scrolling goes right. |
351 info.deltaX = lastTouchPosition.pageX - touch.pageX; | 364 info.deltaX = lastTouchPosition.pageX - touch.pageX; |
352 // Touch moves from down to up => scrolling goes down. | 365 // Touch moves from down to up => scrolling goes down. |
353 info.deltaY = lastTouchPosition.pageY - touch.pageY; | 366 info.deltaY = lastTouchPosition.pageY - touch.pageY; |
354 } | 367 } |
355 return info; | 368 return info; |
356 } | 369 } |
357 }; | 370 }; |
358 })(); | 371 })(); |
359 </script> | 372 </script> |
OLD | NEW |