sorich87 / bootstrap-tour

Quick and easy product tours with Twitter Bootstrap Popovers
http://bootstraptour.com
MIT License
4.44k stars 942 forks source link

Remove "End Tour" button until last step? #244

Closed aensley closed 10 years ago

aensley commented 10 years ago

I have a very specific scenario where I need to force users to go through every step of the tour before they can dismiss it. What is the best way to hide the "End Tour" button until the last step? Do I have to set the template for every step?

sorich87 commented 10 years ago

You can set a template globally.

s7anley commented 10 years ago

As @sorich87 wrote, you can set one global template and really easily determine last step: this.next === -1.

aensley commented 10 years ago

Thank you! Just what I needed.

sjorsvanheuveln commented 7 years ago

@aensley Could you give an example of how you have implemented this. I'm facing the same problem and I'm not sure how to implement this efficiently. Ty

aensley commented 7 years ago

Here's the basic example altered to hide the "End Tour" button until the last step:

// Instance the tour
var tour = new Tour({
    steps: [
        {
            element: "#my-element",
            title: "Title of my step",
            content: "Content of my step"
        },
        {
            element: "#my-other-element",
            title: "Title of my step",
            content: "Content of my step"
        }
    ],
    template: function () {
        return (
            this.next === -1 // Is this the last step?
                ? "<div class='popover tour'>" + // Yes.
                    "<div class='arrow'></div>" +
                    "<h3 class='popover-title'></h3>" +
                    "<div class='popover-content'></div>" +
                    "<div class='popover-navigation'>" +
                        "<button class='btn btn-default' data-role='prev'>« Prev</button>" +
                        "<span data-role='separator'> </span>" +
                        "<button class='btn btn-default' data-role='end'>End tour</button>" +
                    "</div>" +
                "</div>"
                : "<div class='popover tour'>" + // No.
                    "<div class='arrow'></div>" +
                    "<h3 class='popover-title'></h3>" +
                    "<div class='popover-content'></div>" +
                    "<div class='popover-navigation'>" +
                        "<button class='btn btn-default' data-role='prev'>« Prev</button>" +
                        "<span data-role='separator'> </span>" +
                        "<button class='btn btn-default' data-role='next'>Next »</button>" +
                    "</div>" +
                "</div>"
        );
    },
});

// Initialize the tour
tour.init();

// Start the tour
tour.start();
thomasdolberg commented 6 years ago

@aensley is there any way to only have the "Next" / "End Tour" buttons change instead of repeating the entire template?

aensley commented 6 years ago

Replying to https://github.com/sorich87/bootstrap-tour/issues/244#issuecomment-348759039 by @thomasdolberg:

Actually... yes.

// Instance the tour
var tour = new Tour({
    steps: [
        {
            element: "#my-element",
            title: "Title of my step",
            content: "Content of my step"
        },
        {
            element: "#my-other-element",
            title: "Title of my step",
            content: "Content of my step"
        }
    ],
    template: function () {
        return "<div class='popover tour'>" + // Yes.
                    "<div class='arrow'></div>" +
                    "<h3 class='popover-title'></h3>" +
                    "<div class='popover-content'></div>" +
                    "<div class='popover-navigation'>" +
                        "<button class='btn btn-default' data-role='prev'>« Prev</button>" +
                        "<span data-role='separator'> </span>" +
                        (this.next === -1 ? 
                            ? "<button class='btn btn-default' data-role='end'>End tour</button>"
                            : "<button class='btn btn-default' data-role='next'>Next »</button>") +
                    "</div>" +
                "</div>";
    },
});

// Initialize the tour
tour.init();

// Start the tour
tour.start();
sylviestephanies commented 6 years ago

this not work for me, this.next cannot be read

sylviestephanies commented 6 years ago

I figure out, change this.next to tour.getCurrentStep()