OLD | NEW |
1 /** | 1 /** |
2 * @license | 2 * @license |
3 * Copyright (c) 2014 The Polymer Project Authors. All rights reserved. | 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://polyme
r.github.io/LICENSE.txt | 4 * This code may only be used under the BSD style license found at http://polyme
r.github.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/CON
TRIBUTORS.txt | 6 * The complete set of contributors may be found at http://polymer.github.io/CON
TRIBUTORS.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/PA
TENTS.txt | 8 * subject to an additional IP rights grant found at http://polymer.github.io/PA
TENTS.txt |
9 */ | 9 */ |
10 // @version 0.5.1 | 10 // @version 0.5.4 |
11 window.PolymerGestures = {}; | 11 window.PolymerGestures = {}; |
12 | 12 |
13 (function(scope) { | 13 (function(scope) { |
14 var HAS_FULL_PATH = false; | 14 var hasFullPath = false; |
15 | 15 |
16 // test for full event path support | 16 // test for full event path support |
17 var pathTest = document.createElement('meta'); | 17 var pathTest = document.createElement('meta'); |
18 if (pathTest.createShadowRoot) { | 18 if (pathTest.createShadowRoot) { |
19 var sr = pathTest.createShadowRoot(); | 19 var sr = pathTest.createShadowRoot(); |
20 var s = document.createElement('span'); | 20 var s = document.createElement('span'); |
21 sr.appendChild(s); | 21 sr.appendChild(s); |
22 pathTest.addEventListener('testpath', function(ev) { | 22 pathTest.addEventListener('testpath', function(ev) { |
23 if (ev.path) { | 23 if (ev.path) { |
24 // if the span is in the event path, then path[0] is the real source for
all events | 24 // if the span is in the event path, then path[0] is the real source for
all events |
25 HAS_FULL_PATH = ev.path[0] === s; | 25 hasFullPath = ev.path[0] === s; |
26 } | 26 } |
27 ev.stopPropagation(); | 27 ev.stopPropagation(); |
28 }); | 28 }); |
29 var ev = new CustomEvent('testpath', {bubbles: true}); | 29 var ev = new CustomEvent('testpath', {bubbles: true}); |
30 // must add node to DOM to trigger event listener | 30 // must add node to DOM to trigger event listener |
31 document.head.appendChild(pathTest); | 31 document.head.appendChild(pathTest); |
32 s.dispatchEvent(ev); | 32 s.dispatchEvent(ev); |
33 pathTest.parentNode.removeChild(pathTest); | 33 pathTest.parentNode.removeChild(pathTest); |
34 sr = s = null; | 34 sr = s = null; |
35 } | 35 } |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 while (s.parentNode) { | 92 while (s.parentNode) { |
93 s = s.parentNode; | 93 s = s.parentNode; |
94 } | 94 } |
95 // the owner element is expected to be a Document or ShadowRoot | 95 // the owner element is expected to be a Document or ShadowRoot |
96 if (s.nodeType != Node.DOCUMENT_NODE && s.nodeType != Node.DOCUMENT_FRAGME
NT_NODE) { | 96 if (s.nodeType != Node.DOCUMENT_NODE && s.nodeType != Node.DOCUMENT_FRAGME
NT_NODE) { |
97 s = document; | 97 s = document; |
98 } | 98 } |
99 return s; | 99 return s; |
100 }, | 100 }, |
101 findTarget: function(inEvent) { | 101 findTarget: function(inEvent) { |
102 if (HAS_FULL_PATH && inEvent.path && inEvent.path.length) { | 102 if (hasFullPath && inEvent.path && inEvent.path.length) { |
103 return inEvent.path[0]; | 103 return inEvent.path[0]; |
104 } | 104 } |
105 var x = inEvent.clientX, y = inEvent.clientY; | 105 var x = inEvent.clientX, y = inEvent.clientY; |
106 // if the listener is in the shadow root, it is much faster to start there | 106 // if the listener is in the shadow root, it is much faster to start there |
107 var s = this.owner(inEvent.target); | 107 var s = this.owner(inEvent.target); |
108 // if x, y is not in this root, fall back to document search | 108 // if x, y is not in this root, fall back to document search |
109 if (!s.elementFromPoint(x, y)) { | 109 if (!s.elementFromPoint(x, y)) { |
110 s = document; | 110 s = document; |
111 } | 111 } |
112 return this.searchRoot(s, x, y); | 112 return this.searchRoot(s, x, y); |
113 }, | 113 }, |
114 findTouchAction: function(inEvent) { | 114 findTouchAction: function(inEvent) { |
115 var n; | 115 var n; |
116 if (HAS_FULL_PATH && inEvent.path && inEvent.path.length) { | 116 if (hasFullPath && inEvent.path && inEvent.path.length) { |
117 var path = inEvent.path; | 117 var path = inEvent.path; |
118 for (var i = 0; i < path.length; i++) { | 118 for (var i = 0; i < path.length; i++) { |
119 n = path[i]; | 119 n = path[i]; |
120 if (n.nodeType === Node.ELEMENT_NODE && n.hasAttribute('touch-action')
) { | 120 if (n.nodeType === Node.ELEMENT_NODE && n.hasAttribute('touch-action')
) { |
121 return n.getAttribute('touch-action'); | 121 return n.getAttribute('touch-action'); |
122 } | 122 } |
123 } | 123 } |
124 } else { | 124 } else { |
125 n = inEvent.target; | 125 n = inEvent.target; |
126 while(n) { | 126 while(n) { |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 var common = this.LCA(a, b); | 185 var common = this.LCA(a, b); |
186 // if a is the common ancestor, it must "deeply" contain b | 186 // if a is the common ancestor, it must "deeply" contain b |
187 return common === a; | 187 return common === a; |
188 }, | 188 }, |
189 insideNode: function(node, x, y) { | 189 insideNode: function(node, x, y) { |
190 var rect = node.getBoundingClientRect(); | 190 var rect = node.getBoundingClientRect(); |
191 return (rect.left <= x) && (x <= rect.right) && (rect.top <= y) && (y <= r
ect.bottom); | 191 return (rect.left <= x) && (x <= rect.right) && (rect.top <= y) && (y <= r
ect.bottom); |
192 }, | 192 }, |
193 path: function(event) { | 193 path: function(event) { |
194 var p; | 194 var p; |
195 if (HAS_FULL_PATH && event.path && event.path.length) { | 195 if (hasFullPath && event.path && event.path.length) { |
196 p = event.path; | 196 p = event.path; |
197 } else { | 197 } else { |
198 p = []; | 198 p = []; |
199 var n = this.findTarget(event); | 199 var n = this.findTarget(event); |
200 while (n) { | 200 while (n) { |
201 p.push(n); | 201 p.push(n); |
202 n = n.parentNode || n.host; | 202 n = n.parentNode || n.host; |
203 } | 203 } |
204 } | 204 } |
205 return p; | 205 return p; |
(...skipping 734 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
940 })(window.PolymerGestures); | 940 })(window.PolymerGestures); |
941 | 941 |
942 (function(scope) { | 942 (function(scope) { |
943 var dispatcher = scope.dispatcher; | 943 var dispatcher = scope.dispatcher; |
944 var pointermap = dispatcher.pointermap; | 944 var pointermap = dispatcher.pointermap; |
945 // radius around touchend that swallows mouse events | 945 // radius around touchend that swallows mouse events |
946 var DEDUP_DIST = 25; | 946 var DEDUP_DIST = 25; |
947 | 947 |
948 var WHICH_TO_BUTTONS = [0, 1, 4, 2]; | 948 var WHICH_TO_BUTTONS = [0, 1, 4, 2]; |
949 | 949 |
950 var CURRENT_BUTTONS = 0; | 950 var currentButtons = 0; |
951 | 951 |
952 var FIREFOX_LINUX = /Linux.*Firefox\//i; | 952 var FIREFOX_LINUX = /Linux.*Firefox\//i; |
953 | 953 |
954 var HAS_BUTTONS = (function() { | 954 var HAS_BUTTONS = (function() { |
955 // firefox on linux returns spec-incorrect values for mouseup.buttons | 955 // firefox on linux returns spec-incorrect values for mouseup.buttons |
956 // https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent.buttons#See_a
lso | 956 // https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent.buttons#See_a
lso |
957 // https://codereview.chromium.org/727593003/#msg16 | 957 // https://codereview.chromium.org/727593003/#msg16 |
958 if (FIREFOX_LINUX.test(navigator.userAgent)) { | 958 if (FIREFOX_LINUX.test(navigator.userAgent)) { |
959 return false; | 959 return false; |
960 } | 960 } |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1004 prepareEvent: function(inEvent) { | 1004 prepareEvent: function(inEvent) { |
1005 var e = dispatcher.cloneEvent(inEvent); | 1005 var e = dispatcher.cloneEvent(inEvent); |
1006 e.pointerId = this.POINTER_ID; | 1006 e.pointerId = this.POINTER_ID; |
1007 e.isPrimary = true; | 1007 e.isPrimary = true; |
1008 e.pointerType = this.POINTER_TYPE; | 1008 e.pointerType = this.POINTER_TYPE; |
1009 e._source = 'mouse'; | 1009 e._source = 'mouse'; |
1010 if (!HAS_BUTTONS) { | 1010 if (!HAS_BUTTONS) { |
1011 var type = inEvent.type; | 1011 var type = inEvent.type; |
1012 var bit = WHICH_TO_BUTTONS[inEvent.which] || 0; | 1012 var bit = WHICH_TO_BUTTONS[inEvent.which] || 0; |
1013 if (type === 'mousedown') { | 1013 if (type === 'mousedown') { |
1014 CURRENT_BUTTONS |= bit; | 1014 currentButtons |= bit; |
1015 } else if (type === 'mouseup') { | 1015 } else if (type === 'mouseup') { |
1016 CURRENT_BUTTONS &= ~bit; | 1016 currentButtons &= ~bit; |
1017 } | 1017 } |
1018 e.buttons = CURRENT_BUTTONS; | 1018 e.buttons = currentButtons; |
1019 } | 1019 } |
1020 return e; | 1020 return e; |
1021 }, | 1021 }, |
1022 mousedown: function(inEvent) { | 1022 mousedown: function(inEvent) { |
1023 if (!this.isEventSimulatedFromTouch(inEvent)) { | 1023 if (!this.isEventSimulatedFromTouch(inEvent)) { |
1024 var p = pointermap.has(this.POINTER_ID); | 1024 var p = pointermap.has(this.POINTER_ID); |
1025 var e = this.prepareEvent(inEvent); | 1025 var e = this.prepareEvent(inEvent); |
1026 e.target = scope.findTarget(inEvent); | 1026 e.target = scope.findTarget(inEvent); |
1027 pointermap.set(this.POINTER_ID, e.target); | 1027 pointermap.set(this.POINTER_ID, e.target); |
1028 dispatcher.down(e); | 1028 dispatcher.down(e); |
1029 } | 1029 } |
1030 }, | 1030 }, |
1031 mousemove: function(inEvent) { | 1031 mousemove: function(inEvent) { |
1032 if (!this.isEventSimulatedFromTouch(inEvent)) { | 1032 if (!this.isEventSimulatedFromTouch(inEvent)) { |
1033 var target = pointermap.get(this.POINTER_ID); | 1033 var target = pointermap.get(this.POINTER_ID); |
1034 if (target) { | 1034 if (target) { |
1035 var e = this.prepareEvent(inEvent); | 1035 var e = this.prepareEvent(inEvent); |
1036 e.target = target; | 1036 e.target = target; |
1037 // handle case where we missed a mouseup | 1037 // handle case where we missed a mouseup |
1038 if ((HAS_BUTTONS ? e.buttons : e.which) === 0) { | 1038 if ((HAS_BUTTONS ? e.buttons : e.which) === 0) { |
1039 if (!HAS_BUTTONS) { | 1039 if (!HAS_BUTTONS) { |
1040 CURRENT_BUTTONS = e.buttons = 0; | 1040 currentButtons = e.buttons = 0; |
1041 } | 1041 } |
1042 dispatcher.cancel(e); | 1042 dispatcher.cancel(e); |
1043 this.cleanupMouse(e.buttons); | 1043 this.cleanupMouse(e.buttons); |
1044 } else { | 1044 } else { |
1045 dispatcher.move(e); | 1045 dispatcher.move(e); |
1046 } | 1046 } |
1047 } | 1047 } |
1048 } | 1048 } |
1049 }, | 1049 }, |
1050 mouseup: function(inEvent) { | 1050 mouseup: function(inEvent) { |
(...skipping 2755 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3806 Object.defineProperty(scope, parentScopeName, | 3806 Object.defineProperty(scope, parentScopeName, |
3807 { value: parentScope, configurable: true, writable: true }); | 3807 { value: parentScope, configurable: true, writable: true }); |
3808 return scope; | 3808 return scope; |
3809 }; | 3809 }; |
3810 | 3810 |
3811 global.PolymerExpressions = PolymerExpressions; | 3811 global.PolymerExpressions = PolymerExpressions; |
3812 PolymerExpressions.getExpression = getExpression; | 3812 PolymerExpressions.getExpression = getExpression; |
3813 })(this); | 3813 })(this); |
3814 | 3814 |
3815 Polymer = { | 3815 Polymer = { |
3816 version: '0.5.1' | 3816 version: '0.5.4' |
3817 }; | 3817 }; |
3818 | 3818 |
3819 // TODO(sorvell): this ensures Polymer is an object and not a function | 3819 // TODO(sorvell): this ensures Polymer is an object and not a function |
3820 // Platform is currently defining it as a function to allow for async loading | 3820 // Platform is currently defining it as a function to allow for async loading |
3821 // of polymer; once we refine the loading process this likely goes away. | 3821 // of polymer; once we refine the loading process this likely goes away. |
3822 if (typeof window.Polymer === 'function') { | 3822 if (typeof window.Polymer === 'function') { |
3823 Polymer = {}; | 3823 Polymer = {}; |
3824 } | 3824 } |
3825 | 3825 |
3826 | 3826 |
(...skipping 2519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6346 } | 6346 } |
6347 | 6347 |
6348 var BIND = 'bind'; | 6348 var BIND = 'bind'; |
6349 var REPEAT = 'repeat'; | 6349 var REPEAT = 'repeat'; |
6350 var IF = 'if'; | 6350 var IF = 'if'; |
6351 | 6351 |
6352 var templateAttributeDirectives = { | 6352 var templateAttributeDirectives = { |
6353 'template': true, | 6353 'template': true, |
6354 'repeat': true, | 6354 'repeat': true, |
6355 'bind': true, | 6355 'bind': true, |
6356 'ref': true | 6356 'ref': true, |
| 6357 'if': true |
6357 }; | 6358 }; |
6358 | 6359 |
6359 var semanticTemplateElements = { | 6360 var semanticTemplateElements = { |
6360 'THEAD': true, | 6361 'THEAD': true, |
6361 'TBODY': true, | 6362 'TBODY': true, |
6362 'TFOOT': true, | 6363 'TFOOT': true, |
6363 'TH': true, | 6364 'TH': true, |
6364 'TR': true, | 6365 'TR': true, |
6365 'TD': true, | 6366 'TD': true, |
6366 'COLGROUP': true, | 6367 'COLGROUP': true, |
(...skipping 1137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7504 })(this); | 7505 })(this); |
7505 | 7506 |
7506 (function(scope) { | 7507 (function(scope) { |
7507 'use strict'; | 7508 'use strict'; |
7508 | 7509 |
7509 // feature detect for URL constructor | 7510 // feature detect for URL constructor |
7510 var hasWorkingUrl = false; | 7511 var hasWorkingUrl = false; |
7511 if (!scope.forceJURL) { | 7512 if (!scope.forceJURL) { |
7512 try { | 7513 try { |
7513 var u = new URL('b', 'http://a'); | 7514 var u = new URL('b', 'http://a'); |
7514 hasWorkingUrl = u.href === 'http://a/b'; | 7515 u.pathname = 'c%20d'; |
| 7516 hasWorkingUrl = u.href === 'http://a/c%20d'; |
7515 } catch(e) {} | 7517 } catch(e) {} |
7516 } | 7518 } |
7517 | 7519 |
7518 if (hasWorkingUrl) | 7520 if (hasWorkingUrl) |
7519 return; | 7521 return; |
7520 | 7522 |
7521 var relative = Object.create(null); | 7523 var relative = Object.create(null); |
7522 relative['ftp'] = 21; | 7524 relative['ftp'] = 21; |
7523 relative['file'] = 0; | 7525 relative['file'] = 0; |
7524 relative['gopher'] = 70; | 7526 relative['gopher'] = 70; |
(...skipping 782 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8307 urlPath = resolveRelativeUrl(baseUrl, urlPath, keepAbsolute); | 8309 urlPath = resolveRelativeUrl(baseUrl, urlPath, keepAbsolute); |
8308 return pre + '\'' + urlPath + '\'' + post; | 8310 return pre + '\'' + urlPath + '\'' + post; |
8309 }); | 8311 }); |
8310 } | 8312 } |
8311 | 8313 |
8312 function resolveRelativeUrl(baseUrl, url, keepAbsolute) { | 8314 function resolveRelativeUrl(baseUrl, url, keepAbsolute) { |
8313 // do not resolve '/' absolute urls | 8315 // do not resolve '/' absolute urls |
8314 if (url && url[0] === '/') { | 8316 if (url && url[0] === '/') { |
8315 return url; | 8317 return url; |
8316 } | 8318 } |
| 8319 // do not resolve '#' links, they are used for routing |
| 8320 if (url && url[0] === '#') { |
| 8321 return url; |
| 8322 } |
8317 var u = new URL(url, baseUrl); | 8323 var u = new URL(url, baseUrl); |
8318 return keepAbsolute ? u.href : makeDocumentRelPath(u.href); | 8324 return keepAbsolute ? u.href : makeDocumentRelPath(u.href); |
8319 } | 8325 } |
8320 | 8326 |
8321 function makeDocumentRelPath(url) { | 8327 function makeDocumentRelPath(url) { |
8322 var root = baseUrl(document.documentElement); | 8328 var root = baseUrl(document.documentElement); |
8323 var u = new URL(url, root); | 8329 var u = new URL(url, root); |
8324 if (u.host === root.host && u.port === root.port && | 8330 if (u.host === root.host && u.port === root.port && |
8325 u.protocol === root.protocol) { | 8331 u.protocol === root.protocol) { |
8326 return makeRelPath(root, u); | 8332 return makeRelPath(root, u); |
(...skipping 3515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11842 syntax.prepareBinding = function(pathString, name, node) { | 11848 syntax.prepareBinding = function(pathString, name, node) { |
11843 return events.prepareEventBinding(pathString, name, node) || | 11849 return events.prepareEventBinding(pathString, name, node) || |
11844 prepareBinding.call(syntax, pathString, name, node); | 11850 prepareBinding.call(syntax, pathString, name, node); |
11845 }; | 11851 }; |
11846 return syntax; | 11852 return syntax; |
11847 } | 11853 } |
11848 | 11854 |
11849 }); | 11855 }); |
11850 | 11856 |
11851 })(); | 11857 })(); |
OLD | NEW |