Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Issue/89]- add onCapture setting to bubble events such as blur for tour elements… #233

Merged
merged 1 commit into from
Aug 31, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/js/bind.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ export function bindAdvance() {
const handler = _setupAdvanceOnHandler.call(this, selector);

// TODO: this should also bind/unbind on show/hide
if (!isUndefined(selector)) {
const el = document.querySelector(selector);
const el = document.querySelector(selector);
if (!isUndefined(selector) && el) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

event handlers lost on any selector that is null at the time, since the step might not be in the DOM yet.

el.addEventListener(event, handler);
} else {
document.body.addEventListener(event, handler);
document.body.addEventListener(event, handler, true);
}
this.on('destroy', () => {
return document.body.removeEventListener(event, handler);
return document.body.removeEventListener(event, handler, true);
});
}

Expand Down
22 changes: 22 additions & 0 deletions test/unit/test.step.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,28 @@ describe('Step', () => {
assert.isOk(advanced, 'next triggered for advanceOn');
});

it('should support bubbling events for nodes that do not exist yet', () => {
const event = new Event('blur');
let advanced = false;

const step = new Step({
next: () => advanced = true
}, {
text: ['Shepherd is a javascript library for guiding users through your app. It uses <a href="https://popper.js.org/">Popper.js</a>, another open source library, to position all of its steps.', 'Popper makes sure your steps never end up off screen or cropped by an overflow. Try resizing your browser to see what we mean.'],
advanceOn: {
selector: 'a[href="https://popper.js.org/"]',
event: 'blur'
}
});
step.el = document.body;
step.el.hidden = false;

step.bindAdvance();
document.body.dispatchEvent(event);

assert.isOk(advanced, 'next triggered for advanceOn');
});

it('it should call removeEventListener when destoryed', function(done){
const el = document.createElement('div');
const body = spy(document.body, 'removeEventListener');
Expand Down