Skip to content
This repository has been archived by the owner on Sep 20, 2019. It is now read-only.

Commit

Permalink
Merge pull request #140 from webcomponents/fix-139
Browse files Browse the repository at this point in the history
Fixes #139
  • Loading branch information
Steve Orvell authored Apr 24, 2017
2 parents 4d2aad8 + c8178eb commit 1bb8d72
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 10 deletions.
11 changes: 6 additions & 5 deletions shadydom.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion shadydom.min.js.map

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions src/patch-builtins.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,13 @@ function getAssignedSlot(node) {

let windowMixin = {

addEventListener: addEventListener,
// NOTE: ensure these methods are bound to `window` so that `this` is correct
// when called directly from global context without a receiver; e.g.
// `addEventListener(...)`.
addEventListener: addEventListener.bind(window),

removeEventListener: removeEventListener.bind(window)

removeEventListener: removeEventListener
};

let nodeMixin = {
Expand Down
4 changes: 2 additions & 2 deletions src/patch-events.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ export function addEventListener(type, fnOrObj, optionsOrCapture) {
// hack to let ShadyRoots have event listeners
// event listener will be on host, but `currentTarget`
// will be set to shadyroot for event listener
let target = optionsOrCapture && optionsOrCapture.__shadyTarget || this;
let target = (optionsOrCapture && optionsOrCapture.__shadyTarget) || this;

if (fnOrObj.__eventWrappers) {
// Stop if the wrapper function has already been created.
Expand Down Expand Up @@ -392,7 +392,7 @@ export function removeEventListener(type, fnOrObj, optionsOrCapture) {
once = false;
passive = false;
}
let target = optionsOrCapture && optionsOrCapture.__shadyTarget || this;
let target = (optionsOrCapture && optionsOrCapture.__shadyTarget) || this;
// Search the wrapped function.
let wrapperFn = undefined;
if (fnOrObj.__eventWrappers) {
Expand Down
14 changes: 14 additions & 0 deletions tests/event-path.html
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,20 @@
el.parentNode.removeChild(el);
});

test('implicit window add/remove event listener', function() {
var el = createEnabledElement('x-event-scoped-window');
var listener = function(e) {
el.windowListenerEvents = el.windowListenerEvents ? el.windowListenerEvents+1 : 1;
};
addEventListener("composed", listener);
el.fireComposed();
assert.equal(1, el.windowListenerEvents);
removeEventListener("composed", listener);
el.fireComposed();
assert.equal(1, el.windowListenerEvents);
el.parentNode.removeChild(el);
});

test('scoped event does not reach window', function() {
var el = createEnabledElement('x-event-scoped-window');
el.fireScoped();
Expand Down

0 comments on commit 1bb8d72

Please sign in to comment.