Closed arjenmeijer closed 9 years ago
Not fully tested, but this should work:
$tour = new Tour([
'scope' => 'window', //Set scope to make the 'tour' variable global
'startMode' => Tour::START_MODE_INIT_ONLY, //Only initialize the tour
'clientOptions' => [
'steps' => [
[
'element' => "a.btn-success:parent",
'title' => "Step 1",
'content' => "Content of my step 1",
'backdrop' => true,
],
[
'element' => "a.navbar-brand",
'title' => "Step 2",
'content' => "Content of my step 2",
'backdrop' => true,
'backdropContainer' => "nav",
],
],
'onShown' => new JsExpression('function(tour){console.log("step " + tour.getCurrentStep())}'),
],
]);
$tour->run();
echo Html::button('Start the tour', [
'onclick' => $tour->getVarName().'.start(true);' //use $tour->getVarName() to get the reference to the javascript 'tour' var name
]);
This is just a quick example with a button, but it's better to use jQuery to handle the event.
I had to add use yii\web\JsExpression; After that is works! Thanks.
What is the best way to start Tour from a menu? First time, second time, etc.