Skip to content

Commit

Permalink
Fix Gestures when using SD polyfill
Browse files Browse the repository at this point in the history
Test with SD polyfill and native ShadowDOM
Requires webcomponents/webcomponentsjs#434

Fixes #2641
  • Loading branch information
dfreedm committed Nov 4, 2015
1 parent 0dc69df commit 96e4bfa
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/standard/gestures.html
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,11 @@
handleNative: function(ev) {
var handled;
var type = ev.type;
var node = ev.currentTarget;
var node = wrap(ev.currentTarget);
var gobj = node[GESTURE_KEY];
if (!gobj) {
return;
}
var gs = gobj[type];
if (!gs) {
return;
Expand Down Expand Up @@ -292,6 +295,8 @@

// automate the event listeners for the native events
add: function(node, evType, handler) {
// SD polyfill: handle case where `node` is unwrapped, like `document`
node = wrap(node);
var recognizer = this.gestures[evType];
var deps = recognizer.deps;
var name = recognizer.name;
Expand Down Expand Up @@ -323,6 +328,8 @@

// automate event listener removal for native events
remove: function(node, evType, handler) {
// SD polyfill: handle case where `node` is unwrapped, like `document`
node = wrap(node);
var recognizer = this.gestures[evType];
var deps = recognizer.deps;
var name = recognizer.name;
Expand Down
1 change: 1 addition & 0 deletions test/runner.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
'unit/array-selector.html',
'unit/events.html',
'unit/gestures.html',
'unit/gestures.html?dom=shadow',
'unit/utils.html',
'unit/utils-content.html',
'unit/utils.html?dom=shadow',
Expand Down
25 changes: 25 additions & 0 deletions test/unit/gestures-elements.html
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,28 @@
});
</script>
</dom-module>

<dom-module id="x-document-listener">
<script>
Polymer({
is: 'x-document-listener',
properties: {
stream: {
type: Array,
value: function() {
return [];
}
}
},
setup: function() {
this.listen(document, 'down', 'handler');
},
teardown: function() {
this.unlisten(document, 'down', 'handler');
},
handler: function(e) {
this.stream.push(e);
}
});
</script>
</dom-module>
22 changes: 21 additions & 1 deletion test/unit/gestures.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<head>
<meta charset="utf-8">

<script src="../../../webcomponentsjs/webcomponents-lite.js"></script>
<script src="../../../webcomponentsjs/webcomponents.js"></script>
<script src="../../../web-component-tester/browser.js"></script>

<link rel="import" href="../../polymer.html">
Expand Down Expand Up @@ -386,6 +386,26 @@
});
});
});

suite('SD Polyfill', function() {
var el;
setup(function() {
el = document.createElement('x-document-listener');
document.body.appendChild(el);
el.setup();
});

teardown(function() {
el.teardown();
document.body.removeChild(el);
});

test('document listener works in SD polyfill', function() {
var ev = new CustomEvent('mousedown', {bubbles: true});
el.dispatchEvent(ev);
assert.equal(el.stream.length, 1);
});
});
</script>

</body>
Expand Down

0 comments on commit 96e4bfa

Please sign in to comment.