MyCademy / yii2-bootstrap-tour

Yii 2 Bootstrap Tour Extension
Apache License 2.0
3 stars 5 forks source link

Start from a menu #4

Closed arjenmeijer closed 9 years ago

arjenmeijer commented 9 years ago

What is the best way to start Tour from a menu? First time, second time, etc.

rhertogh commented 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.

arjenmeijer commented 9 years ago

I had to add use yii\web\JsExpression; After that is works! Thanks.