mirror of
https://github.com/twbs/bootstrap.git
synced 2024-12-01 13:24:25 +01:00
Remove the show delay for our toast plugin
This commit is contained in:
parent
4cac833447
commit
557d5ac74d
@ -38,16 +38,13 @@ const Toast = (($) => {
|
|||||||
const DefaultType = {
|
const DefaultType = {
|
||||||
animation : 'boolean',
|
animation : 'boolean',
|
||||||
autohide : 'boolean',
|
autohide : 'boolean',
|
||||||
delay : '(number|object)'
|
delay : 'number'
|
||||||
}
|
}
|
||||||
|
|
||||||
const Default = {
|
const Default = {
|
||||||
animation : true,
|
animation : true,
|
||||||
autohide : true,
|
autohide : true,
|
||||||
delay : {
|
delay : 500
|
||||||
show: 0,
|
|
||||||
hide: 500
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const Selector = {
|
const Selector = {
|
||||||
@ -95,19 +92,16 @@ const Toast = (($) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this._timeout = setTimeout(() => {
|
this._element.classList.add(ClassName.SHOW)
|
||||||
this._element.classList.add(ClassName.SHOW)
|
if (this._config.animation) {
|
||||||
|
const transitionDuration = Util.getTransitionDurationFromElement(this._element)
|
||||||
|
|
||||||
if (this._config.animation) {
|
$(this._element)
|
||||||
const transitionDuration = Util.getTransitionDurationFromElement(this._element)
|
.one(Util.TRANSITION_END, complete)
|
||||||
|
.emulateTransitionEnd(transitionDuration)
|
||||||
$(this._element)
|
} else {
|
||||||
.one(Util.TRANSITION_END, complete)
|
complete()
|
||||||
.emulateTransitionEnd(transitionDuration)
|
}
|
||||||
} else {
|
|
||||||
complete()
|
|
||||||
}
|
|
||||||
}, this._config.delay.show)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
hide(withoutTimeout) {
|
hide(withoutTimeout) {
|
||||||
@ -122,7 +116,7 @@ const Toast = (($) => {
|
|||||||
} else {
|
} else {
|
||||||
this._timeout = setTimeout(() => {
|
this._timeout = setTimeout(() => {
|
||||||
this._close()
|
this._close()
|
||||||
}, this._config.delay.hide)
|
}, this._config.delay)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -150,13 +144,6 @@ const Toast = (($) => {
|
|||||||
...typeof config === 'object' && config ? config : {}
|
...typeof config === 'object' && config ? config : {}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof config.delay === 'number') {
|
|
||||||
config.delay = {
|
|
||||||
show: config.delay,
|
|
||||||
hide: config.delay
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Util.typeCheckConfig(
|
Util.typeCheckConfig(
|
||||||
NAME,
|
NAME,
|
||||||
config,
|
config,
|
||||||
|
@ -184,28 +184,6 @@ $(function () {
|
|||||||
.bootstrapToast('show')
|
.bootstrapToast('show')
|
||||||
})
|
})
|
||||||
|
|
||||||
QUnit.test('should allow to pass delay object in html', function (assert) {
|
|
||||||
assert.expect(1)
|
|
||||||
var done = assert.async()
|
|
||||||
|
|
||||||
var toastHtml =
|
|
||||||
'<div class="toast" data-delay=\'{"show": 0, "hide": 1}\'>' +
|
|
||||||
'<div class="toast-body">' +
|
|
||||||
'a simple toast' +
|
|
||||||
'</div>' +
|
|
||||||
'</div>'
|
|
||||||
|
|
||||||
var $toast = $(toastHtml)
|
|
||||||
.bootstrapToast()
|
|
||||||
.appendTo($('#qunit-fixture'))
|
|
||||||
|
|
||||||
$toast.on('shown.bs.toast', function () {
|
|
||||||
assert.strictEqual($toast.hasClass('show'), true)
|
|
||||||
done()
|
|
||||||
})
|
|
||||||
.bootstrapToast('show')
|
|
||||||
})
|
|
||||||
|
|
||||||
QUnit.test('should allow to config in js', function (assert) {
|
QUnit.test('should allow to config in js', function (assert) {
|
||||||
assert.expect(1)
|
assert.expect(1)
|
||||||
var done = assert.async()
|
var done = assert.async()
|
||||||
@ -219,10 +197,7 @@ $(function () {
|
|||||||
|
|
||||||
var $toast = $(toastHtml)
|
var $toast = $(toastHtml)
|
||||||
.bootstrapToast({
|
.bootstrapToast({
|
||||||
delay: {
|
delay: 1
|
||||||
show: 0,
|
|
||||||
hide: 1
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.appendTo($('#qunit-fixture'))
|
.appendTo($('#qunit-fixture'))
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="notifications">
|
<div class="notifications">
|
||||||
<div id="toastAutoHide" class="toast" role="alert" aria-live="assertive" aria-atomic="true">
|
<div id="toastAutoHide" class="toast" role="alert" aria-live="assertive" aria-atomic="true" data-delay="2000">
|
||||||
<div class="toast-header">
|
<div class="toast-header">
|
||||||
<img class="rounded mr-2" data-src="holder.js/20x20?size=1&text=.&bg=#007aff" alt="">
|
<img class="rounded mr-2" data-src="holder.js/20x20?size=1&text=.&bg=#007aff" alt="">
|
||||||
<strong class="mr-auto">Bootstrap</strong>
|
<strong class="mr-auto">Bootstrap</strong>
|
||||||
@ -60,10 +60,6 @@
|
|||||||
<script src="../../dist/toast.js"></script>
|
<script src="../../dist/toast.js"></script>
|
||||||
<script>
|
<script>
|
||||||
$(function () {
|
$(function () {
|
||||||
$('#toastAutoHide').attr('data-delay', JSON.stringify({
|
|
||||||
show: 0,
|
|
||||||
hide: 2000
|
|
||||||
}))
|
|
||||||
$('.toast').toast()
|
$('.toast').toast()
|
||||||
|
|
||||||
$('#btnShowToast').on('click', function () {
|
$('#btnShowToast').on('click', function () {
|
||||||
|
@ -242,15 +242,11 @@ Options can be passed via data attributes or JavaScript. For data attributes, ap
|
|||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>delay</td>
|
<td>delay</td>
|
||||||
<td>number | object</td>
|
<td>number</td>
|
||||||
<td>
|
<td>
|
||||||
<code>{ show: 0, hide: 500 }</code>
|
<code>500</code>
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
<p>Delay showing and hiding the toast (ms)</p>
|
|
||||||
<p>If a number is supplied, delay is applied to both hide/show</p>
|
|
||||||
<p>Object structure is: <code>delay: { "show": 500, "hide": 100 }</code></p>
|
|
||||||
</td>
|
</td>
|
||||||
|
<td>Delay hiding the toast (ms)</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
Loading…
Reference in New Issue
Block a user