1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace diecoding\toastr; |
4
|
|
|
|
5
|
|
|
use yii\base\Widget; |
6
|
|
|
use yii\helpers\ArrayHelper; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* ToastrBase is the base class for widgets. |
10
|
|
|
* |
11
|
|
|
* @link [sugeng-sulistiyawan.github.io](sugeng-sulistiyawan.github.io) |
12
|
|
|
* @author Sugeng Sulistiyawan <[email protected]> |
13
|
|
|
* @copyright Copyright (c) 2023 |
14
|
|
|
*/ |
15
|
|
|
class ToastrBase extends Widget |
16
|
|
|
{ |
17
|
|
|
const TYPE_INFO = "info"; |
18
|
|
|
const TYPE_ERROR = "error"; |
19
|
|
|
const TYPE_SUCCESS = "success"; |
20
|
|
|
const TYPE_WARNING = "warning"; |
21
|
|
|
|
22
|
|
|
const POSITION_TOP_RIGHT = "toast-top-right"; |
23
|
|
|
const POSITION_TOP_LEFT = "toast-top-left"; |
24
|
|
|
const POSITION_TOP_CENTER = "toast-top-center"; |
25
|
|
|
const POSITION_TOP_FULL_WIDTH = "toast-top-full-width"; |
26
|
|
|
|
27
|
|
|
const POSITION_BOTTOM_RIGHT = "toast-bottom-right"; |
28
|
|
|
const POSITION_BOTTOM_LEFT = "toast-bottom-left"; |
29
|
|
|
const POSITION_BOTTOM_CENTER = "toast-bottom-center"; |
30
|
|
|
const POSITION_BOTTOM_FULL_WIDTH = "toast-bottom-full-width"; |
31
|
|
|
|
32
|
|
|
const TYPES = [ |
33
|
|
|
self::TYPE_INFO, |
34
|
|
|
self::TYPE_ERROR, |
35
|
|
|
self::TYPE_SUCCESS, |
36
|
|
|
self::TYPE_WARNING, |
37
|
|
|
]; |
38
|
|
|
|
39
|
|
|
const POSITIONS = [ |
40
|
|
|
self::POSITION_TOP_RIGHT, |
41
|
|
|
self::POSITION_TOP_LEFT, |
42
|
|
|
self::POSITION_TOP_CENTER, |
43
|
|
|
self::POSITION_TOP_FULL_WIDTH, |
44
|
|
|
|
45
|
|
|
self::POSITION_BOTTOM_RIGHT, |
46
|
|
|
self::POSITION_BOTTOM_LEFT, |
47
|
|
|
self::POSITION_BOTTOM_CENTER, |
48
|
|
|
self::POSITION_BOTTOM_FULL_WIDTH, |
49
|
|
|
]; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @var string default `self::TYPE_INFO` |
53
|
|
|
*/ |
54
|
|
|
public $typeDefault = self::TYPE_INFO; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @var string default `""` |
58
|
|
|
*/ |
59
|
|
|
public $titleDefault = ""; |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @var string default `""` |
63
|
|
|
*/ |
64
|
|
|
public $messageDefault = ""; |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @var bool default `false` |
68
|
|
|
*/ |
69
|
|
|
public $closeButton = false; |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @var bool default `false` |
73
|
|
|
*/ |
74
|
|
|
public $debug = false; |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @var bool default `true` |
78
|
|
|
*/ |
79
|
|
|
public $newestOnTop = true; |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @var bool default `true` |
83
|
|
|
*/ |
84
|
|
|
public $progressBar = true; |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @var string default `self::POSITION_TOP_RIGHT` |
88
|
|
|
*/ |
89
|
|
|
public $positionClass = self::POSITION_TOP_RIGHT; |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @var bool default `true` |
93
|
|
|
*/ |
94
|
|
|
public $preventDuplicates = true; |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @var int|null default `300` in `ms`, `null` for skip |
98
|
|
|
*/ |
99
|
|
|
public $showDuration = 300; |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @var int|null default `1000` in `ms`, `null` for skip |
103
|
|
|
*/ |
104
|
|
|
public $hideDuration = 1000; |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @var int|null default `5000` in `ms`, `null` for skip |
108
|
|
|
*/ |
109
|
|
|
public $timeOut = 5000; |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @var int|null default `1000` in `ms`, `null` for skip |
113
|
|
|
*/ |
114
|
|
|
public $extendedTimeOut = 1000; |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* @var string default `swing`, `swing` and `linear` are built into jQuery |
118
|
|
|
*/ |
119
|
|
|
public $showEasing = "swing"; |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* @var string default `swing`, `swing` and `linear` are built into jQuery |
123
|
|
|
*/ |
124
|
|
|
public $hideEasing = "swing"; |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @var string default `slideDown`, `fadeIn`, `slideDown`, and `show` are built into jQuery |
128
|
|
|
*/ |
129
|
|
|
public $showMethod = "slideDown"; |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* @var string default `slideUp`, `hide`, `fadeOut` and `slideUp` are built into jQuery |
133
|
|
|
*/ |
134
|
|
|
public $hideMethod = "slideUp"; |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* @var bool default `true` |
138
|
|
|
*/ |
139
|
|
|
public $tapToDismiss = true; |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* @var bool default `true` |
143
|
|
|
*/ |
144
|
|
|
public $escapeHtml = true; |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* @var bool default `false` |
148
|
|
|
*/ |
149
|
|
|
public $rtl = false; |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* @var bool default `false`, `true` if use custom or external toastr assets |
153
|
|
|
*/ |
154
|
|
|
public $skipCoreAssets = false; |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* @var bool default `false`, `true` if use custom or external toastr assets |
158
|
|
|
* @deprecated since 1.2.0. Use `$skipCoreAssets` instead, this method will be removed in 2.0.0. |
159
|
|
|
*/ |
160
|
|
|
public $useCustomAssets; |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* @var array default `[]`, Custom Toastr options and override default options |
164
|
|
|
*/ |
165
|
|
|
public $options = []; |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* @inheritdoc |
169
|
|
|
*/ |
170
|
|
|
public function init() |
171
|
|
|
{ |
172
|
|
|
// add alias for old support |
173
|
|
|
$this->skipCoreAssets = $this->skipCoreAssets !== true && $this->useCustomAssets !== null ? $this->useCustomAssets : $this->skipCoreAssets; |
|
|
|
|
174
|
|
|
if ($this->skipCoreAssets === false) { |
175
|
|
|
$this->view->registerAssetBundle(ToastrAsset::class); |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
$this->options = ArrayHelper::merge([ |
179
|
|
|
"closeButton" => $this->closeButton, |
180
|
|
|
"debug" => $this->debug, |
181
|
|
|
"newestOnTop" => $this->newestOnTop, |
182
|
|
|
"progressBar" => $this->progressBar, |
183
|
|
|
"positionClass" => $this->positionClass, |
184
|
|
|
"preventDuplicates" => $this->preventDuplicates, |
185
|
|
|
"showDuration" => $this->showDuration, |
186
|
|
|
"hideDuration" => $this->hideDuration, |
187
|
|
|
"timeOut" => $this->timeOut, |
188
|
|
|
"extendedTimeOut" => $this->extendedTimeOut, |
189
|
|
|
"showEasing" => $this->showEasing, |
190
|
|
|
"hideEasing" => $this->hideEasing, |
191
|
|
|
"showMethod" => $this->showMethod, |
192
|
|
|
"hideMethod" => $this->hideMethod, |
193
|
|
|
"tapToDismiss" => $this->tapToDismiss, |
194
|
|
|
"escapeHtml" => $this->escapeHtml, |
195
|
|
|
"rtl" => $this->rtl, |
196
|
|
|
], $this->options); |
197
|
|
|
|
198
|
|
|
parent::init(); |
199
|
|
|
} |
200
|
|
|
} |
201
|
|
|
|
This property has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.