File tree Expand file tree Collapse file tree 3 files changed +28
-6
lines changed Expand file tree Collapse file tree 3 files changed +28
-6
lines changed Original file line number Diff line number Diff line change 59
59
} catch(e) {}
60
60
})();
61
61
62
- // decide whether to use {passive: true} for gestures listening for touch events
63
- let PASSIVE_TOUCH = Boolean(HAS_NATIVE_TA && SUPPORTS_PASSIVE && Polymer.passiveTouchGestures);
62
+ /**
63
+ * Generate settings for event listeners, dependant on `Polymer.passiveTouchGestures`
64
+ *
65
+ * @return {{passive: boolean} | undefined} Options to use for addEventListener and removeEventListener
66
+ */
67
+ function PASSIVE_TOUCH() {
68
+ if (HAS_NATIVE_TA && SUPPORTS_PASSIVE && Polymer.passiveTouchGestures) {
69
+ return {passive: true};
70
+ } else {
71
+ return;
72
+ }
73
+ }
64
74
65
75
// Check for touch-only devices
66
76
let IS_TOUCH_ONLY = navigator.userAgent.match(/iP(?:[oa]d|hone)|Android/);
470
480
gobj[dep] = gd = {_count: 0};
471
481
}
472
482
if (gd._count === 0) {
473
- let options = !isMouseEvent(dep) && PASSIVE_TOUCH ? {passive: true} : undefined ;
483
+ let options = !isMouseEvent(dep) && PASSIVE_TOUCH() ;
474
484
node.addEventListener(dep, this._handleNative, options);
475
485
}
476
486
gd[name] = (gd[name] || 0) + 1;
504
514
gd[name] = (gd[name] || 1) - 1;
505
515
gd._count = (gd._count || 1) - 1;
506
516
if (gd._count === 0) {
507
- let options = !isMouseEvent(dep) && PASSIVE_TOUCH ? {passive: true} : undefined ;
517
+ let options = !isMouseEvent(dep) && PASSIVE_TOUCH() ;
508
518
node.removeEventListener(dep, this._handleNative, options);
509
519
}
510
520
}
Original file line number Diff line number Diff line change 102
102
*
103
103
* @memberof Polymer
104
104
*/
105
- Polymer.passiveTouchGestures = Polymer.passiveTouchGestures || false;
105
+ let passiveTouchGestures = false;
106
+
107
+ Polymer.passiveTouchGestures = passiveTouchGestures;
108
+
109
+ /**
110
+ * Sets `passiveTouchGestures` globally for all elements using Polymer Gestures.
111
+ *
112
+ * @memberof Polymer
113
+ * @param {boolean} usePassive enable or disable passive touch gestures globally
114
+ */
115
+ Polymer.setPassiveTouchGestures = function(usePassive) {
116
+ Polymer.passiveTouchGestures = usePassive;
117
+ };
106
118
})();
107
119
</script>
Original file line number Diff line number Diff line change 11
11
<html>
12
12
<head>
13
13
<script src="../../../webcomponentsjs/webcomponents-loader.js"></script>
14
- <script>Polymer = {passiveTouchGestures: true}</script>
15
14
<link rel="import" href="../../polymer.html">
15
+ <script>Polymer.setPassiveTouchGestures(true);</script>
16
16
<style>
17
17
html, body {
18
18
margin: 0;
You can’t perform that action at this time.
0 commit comments