Skip to content

Commit 27dd45d

Browse files
committed
removing the show delay for our toast plugin
1 parent 7d605f8 commit 27dd45d

File tree

4 files changed

+17
-63
lines changed

4 files changed

+17
-63
lines changed

js/src/toast.js

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,13 @@ const Toast = (($) => {
3838
const DefaultType = {
3939
animation : 'boolean',
4040
autohide : 'boolean',
41-
delay : '(number|object)'
41+
delay : 'number'
4242
}
4343

4444
const Default = {
4545
animation : true,
4646
autohide : true,
47-
delay : {
48-
show: 0,
49-
hide: 500
50-
}
47+
delay : 500
5148
}
5249

5350
const Selector = {
@@ -95,19 +92,16 @@ const Toast = (($) => {
9592
}
9693
}
9794

98-
this._timeout = setTimeout(() => {
99-
this._element.classList.add(ClassName.SHOW)
100-
101-
if (this._config.animation) {
102-
const transitionDuration = Util.getTransitionDurationFromElement(this._element)
95+
this._element.classList.add(ClassName.SHOW)
96+
if (this._config.animation) {
97+
const transitionDuration = Util.getTransitionDurationFromElement(this._element)
10398

104-
$(this._element)
105-
.one(Util.TRANSITION_END, complete)
106-
.emulateTransitionEnd(transitionDuration)
107-
} else {
108-
complete()
109-
}
110-
}, this._config.delay.show)
99+
$(this._element)
100+
.one(Util.TRANSITION_END, complete)
101+
.emulateTransitionEnd(transitionDuration)
102+
} else {
103+
complete()
104+
}
111105
}
112106

113107
hide(withoutTimeout) {
@@ -122,7 +116,7 @@ const Toast = (($) => {
122116
} else {
123117
this._timeout = setTimeout(() => {
124118
this._close()
125-
}, this._config.delay.hide)
119+
}, this._config.delay)
126120
}
127121
}
128122

@@ -150,13 +144,6 @@ const Toast = (($) => {
150144
...typeof config === 'object' && config ? config : {}
151145
}
152146

153-
if (typeof config.delay === 'number') {
154-
config.delay = {
155-
show: config.delay,
156-
hide: config.delay
157-
}
158-
}
159-
160147
Util.typeCheckConfig(
161148
NAME,
162149
config,

js/tests/unit/toast.js

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -184,28 +184,6 @@ $(function () {
184184
.bootstrapToast('show')
185185
})
186186

187-
QUnit.test('should allow to pass delay object in html', function (assert) {
188-
assert.expect(1)
189-
var done = assert.async()
190-
191-
var toastHtml =
192-
'<div class="toast" data-delay=\'{"show": 0, "hide": 1}\'>' +
193-
'<div class="toast-body">' +
194-
'a simple toast' +
195-
'</div>' +
196-
'</div>'
197-
198-
var $toast = $(toastHtml)
199-
.bootstrapToast()
200-
.appendTo($('#qunit-fixture'))
201-
202-
$toast.on('shown.bs.toast', function () {
203-
assert.strictEqual($toast.hasClass('show'), true)
204-
done()
205-
})
206-
.bootstrapToast('show')
207-
})
208-
209187
QUnit.test('should allow to config in js', function (assert) {
210188
assert.expect(1)
211189
var done = assert.async()
@@ -219,10 +197,7 @@ $(function () {
219197

220198
var $toast = $(toastHtml)
221199
.bootstrapToast({
222-
delay: {
223-
show: 0,
224-
hide: 1
225-
}
200+
delay: 1
226201
})
227202
.appendTo($('#qunit-fixture'))
228203

js/tests/visual/toast.html

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ <h1>Toast <small>Bootstrap Visual Test</small></h1>
2626
</div>
2727

2828
<div class="notifications">
29-
<div id="toastAutoHide" class="toast" role="alert" aria-live="assertive" aria-atomic="true">
29+
<div id="toastAutoHide" class="toast" role="alert" aria-live="assertive" aria-atomic="true" data-delay="2000">
3030
<div class="toast-header">
3131
<img class="rounded mr-2" data-src="holder.js/20x20?size=1&text=.&bg=#007aff" alt="">
3232
<strong class="mr-auto">Bootstrap</strong>
@@ -60,10 +60,6 @@ <h1>Toast <small>Bootstrap Visual Test</small></h1>
6060
<script src="../../dist/toast.js"></script>
6161
<script>
6262
$(function () {
63-
$('#toastAutoHide').attr('data-delay', JSON.stringify({
64-
show: 0,
65-
hide: 2000
66-
}))
6763
$('.toast').toast()
6864

6965
$('#btnShowToast').on('click', function () {

site/docs/4.1/components/toasts.md

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -242,15 +242,11 @@ Options can be passed via data attributes or JavaScript. For data attributes, ap
242242
</tr>
243243
<tr>
244244
<td>delay</td>
245-
<td>number | object</td>
245+
<td>number</td>
246246
<td>
247-
<code>{ show: 0, hide: 500 }</code>
248-
</td>
249-
<td>
250-
<p>Delay showing and hiding the toast (ms)</p>
251-
<p>If a number is supplied, delay is applied to both hide/show</p>
252-
<p>Object structure is: <code>delay: { "show": 500, "hide": 100 }</code></p>
247+
<code>500</code>
253248
</td>
249+
<td>Delay hiding the toast (ms)</td>
254250
</tr>
255251
</tbody>
256252
</table>

0 commit comments

Comments
 (0)