3

Good day!

I just started using Bootstrap Tour on our project and I seem to like it because of its simple yet functional interface. But I just have one tiny issue - how do I get the elements being highlighted by the tour to be temporarily disabled?

For example, if the current highlight of the tour is on a set of buttons, is there a way so that the users will not be able to click them while on tour?

Any help would be much appreciated! :)

zessx
  • 68,042
  • 28
  • 135
  • 158
Israel Sato
  • 199
  • 1
  • 2
  • 12

4 Answers4

5

You can specify callback functions when a step is shown/hidden. In those functions, you've acces to the current element, and you can act on it (see the documentation : Tour Options) :

var tour = new Tour({
    onShown: function(tour) {
        var step = tour._steps[tour._current];
        $(step.element).attr('disabled', true);
    },
    onHidden: function(tour) {
        var step = tour._steps[tour._current];
        $(step.element).removeAttr('disabled');
    }
})
zessx
  • 68,042
  • 28
  • 135
  • 158
4

For me, the easiest way to accomplish this was using CSS.

You can apply CSS to your highligthed element:

.tour-NameOfYourTour-element {
    pointer-events: none;
}

This doesn't change anything visually, and clic don't work.

Romias
  • 13,783
  • 7
  • 56
  • 85
1

Using the same callback technique, I decided to overlay a div instead of add the disabled attribute to the step element. This works well when the backdrop is turned on and the element is not an input field (i.e. the disabled property takes no effect).

First the css for the overlay:

.tour-step-backdrop-parent {
    position: absolute;
    z-index: 1100;
}

And the code (updated to account for backdrop padding and absolute positioned step element):

onShown: function(tour) {
    var step = tour._options.steps[tour._current];

    /// Overlay a div on the tour contents to prevent clicking
    // Remove any existing overlay divs - accounting for shown event being called on window resize
    $(step.element).siblings('.tour-step-backdrop-parent').remove();
    // Create overlay div
    var disabledOverlay = $('<div class="tour-step-backdrop-parent"></div>');
    // Insert overlay div before step element in DOM
    $(step.element).before(disabledOverlay);
    // Account for step's backdrop padding if any (double it since it surrounds the element)
    var padding = (step.backdropPadding || 0) * 2;
    // Set size of the overlay div to the step element's size and account for rounding by adding 1 pixel
    disabledOverlay.outerHeight(stepElement.outerHeight() + padding + 1).outerWidth(stepElement.outerWidth() + padding + 1);
    // Set position based on element's position and adjust for backdrop padding
    var offset = stepElement.offset();console.log(offset);
    offset.top = offset.top - (step.backdropPadding || 0);
    offset.left = offset.left - (step.backdropPadding || 0);
    disabledOverlay.offset(offset);
},
onHidden: function(tour) {
    var step = tour._options.steps[tour._current];
    // Remove overlay div
    $(step.element).siblings('.tour-step-backdrop-parent').remove();
}
thenninger
  • 506
  • 3
  • 16
0

The API is updated, in v0.12.0 you can achieve the same functionality through the following code.

var tour = new Tour({
    onShown: function(tour) {
        var step = tour.getStep(tour._current);
        $(step.element).attr('disabled', true);
    },
    onHidden: function(tour) {
        var step = tour.getStep(tour._current);
        $(step.element).removeAttr('disabled');
    }
})

Credit goes to @zessx

Muaaz Khalid
  • 2,199
  • 2
  • 28
  • 51