-
Notifications
You must be signed in to change notification settings - Fork 5
/
Tour.php
96 lines (78 loc) · 2.59 KB
/
Tour.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
/**
* Created by PhpStorm.
* User: rutger
* Date: 7/7/2015
* Time: 16:50
*/
namespace MyCademy\BootstrapTour;
use yii\base\Widget;
use yii\helpers\Json;
/**
* Class Tour
* @package MyCademy\BootstrapTour
*
* @property array $clientOptions the options for the underlying Bootstrap Tour JS plugin.
* Please refer to the corresponding [Bootstrap Tour plugin API](http://bootstraptour.com/api/) for possible options
*/
class Tour extends Widget
{
const START_MODE_NONE = 0; //Don't initialize or start the tour
const START_MODE_INIT_ONLY = 1; //Only initialize the tour
const START_MODE_DEFAULT = 2; //Initialize and start the tour
const START_MODE_FORCE_START = 3; //Initialize and force start the tour
/**
* @var string $name The javascript variable name used for the tour
*/
public $name = 'tour';
/**
* @var string $scope The scope used for the javascript variable, e.g. 'window'. Leave blank for local scope.
*/
public $scope;
/**
* @var int Start of the tour
*/
public $startMode = self::START_MODE_DEFAULT;
/**
* @var array the options for the underlying Bootstrap Tour JS plugin.
* Please refer to the corresponding [Bootstrap Tour plugin API](http://bootstraptour.com/api/) for possible options.
*/
protected $_clientOptions = [];
/**
* Renders the widget.
*/
public function run()
{
$view = $this->getView();
BootstrapTourPluginAsset::register($view);
if ($this->clientOptions !== false) {
$varName = $this->getVarName();
$options = empty($this->clientOptions) ? '' : Json::htmlEncode($this->clientOptions);
$js = "$varName = new Tour($options);\n";
if ($this->startMode >= self::START_MODE_INIT_ONLY)
$js .= "$varName.init();\n";
if ($this->startMode >= self::START_MODE_DEFAULT) {
$forced = $this->startMode >= self::START_MODE_FORCE_START ? 'true' : '';
$js .= "$varName.start($forced);\n";
}
$view->registerJs($js);
}
}
public function getVarName(){
return $this->scope ? $this->scope . '.' . $this->name : $this->name;
}
/**
* @return array
*/
public function getClientOptions()
{
return $this->_clientOptions;
}
/**
* @param array $clientOptions
*/
public function setClientOptions($clientOptions)
{
$this->_clientOptions = $clientOptions;
}
}