polymer-paper-elements-rails 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (188) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +51 -0
  3. data/Rakefile +1 -0
  4. data/app/assets/components/iron-a11y-announcer/iron-a11y-announcer.html +125 -0
  5. data/app/assets/components/iron-a11y-keys-behavior/iron-a11y-keys-behavior.html +418 -0
  6. data/app/assets/components/iron-autogrow-textarea/hero.svg +33 -0
  7. data/app/assets/components/iron-autogrow-textarea/iron-autogrow-textarea.html +263 -0
  8. data/app/assets/components/iron-behaviors/iron-button-state.html +195 -0
  9. data/app/assets/components/iron-behaviors/iron-control-state.html +102 -0
  10. data/app/assets/components/iron-fit-behavior/iron-fit-behavior.html +230 -0
  11. data/app/assets/components/iron-flex-layout/classes/iron-flex-layout.html +307 -0
  12. data/app/assets/components/iron-flex-layout/classes/iron-shadow-flex-layout.html +302 -0
  13. data/app/assets/components/iron-flex-layout/iron-flex-layout.html +313 -0
  14. data/app/assets/components/iron-form-element-behavior/iron-form-element-behavior.html +50 -0
  15. data/app/assets/components/iron-icon/hero.svg +19 -0
  16. data/app/assets/components/iron-icon/iron-icon.html +187 -0
  17. data/app/assets/components/iron-icons/av-icons.html +73 -0
  18. data/app/assets/components/iron-icons/communication-icons.html +59 -0
  19. data/app/assets/components/iron-icons/device-icons.html +94 -0
  20. data/app/assets/components/iron-icons/editor-icons.html +70 -0
  21. data/app/assets/components/iron-icons/hardware-icons.html +61 -0
  22. data/app/assets/components/iron-icons/hero.svg +35 -0
  23. data/app/assets/components/iron-icons/image-icons.html +164 -0
  24. data/app/assets/components/iron-icons/iron-icons.html +303 -0
  25. data/app/assets/components/iron-icons/maps-icons.html +71 -0
  26. data/app/assets/components/iron-icons/notification-icons.html +62 -0
  27. data/app/assets/components/iron-icons/social-icons.html +40 -0
  28. data/app/assets/components/iron-iconset-svg/iron-iconset-svg.html +191 -0
  29. data/app/assets/components/iron-input/hero.svg +19 -0
  30. data/app/assets/components/iron-input/iron-input.html +235 -0
  31. data/app/assets/components/iron-media-query/hero.svg +29 -0
  32. data/app/assets/components/iron-media-query/iron-media-query.html +84 -0
  33. data/app/assets/components/iron-menu-behavior/iron-menu-behavior.html +214 -0
  34. data/app/assets/components/iron-menu-behavior/iron-menubar-behavior.html +65 -0
  35. data/app/assets/components/iron-meta/hero.svg +33 -0
  36. data/app/assets/components/iron-meta/iron-meta.html +352 -0
  37. data/app/assets/components/iron-overlay-behavior/iron-overlay-backdrop.html +132 -0
  38. data/app/assets/components/iron-overlay-behavior/iron-overlay-behavior.html +432 -0
  39. data/app/assets/components/iron-overlay-behavior/iron-overlay-manager.html +107 -0
  40. data/app/assets/components/iron-range-behavior/iron-range-behavior.html +101 -0
  41. data/app/assets/components/iron-resizable-behavior/iron-resizable-behavior.html +139 -0
  42. data/app/assets/components/iron-selector/iron-multi-selectable.html +120 -0
  43. data/app/assets/components/iron-selector/iron-selectable.html +307 -0
  44. data/app/assets/components/iron-selector/iron-selection.html +115 -0
  45. data/app/assets/components/iron-selector/iron-selector.html +71 -0
  46. data/app/assets/components/iron-validatable-behavior/iron-validatable-behavior.html +100 -0
  47. data/app/assets/components/neon-animation/animations/cascaded-animation.html +84 -0
  48. data/app/assets/components/neon-animation/animations/fade-in-animation.html +49 -0
  49. data/app/assets/components/neon-animation/animations/fade-out-animation.html +49 -0
  50. data/app/assets/components/neon-animation/animations/hero-animation.html +83 -0
  51. data/app/assets/components/neon-animation/animations/opaque-animation.html +46 -0
  52. data/app/assets/components/neon-animation/animations/ripple-animation.html +92 -0
  53. data/app/assets/components/neon-animation/animations/scale-down-animation.html +65 -0
  54. data/app/assets/components/neon-animation/animations/scale-up-animation.html +58 -0
  55. data/app/assets/components/neon-animation/animations/slide-down-animation.html +59 -0
  56. data/app/assets/components/neon-animation/animations/slide-from-left-animation.html +60 -0
  57. data/app/assets/components/neon-animation/animations/slide-from-right-animation.html +60 -0
  58. data/app/assets/components/neon-animation/animations/slide-left-animation.html +59 -0
  59. data/app/assets/components/neon-animation/animations/slide-right-animation.html +59 -0
  60. data/app/assets/components/neon-animation/animations/slide-up-animation.html +59 -0
  61. data/app/assets/components/neon-animation/animations/transform-animation.html +61 -0
  62. data/app/assets/components/neon-animation/guides/neon-animation.md +313 -0
  63. data/app/assets/components/neon-animation/neon-animatable-behavior.html +156 -0
  64. data/app/assets/components/neon-animation/neon-animatable.html +54 -0
  65. data/app/assets/components/neon-animation/neon-animated-pages.html +208 -0
  66. data/app/assets/components/neon-animation/neon-animation-behavior.html +88 -0
  67. data/app/assets/components/neon-animation/neon-animation-runner-behavior.html +110 -0
  68. data/app/assets/components/neon-animation/neon-animation.html +17 -0
  69. data/app/assets/components/neon-animation/neon-animations.html +25 -0
  70. data/app/assets/components/neon-animation/neon-shared-element-animatable-behavior.html +37 -0
  71. data/app/assets/components/neon-animation/neon-shared-element-animation-behavior.html +66 -0
  72. data/app/assets/components/neon-animation/web-animations.html +11 -0
  73. data/app/assets/components/paper-behaviors/paper-button-behavior.html +55 -0
  74. data/app/assets/components/paper-behaviors/paper-inky-focus-behavior.html +44 -0
  75. data/app/assets/components/paper-button/paper-button.html +177 -0
  76. data/app/assets/components/paper-checkbox/metadata.html +17 -0
  77. data/app/assets/components/paper-checkbox/paper-checkbox.css +149 -0
  78. data/app/assets/components/paper-checkbox/paper-checkbox.html +163 -0
  79. data/app/assets/components/paper-dialog-behavior/hero.svg +51 -0
  80. data/app/assets/components/paper-dialog-behavior/paper-dialog-behavior.html +236 -0
  81. data/app/assets/components/paper-dialog-behavior/paper-dialog-common.css +58 -0
  82. data/app/assets/components/paper-dialog-scrollable/hero.svg +69 -0
  83. data/app/assets/components/paper-dialog-scrollable/paper-dialog-scrollable.html +150 -0
  84. data/app/assets/components/paper-dialog/hero.svg +58 -0
  85. data/app/assets/components/paper-dialog/paper-dialog.html +122 -0
  86. data/app/assets/components/paper-drawer-panel/hero.svg +21 -0
  87. data/app/assets/components/paper-drawer-panel/paper-drawer-panel.css +142 -0
  88. data/app/assets/components/paper-drawer-panel/paper-drawer-panel.html +585 -0
  89. data/app/assets/components/paper-fab/paper-fab.html +159 -0
  90. data/app/assets/components/paper-header-panel/hero.svg +38 -0
  91. data/app/assets/components/paper-header-panel/paper-header-panel.html +496 -0
  92. data/app/assets/components/paper-icon-button/paper-icon-button.html +141 -0
  93. data/app/assets/components/paper-input/all-imports.html +12 -0
  94. data/app/assets/components/paper-input/hero.svg +19 -0
  95. data/app/assets/components/paper-input/paper-input-addon-behavior.html +43 -0
  96. data/app/assets/components/paper-input/paper-input-behavior.html +293 -0
  97. data/app/assets/components/paper-input/paper-input-char-counter.html +95 -0
  98. data/app/assets/components/paper-input/paper-input-container.html +495 -0
  99. data/app/assets/components/paper-input/paper-input-error.html +99 -0
  100. data/app/assets/components/paper-input/paper-input.html +126 -0
  101. data/app/assets/components/paper-input/paper-textarea.html +100 -0
  102. data/app/assets/components/paper-item/all-imports.html +13 -0
  103. data/app/assets/components/paper-item/paper-icon-item.html +86 -0
  104. data/app/assets/components/paper-item/paper-item-body.html +93 -0
  105. data/app/assets/components/paper-item/paper-item-shared.css +19 -0
  106. data/app/assets/components/paper-item/paper-item.html +95 -0
  107. data/app/assets/components/paper-material/paper-material.html +98 -0
  108. data/app/assets/components/paper-menu/hero.svg +35 -0
  109. data/app/assets/components/paper-menu/paper-menu.html +133 -0
  110. data/app/assets/components/paper-progress/hero.svg +21 -0
  111. data/app/assets/components/paper-progress/paper-progress.html +199 -0
  112. data/app/assets/components/paper-radio-button/hero.svg +22 -0
  113. data/app/assets/components/paper-radio-button/paper-radio-button.css +109 -0
  114. data/app/assets/components/paper-radio-button/paper-radio-button.html +148 -0
  115. data/app/assets/components/paper-radio-group/hero.svg +25 -0
  116. data/app/assets/components/paper-radio-group/paper-radio-group.html +186 -0
  117. data/app/assets/components/paper-ripple/hero.svg +30 -0
  118. data/app/assets/components/paper-ripple/paper-ripple.html +714 -0
  119. data/app/assets/components/paper-scroll-header-panel/hero.svg +41 -0
  120. data/app/assets/components/paper-scroll-header-panel/paper-scroll-header-panel.html +455 -0
  121. data/app/assets/components/paper-slider/hero.svg +20 -0
  122. data/app/assets/components/paper-slider/paper-slider.css +252 -0
  123. data/app/assets/components/paper-slider/paper-slider.html +449 -0
  124. data/app/assets/components/paper-spinner/hero.svg +27 -0
  125. data/app/assets/components/paper-spinner/paper-spinner.css +325 -0
  126. data/app/assets/components/paper-spinner/paper-spinner.html +222 -0
  127. data/app/assets/components/paper-styles/classes/global.html +96 -0
  128. data/app/assets/components/paper-styles/classes/shadow-layout.html +302 -0
  129. data/app/assets/components/paper-styles/classes/shadow.html +39 -0
  130. data/app/assets/components/paper-styles/classes/typography.html +171 -0
  131. data/app/assets/components/paper-styles/color.html +333 -0
  132. data/app/assets/components/paper-styles/default-theme.html +39 -0
  133. data/app/assets/components/paper-styles/paper-styles-classes.html +14 -0
  134. data/app/assets/components/paper-styles/paper-styles.html +17 -0
  135. data/app/assets/components/paper-styles/shadow.html +61 -0
  136. data/app/assets/components/paper-styles/typography.html +240 -0
  137. data/app/assets/components/paper-tabs/hero.svg +23 -0
  138. data/app/assets/components/paper-tabs/paper-tab.html +158 -0
  139. data/app/assets/components/paper-tabs/paper-tabs-icons.html +18 -0
  140. data/app/assets/components/paper-tabs/paper-tabs.html +483 -0
  141. data/app/assets/components/paper-toast/hero.svg +20 -0
  142. data/app/assets/components/paper-toast/paper-toast.html +164 -0
  143. data/app/assets/components/paper-toggle-button/hero.svg +22 -0
  144. data/app/assets/components/paper-toggle-button/paper-toggle-button.css +108 -0
  145. data/app/assets/components/paper-toggle-button/paper-toggle-button.html +183 -0
  146. data/app/assets/components/paper-toolbar/paper-toolbar.html +375 -0
  147. data/app/assets/components/polymer-gestures/Gruntfile.js +60 -0
  148. data/app/assets/components/polymer-gestures/banner.txt +9 -0
  149. data/app/assets/components/polymer-gestures/build.json +17 -0
  150. data/app/assets/components/polymer-gestures/conf/karma.conf.js +39 -0
  151. data/app/assets/components/polymer-gestures/package.json +20 -0
  152. data/app/assets/components/polymer-gestures/polymer-gestures.html +21 -0
  153. data/app/assets/components/polymer-gestures/polymer-gestures.js +46 -0
  154. data/app/assets/components/polymer-gestures/src/dispatcher.js +474 -0
  155. data/app/assets/components/polymer-gestures/src/eventFactory.js +127 -0
  156. data/app/assets/components/polymer-gestures/src/hold.js +129 -0
  157. data/app/assets/components/polymer-gestures/src/mouse.js +135 -0
  158. data/app/assets/components/polymer-gestures/src/ms.js +80 -0
  159. data/app/assets/components/polymer-gestures/src/pinch.js +186 -0
  160. data/app/assets/components/polymer-gestures/src/platform-events.js +39 -0
  161. data/app/assets/components/polymer-gestures/src/pointer.js +68 -0
  162. data/app/assets/components/polymer-gestures/src/pointermap.js +67 -0
  163. data/app/assets/components/polymer-gestures/src/scope.js +10 -0
  164. data/app/assets/components/polymer-gestures/src/tap.js +103 -0
  165. data/app/assets/components/polymer-gestures/src/targetfind.js +244 -0
  166. data/app/assets/components/polymer-gestures/src/touch-action.js +60 -0
  167. data/app/assets/components/polymer-gestures/src/touch.js +341 -0
  168. data/app/assets/components/polymer-gestures/src/track.js +230 -0
  169. data/app/assets/components/web-animations-js/web-animations-next-lite.min.js +17 -0
  170. data/app/assets/components/web-animations-js/web-animations-next.min.js +17 -0
  171. data/app/assets/components/web-animations-js/web-animations.min.js +17 -0
  172. data/app/assets/components/webcomponentsjs/CustomElements.js +956 -0
  173. data/app/assets/components/webcomponentsjs/CustomElements.min.js +11 -0
  174. data/app/assets/components/webcomponentsjs/HTMLImports.js +1078 -0
  175. data/app/assets/components/webcomponentsjs/HTMLImports.min.js +11 -0
  176. data/app/assets/components/webcomponentsjs/MutationObserver.js +344 -0
  177. data/app/assets/components/webcomponentsjs/MutationObserver.min.js +11 -0
  178. data/app/assets/components/webcomponentsjs/ShadowDOM.js +4414 -0
  179. data/app/assets/components/webcomponentsjs/ShadowDOM.min.js +15 -0
  180. data/app/assets/components/webcomponentsjs/package.json +31 -0
  181. data/app/assets/components/webcomponentsjs/webcomponents-lite.js +2300 -0
  182. data/app/assets/components/webcomponentsjs/webcomponents-lite.min.js +13 -0
  183. data/app/assets/components/webcomponentsjs/webcomponents.js +7112 -0
  184. data/app/assets/components/webcomponentsjs/webcomponents.min.js +15 -0
  185. data/lib/polymer-paper-elements-rails.rb +2 -0
  186. data/lib/polymer-paper-elements-rails/engine.rb +4 -0
  187. data/lib/polymer-paper-elements-rails/version.rb +3 -0
  188. metadata +272 -0
@@ -0,0 +1,244 @@
1
+ /*
2
+ * Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
3
+ * This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
4
+ * The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
5
+ * The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
6
+ * Code distributed by Google as part of the polymer project is also
7
+ * subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
8
+ */
9
+
10
+ (function(scope) {
11
+ var hasFullPath = false;
12
+
13
+ // test for full event path support
14
+ var pathTest = document.createElement('meta');
15
+ if (pathTest.createShadowRoot) {
16
+ var sr = pathTest.createShadowRoot();
17
+ var s = document.createElement('span');
18
+ sr.appendChild(s);
19
+ pathTest.addEventListener('testpath', function(ev) {
20
+ if (ev.path) {
21
+ // if the span is in the event path, then path[0] is the real source for all events
22
+ hasFullPath = ev.path[0] === s;
23
+ }
24
+ ev.stopPropagation();
25
+ });
26
+ var ev = new CustomEvent('testpath', {bubbles: true});
27
+ // must add node to DOM to trigger event listener
28
+ document.head.appendChild(pathTest);
29
+ s.dispatchEvent(ev);
30
+ pathTest.parentNode.removeChild(pathTest);
31
+ sr = s = null;
32
+ }
33
+ pathTest = null;
34
+
35
+ var target = {
36
+ shadow: function(inEl) {
37
+ if (inEl) {
38
+ return inEl.shadowRoot || inEl.webkitShadowRoot;
39
+ }
40
+ },
41
+ canTarget: function(shadow) {
42
+ return shadow && Boolean(shadow.elementFromPoint);
43
+ },
44
+ targetingShadow: function(inEl) {
45
+ var s = this.shadow(inEl);
46
+ if (this.canTarget(s)) {
47
+ return s;
48
+ }
49
+ },
50
+ olderShadow: function(shadow) {
51
+ var os = shadow.olderShadowRoot;
52
+ if (!os) {
53
+ var se = shadow.querySelector('shadow');
54
+ if (se) {
55
+ os = se.olderShadowRoot;
56
+ }
57
+ }
58
+ return os;
59
+ },
60
+ allShadows: function(element) {
61
+ var shadows = [], s = this.shadow(element);
62
+ while(s) {
63
+ shadows.push(s);
64
+ s = this.olderShadow(s);
65
+ }
66
+ return shadows;
67
+ },
68
+ searchRoot: function(inRoot, x, y) {
69
+ var t, st, sr, os;
70
+ if (inRoot) {
71
+ t = inRoot.elementFromPoint(x, y);
72
+ if (t) {
73
+ // found element, check if it has a ShadowRoot
74
+ sr = this.targetingShadow(t);
75
+ } else if (inRoot !== document) {
76
+ // check for sibling roots
77
+ sr = this.olderShadow(inRoot);
78
+ }
79
+ // search other roots, fall back to light dom element
80
+ return this.searchRoot(sr, x, y) || t;
81
+ }
82
+ },
83
+ owner: function(element) {
84
+ if (!element) {
85
+ return document;
86
+ }
87
+ var s = element;
88
+ // walk up until you hit the shadow root or document
89
+ while (s.parentNode) {
90
+ s = s.parentNode;
91
+ }
92
+ // the owner element is expected to be a Document or ShadowRoot
93
+ if (s.nodeType != Node.DOCUMENT_NODE && s.nodeType != Node.DOCUMENT_FRAGMENT_NODE) {
94
+ s = document;
95
+ }
96
+ return s;
97
+ },
98
+ findTarget: function(inEvent) {
99
+ if (hasFullPath && inEvent.path && inEvent.path.length) {
100
+ return inEvent.path[0];
101
+ }
102
+ var x = inEvent.clientX, y = inEvent.clientY;
103
+ // if the listener is in the shadow root, it is much faster to start there
104
+ var s = this.owner(inEvent.target);
105
+ // if x, y is not in this root, fall back to document search
106
+ if (!s.elementFromPoint(x, y)) {
107
+ s = document;
108
+ }
109
+ return this.searchRoot(s, x, y);
110
+ },
111
+ findTouchAction: function(inEvent) {
112
+ var n;
113
+ if (hasFullPath && inEvent.path && inEvent.path.length) {
114
+ var path = inEvent.path;
115
+ for (var i = 0; i < path.length; i++) {
116
+ n = path[i];
117
+ if (n.nodeType === Node.ELEMENT_NODE && n.hasAttribute('touch-action')) {
118
+ return n.getAttribute('touch-action');
119
+ }
120
+ }
121
+ } else {
122
+ n = inEvent.target;
123
+ while(n) {
124
+ if (n.nodeType === Node.ELEMENT_NODE && n.hasAttribute('touch-action')) {
125
+ return n.getAttribute('touch-action');
126
+ }
127
+ n = n.parentNode || n.host;
128
+ }
129
+ }
130
+ // auto is default
131
+ return "auto";
132
+ },
133
+ LCA: function(a, b) {
134
+ if (a === b) {
135
+ return a;
136
+ }
137
+ if (a && !b) {
138
+ return a;
139
+ }
140
+ if (b && !a) {
141
+ return b;
142
+ }
143
+ if (!b && !a) {
144
+ return document;
145
+ }
146
+ // fast case, a is a direct descendant of b or vice versa
147
+ if (a.contains && a.contains(b)) {
148
+ return a;
149
+ }
150
+ if (b.contains && b.contains(a)) {
151
+ return b;
152
+ }
153
+ var adepth = this.depth(a);
154
+ var bdepth = this.depth(b);
155
+ var d = adepth - bdepth;
156
+ if (d >= 0) {
157
+ a = this.walk(a, d);
158
+ } else {
159
+ b = this.walk(b, -d);
160
+ }
161
+ while (a && b && a !== b) {
162
+ a = a.parentNode || a.host;
163
+ b = b.parentNode || b.host;
164
+ }
165
+ return a;
166
+ },
167
+ walk: function(n, u) {
168
+ for (var i = 0; n && (i < u); i++) {
169
+ n = n.parentNode || n.host;
170
+ }
171
+ return n;
172
+ },
173
+ depth: function(n) {
174
+ var d = 0;
175
+ while(n) {
176
+ d++;
177
+ n = n.parentNode || n.host;
178
+ }
179
+ return d;
180
+ },
181
+ deepContains: function(a, b) {
182
+ var common = this.LCA(a, b);
183
+ // if a is the common ancestor, it must "deeply" contain b
184
+ return common === a;
185
+ },
186
+ insideNode: function(node, x, y) {
187
+ var rect = node.getBoundingClientRect();
188
+ return (rect.left <= x) && (x <= rect.right) && (rect.top <= y) && (y <= rect.bottom);
189
+ },
190
+ path: function(event) {
191
+ var p;
192
+ if (hasFullPath && event.path && event.path.length) {
193
+ p = event.path;
194
+ } else {
195
+ p = [];
196
+ var n = this.findTarget(event);
197
+ while (n) {
198
+ p.push(n);
199
+ n = n.parentNode || n.host;
200
+ }
201
+ }
202
+ return p;
203
+ }
204
+ };
205
+ scope.targetFinding = target;
206
+ /**
207
+ * Given an event, finds the "deepest" node that could have been the original target before ShadowDOM retargetting
208
+ *
209
+ * @param {Event} Event An event object with clientX and clientY properties
210
+ * @return {Element} The probable event origninator
211
+ */
212
+ scope.findTarget = target.findTarget.bind(target);
213
+ /**
214
+ * Determines if the "container" node deeply contains the "containee" node, including situations where the "containee" is contained by one or more ShadowDOM
215
+ * roots.
216
+ *
217
+ * @param {Node} container
218
+ * @param {Node} containee
219
+ * @return {Boolean}
220
+ */
221
+ scope.deepContains = target.deepContains.bind(target);
222
+
223
+ /**
224
+ * Determines if the x/y position is inside the given node.
225
+ *
226
+ * Example:
227
+ *
228
+ * function upHandler(event) {
229
+ * var innode = PolymerGestures.insideNode(event.target, event.clientX, event.clientY);
230
+ * if (innode) {
231
+ * // wait for tap?
232
+ * } else {
233
+ * // tap will never happen
234
+ * }
235
+ * }
236
+ *
237
+ * @param {Node} node
238
+ * @param {Number} x Screen X position
239
+ * @param {Number} y screen Y position
240
+ * @return {Boolean}
241
+ */
242
+ scope.insideNode = target.insideNode;
243
+
244
+ })(window.PolymerGestures);
@@ -0,0 +1,60 @@
1
+ /*
2
+ *
3
+ * Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
4
+ * This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.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/CONTRIBUTORS.txt
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/PATENTS.txt
9
+ */
10
+
11
+ (function() {
12
+ function shadowSelector(v) {
13
+ return 'html /deep/ ' + selector(v);
14
+ }
15
+ function selector(v) {
16
+ return '[touch-action="' + v + '"]';
17
+ }
18
+ function rule(v) {
19
+ return '{ -ms-touch-action: ' + v + '; touch-action: ' + v + ';}';
20
+ }
21
+ var attrib2css = [
22
+ 'none',
23
+ 'auto',
24
+ 'pan-x',
25
+ 'pan-y',
26
+ {
27
+ rule: 'pan-x pan-y',
28
+ selectors: [
29
+ 'pan-x pan-y',
30
+ 'pan-y pan-x'
31
+ ]
32
+ },
33
+ 'manipulation'
34
+ ];
35
+ var styles = '';
36
+ // only install stylesheet if the browser has touch action support
37
+ var hasTouchAction = typeof document.head.style.touchAction === 'string';
38
+ // only add shadow selectors if shadowdom is supported
39
+ var hasShadowRoot = !window.ShadowDOMPolyfill && document.head.createShadowRoot;
40
+
41
+ if (hasTouchAction) {
42
+ attrib2css.forEach(function(r) {
43
+ if (String(r) === r) {
44
+ styles += selector(r) + rule(r) + '\n';
45
+ if (hasShadowRoot) {
46
+ styles += shadowSelector(r) + rule(r) + '\n';
47
+ }
48
+ } else {
49
+ styles += r.selectors.map(selector) + rule(r.rule) + '\n';
50
+ if (hasShadowRoot) {
51
+ styles += r.selectors.map(shadowSelector) + rule(r.rule) + '\n';
52
+ }
53
+ }
54
+ });
55
+
56
+ var el = document.createElement('style');
57
+ el.textContent = styles;
58
+ document.head.appendChild(el);
59
+ }
60
+ })();
@@ -0,0 +1,341 @@
1
+ /*
2
+ * Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
3
+ * This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
4
+ * The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
5
+ * The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
6
+ * Code distributed by Google as part of the polymer project is also
7
+ * subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
8
+ */
9
+
10
+ (function(scope) {
11
+ var dispatcher = scope.dispatcher;
12
+ var allShadows = scope.targetFinding.allShadows.bind(scope.targetFinding);
13
+ var pointermap = dispatcher.pointermap;
14
+ var touchMap = Array.prototype.map.call.bind(Array.prototype.map);
15
+ // This should be long enough to ignore compat mouse events made by touch
16
+ var DEDUP_TIMEOUT = 2500;
17
+ var DEDUP_DIST = 25;
18
+ var CLICK_COUNT_TIMEOUT = 200;
19
+ var HYSTERESIS = 20;
20
+ var ATTRIB = 'touch-action';
21
+ // TODO(dfreedm): disable until http://crbug.com/399765 is resolved
22
+ // var HAS_TOUCH_ACTION = ATTRIB in document.head.style;
23
+ var HAS_TOUCH_ACTION = false;
24
+
25
+ // handler block for native touch events
26
+ var touchEvents = {
27
+ IS_IOS: false,
28
+ events: [
29
+ 'touchstart',
30
+ 'touchmove',
31
+ 'touchend',
32
+ 'touchcancel'
33
+ ],
34
+ exposes: [
35
+ 'down',
36
+ 'up',
37
+ 'move'
38
+ ],
39
+ register: function(target, initial) {
40
+ if (this.IS_IOS ? initial : !initial) {
41
+ dispatcher.listen(target, this.events);
42
+ }
43
+ },
44
+ unregister: function(target) {
45
+ if (!this.IS_IOS) {
46
+ dispatcher.unlisten(target, this.events);
47
+ }
48
+ },
49
+ scrollTypes: {
50
+ EMITTER: 'none',
51
+ XSCROLLER: 'pan-x',
52
+ YSCROLLER: 'pan-y',
53
+ },
54
+ touchActionToScrollType: function(touchAction) {
55
+ var t = touchAction;
56
+ var st = this.scrollTypes;
57
+ if (t === st.EMITTER) {
58
+ return 'none';
59
+ } else if (t === st.XSCROLLER) {
60
+ return 'X';
61
+ } else if (t === st.YSCROLLER) {
62
+ return 'Y';
63
+ } else {
64
+ return 'XY';
65
+ }
66
+ },
67
+ POINTER_TYPE: 'touch',
68
+ firstTouch: null,
69
+ isPrimaryTouch: function(inTouch) {
70
+ return this.firstTouch === inTouch.identifier;
71
+ },
72
+ setPrimaryTouch: function(inTouch) {
73
+ // set primary touch if there no pointers, or the only pointer is the mouse
74
+ if (pointermap.pointers() === 0 || (pointermap.pointers() === 1 && pointermap.has(1))) {
75
+ this.firstTouch = inTouch.identifier;
76
+ this.firstXY = {X: inTouch.clientX, Y: inTouch.clientY};
77
+ this.firstTarget = inTouch.target;
78
+ this.scrolling = null;
79
+ this.cancelResetClickCount();
80
+ }
81
+ },
82
+ removePrimaryPointer: function(inPointer) {
83
+ if (inPointer.isPrimary) {
84
+ this.firstTouch = null;
85
+ this.firstXY = null;
86
+ this.resetClickCount();
87
+ }
88
+ },
89
+ clickCount: 0,
90
+ resetId: null,
91
+ resetClickCount: function() {
92
+ var fn = function() {
93
+ this.clickCount = 0;
94
+ this.resetId = null;
95
+ }.bind(this);
96
+ this.resetId = setTimeout(fn, CLICK_COUNT_TIMEOUT);
97
+ },
98
+ cancelResetClickCount: function() {
99
+ if (this.resetId) {
100
+ clearTimeout(this.resetId);
101
+ }
102
+ },
103
+ typeToButtons: function(type) {
104
+ var ret = 0;
105
+ if (type === 'touchstart' || type === 'touchmove') {
106
+ ret = 1;
107
+ }
108
+ return ret;
109
+ },
110
+ findTarget: function(touch, id) {
111
+ if (this.currentTouchEvent.type === 'touchstart') {
112
+ if (this.isPrimaryTouch(touch)) {
113
+ var fastPath = {
114
+ clientX: touch.clientX,
115
+ clientY: touch.clientY,
116
+ path: this.currentTouchEvent.path,
117
+ target: this.currentTouchEvent.target
118
+ };
119
+ return scope.findTarget(fastPath);
120
+ } else {
121
+ return scope.findTarget(touch);
122
+ }
123
+ }
124
+ // reuse target we found in touchstart
125
+ return pointermap.get(id);
126
+ },
127
+ touchToPointer: function(inTouch) {
128
+ var cte = this.currentTouchEvent;
129
+ var e = dispatcher.cloneEvent(inTouch);
130
+ // Spec specifies that pointerId 1 is reserved for Mouse.
131
+ // Touch identifiers can start at 0.
132
+ // Add 2 to the touch identifier for compatibility.
133
+ var id = e.pointerId = inTouch.identifier + 2;
134
+ e.target = this.findTarget(inTouch, id);
135
+ e.bubbles = true;
136
+ e.cancelable = true;
137
+ e.detail = this.clickCount;
138
+ e.buttons = this.typeToButtons(cte.type);
139
+ e.width = inTouch.webkitRadiusX || inTouch.radiusX || 0;
140
+ e.height = inTouch.webkitRadiusY || inTouch.radiusY || 0;
141
+ e.pressure = inTouch.webkitForce || inTouch.force || 0.5;
142
+ e.isPrimary = this.isPrimaryTouch(inTouch);
143
+ e.pointerType = this.POINTER_TYPE;
144
+ e._source = 'touch';
145
+ // forward touch preventDefaults
146
+ var self = this;
147
+ e.preventDefault = function() {
148
+ self.scrolling = false;
149
+ self.firstXY = null;
150
+ cte.preventDefault();
151
+ };
152
+ return e;
153
+ },
154
+ processTouches: function(inEvent, inFunction) {
155
+ var tl = inEvent.changedTouches;
156
+ this.currentTouchEvent = inEvent;
157
+ for (var i = 0, t, p; i < tl.length; i++) {
158
+ t = tl[i];
159
+ p = this.touchToPointer(t);
160
+ if (inEvent.type === 'touchstart') {
161
+ pointermap.set(p.pointerId, p.target);
162
+ }
163
+ if (pointermap.has(p.pointerId)) {
164
+ inFunction.call(this, p);
165
+ }
166
+ if (inEvent.type === 'touchend' || inEvent._cancel) {
167
+ this.cleanUpPointer(p);
168
+ }
169
+ }
170
+ },
171
+ // For single axis scrollers, determines whether the element should emit
172
+ // pointer events or behave as a scroller
173
+ shouldScroll: function(inEvent) {
174
+ if (this.firstXY) {
175
+ var ret;
176
+ var touchAction = scope.targetFinding.findTouchAction(inEvent);
177
+ var scrollAxis = this.touchActionToScrollType(touchAction);
178
+ if (scrollAxis === 'none') {
179
+ // this element is a touch-action: none, should never scroll
180
+ ret = false;
181
+ } else if (scrollAxis === 'XY') {
182
+ // this element should always scroll
183
+ ret = true;
184
+ } else {
185
+ var t = inEvent.changedTouches[0];
186
+ // check the intended scroll axis, and other axis
187
+ var a = scrollAxis;
188
+ var oa = scrollAxis === 'Y' ? 'X' : 'Y';
189
+ var da = Math.abs(t['client' + a] - this.firstXY[a]);
190
+ var doa = Math.abs(t['client' + oa] - this.firstXY[oa]);
191
+ // if delta in the scroll axis > delta other axis, scroll instead of
192
+ // making events
193
+ ret = da >= doa;
194
+ }
195
+ return ret;
196
+ }
197
+ },
198
+ findTouch: function(inTL, inId) {
199
+ for (var i = 0, l = inTL.length, t; i < l && (t = inTL[i]); i++) {
200
+ if (t.identifier === inId) {
201
+ return true;
202
+ }
203
+ }
204
+ },
205
+ // In some instances, a touchstart can happen without a touchend. This
206
+ // leaves the pointermap in a broken state.
207
+ // Therefore, on every touchstart, we remove the touches that did not fire a
208
+ // touchend event.
209
+ // To keep state globally consistent, we fire a
210
+ // pointercancel for this "abandoned" touch
211
+ vacuumTouches: function(inEvent) {
212
+ var tl = inEvent.touches;
213
+ // pointermap.pointers() should be < tl.length here, as the touchstart has not
214
+ // been processed yet.
215
+ if (pointermap.pointers() >= tl.length) {
216
+ var d = [];
217
+ pointermap.forEach(function(value, key) {
218
+ // Never remove pointerId == 1, which is mouse.
219
+ // Touch identifiers are 2 smaller than their pointerId, which is the
220
+ // index in pointermap.
221
+ if (key !== 1 && !this.findTouch(tl, key - 2)) {
222
+ var p = value;
223
+ d.push(p);
224
+ }
225
+ }, this);
226
+ d.forEach(function(p) {
227
+ this.cancel(p);
228
+ pointermap.delete(p.pointerId);
229
+ }, this);
230
+ }
231
+ },
232
+ touchstart: function(inEvent) {
233
+ this.vacuumTouches(inEvent);
234
+ this.setPrimaryTouch(inEvent.changedTouches[0]);
235
+ this.dedupSynthMouse(inEvent);
236
+ if (!this.scrolling) {
237
+ this.clickCount++;
238
+ this.processTouches(inEvent, this.down);
239
+ }
240
+ },
241
+ down: function(inPointer) {
242
+ dispatcher.down(inPointer);
243
+ },
244
+ touchmove: function(inEvent) {
245
+ if (HAS_TOUCH_ACTION) {
246
+ // touchevent.cancelable == false is sent when the page is scrolling under native Touch Action in Chrome 36
247
+ // https://groups.google.com/a/chromium.org/d/msg/input-dev/wHnyukcYBcA/b9kmtwM1jJQJ
248
+ if (inEvent.cancelable) {
249
+ this.processTouches(inEvent, this.move);
250
+ }
251
+ } else {
252
+ if (!this.scrolling) {
253
+ if (this.scrolling === null && this.shouldScroll(inEvent)) {
254
+ this.scrolling = true;
255
+ } else {
256
+ this.scrolling = false;
257
+ inEvent.preventDefault();
258
+ this.processTouches(inEvent, this.move);
259
+ }
260
+ } else if (this.firstXY) {
261
+ var t = inEvent.changedTouches[0];
262
+ var dx = t.clientX - this.firstXY.X;
263
+ var dy = t.clientY - this.firstXY.Y;
264
+ var dd = Math.sqrt(dx * dx + dy * dy);
265
+ if (dd >= HYSTERESIS) {
266
+ this.touchcancel(inEvent);
267
+ this.scrolling = true;
268
+ this.firstXY = null;
269
+ }
270
+ }
271
+ }
272
+ },
273
+ move: function(inPointer) {
274
+ dispatcher.move(inPointer);
275
+ },
276
+ touchend: function(inEvent) {
277
+ this.dedupSynthMouse(inEvent);
278
+ this.processTouches(inEvent, this.up);
279
+ },
280
+ up: function(inPointer) {
281
+ inPointer.relatedTarget = scope.findTarget(inPointer);
282
+ dispatcher.up(inPointer);
283
+ },
284
+ cancel: function(inPointer) {
285
+ dispatcher.cancel(inPointer);
286
+ },
287
+ touchcancel: function(inEvent) {
288
+ inEvent._cancel = true;
289
+ this.processTouches(inEvent, this.cancel);
290
+ },
291
+ cleanUpPointer: function(inPointer) {
292
+ pointermap['delete'](inPointer.pointerId);
293
+ this.removePrimaryPointer(inPointer);
294
+ },
295
+ // prevent synth mouse events from creating pointer events
296
+ dedupSynthMouse: function(inEvent) {
297
+ var lts = scope.mouseEvents.lastTouches;
298
+ var t = inEvent.changedTouches[0];
299
+ // only the primary finger will synth mouse events
300
+ if (this.isPrimaryTouch(t)) {
301
+ // remember x/y of last touch
302
+ var lt = {x: t.clientX, y: t.clientY};
303
+ lts.push(lt);
304
+ var fn = (function(lts, lt){
305
+ var i = lts.indexOf(lt);
306
+ if (i > -1) {
307
+ lts.splice(i, 1);
308
+ }
309
+ }).bind(null, lts, lt);
310
+ setTimeout(fn, DEDUP_TIMEOUT);
311
+ }
312
+ }
313
+ };
314
+
315
+ // prevent "ghost clicks" that come from elements that were removed in a touch handler
316
+ var STOP_PROP_FN = Event.prototype.stopImmediatePropagation || Event.prototype.stopPropagation;
317
+ document.addEventListener('click', function(ev) {
318
+ var x = ev.clientX, y = ev.clientY;
319
+ // check if a click is within DEDUP_DIST px radius of the touchstart
320
+ var closeTo = function(touch) {
321
+ var dx = Math.abs(x - touch.x), dy = Math.abs(y - touch.y);
322
+ return (dx <= DEDUP_DIST && dy <= DEDUP_DIST);
323
+ };
324
+ // if click coordinates are close to touch coordinates, assume the click came from a touch
325
+ var wasTouched = scope.mouseEvents.lastTouches.some(closeTo);
326
+ // if the click came from touch, and the touchstart target is not in the path of the click event,
327
+ // then the touchstart target was probably removed, and the click should be "busted"
328
+ var path = scope.targetFinding.path(ev);
329
+ if (wasTouched) {
330
+ for (var i = 0; i < path.length; i++) {
331
+ if (path[i] === touchEvents.firstTarget) {
332
+ return;
333
+ }
334
+ }
335
+ ev.preventDefault();
336
+ STOP_PROP_FN.call(ev);
337
+ }
338
+ }, true);
339
+
340
+ scope.touchEvents = touchEvents;
341
+ })(window.PolymerGestures);