-
-
Notifications
You must be signed in to change notification settings - Fork 651
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
cancelling the tour when clicking outside the element #141
Comments
This is what I did to allow:
First, I add a div to the page, the same size as the window: function addTourOverlay() {
if ($('#tour-overlay').length === 0) {
$('body').prepend('<div id="tour-overlay"></div>');
}
resizeOverlay();
}
function resizeOverlay() {
var window_height = $(window).height;
var window_width = $(window).width;
$('#tour-overlay').height(window_height).width(window_width);
} I style it like this: .shepherd-step {
z-index: 1000; }
#tour-overlay {
opacity: 0;
width: 100%;
height: 100%;
z-index: -9999;
position: fixed;
overflow: hidden;
left: 0;
top: 0; }
.shepherd-active #tour-overlay {
z-index: 998; }
.shepherd-active.shepherd-element-attached-middle #tour-overlay, .shepherd-active.shepherd-target-attached-middle #tour-overlay {
background-color: #1aa3dd;
opacity: 0.4; }
.shepherd-target.shepherd-enabled {
box-shadow: 0px 0px 0px 10000px rgba(26, 163, 221, 0.4), inset 0px 0px 2px rgba(26, 163, 221, 0.4);
position: relative;
z-index: 10; } This uses the CSS This is the elements' z-index order, sorted, from top to bottom:
This lets clicks outside the current tour step popup hit the targeted area (unfortunately, depending on your use case, this includes the currently-targeted element, so we can't just use it to isolate the current target). If nothing is being targeted, we make the overlay visible, so it functions as the translucent background. And then, to let clicks on the overlay with the overlay AND with the div, I do this: // Cancel the tour when users click outside the tour area.
$('body').on('click', '#tour-overlay', function() {
tour.cancel();
});
// Keyboard commands for interacting with the tour:
// cancel the tour when users hit escape.
// move to next item in tour when users hit right arrow.
// go back on left arrow.
document.onkeydown = function(evt) {
evt = evt || window.event;
var isEscape = false;
if ("key" in evt) {
isEscape = (evt.key == "Escape" || evt.key == "Esc");
} else {
isEscape = (evt.keyCode == 27);
}
if (isEscape) {
tour.cancel();
}
// this is not the escape key.
else {
// we only interact with the tour if the tour is active.
if ($('body.shepherd-active').length !== 0) {
// left arrow
if (evt.keyCode == '37') {
tour.back();
}
// right arrow
else if (evt.keyCode == '39') {
tour.next();
}
// // up arrow
// else if (evt.keyCode == '38') {
//
// }
// // down arrow
// else if (evt.keyCode == '40') {
//
// }
}
} |
I think this functionality is potentially outside the scope of Shepherd, and would be something you would want to implement in your app, as needed. If someone has a small idea and wants to try a PR we would definitely consider it! |
Do we have any native option for that? Using Shepherd or
tetherOptions
?What about typing the
Esc
key for that?Thanks in advance
The text was updated successfully, but these errors were encountered: