From 72b6de976134a06850e77a3d16b2cfb790419343 Mon Sep 17 00:00:00 2001 From: Johann-S Date: Thu, 23 Aug 2018 21:36:32 +0200 Subject: [PATCH] update toast documentation with the javascript part --- site/docs/4.1/components/toasts.md | 123 +++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) diff --git a/site/docs/4.1/components/toasts.md b/site/docs/4.1/components/toasts.md index df5d2e827e91..54e0a1c52cd1 100644 --- a/site/docs/4.1/components/toasts.md +++ b/site/docs/4.1/components/toasts.md @@ -8,6 +8,16 @@ toc: true Toasts are lightweight notifications designed to mimic the push notifications that have been popularized by mobile and desktop operating systems. They're built with flexbox, so they're easy to align and position. +## Overview + +Things to know when using the toast plugin: + +- If you're building our JavaScript from source, it [requires `util.js`]({{ site.baseurl }}/docs/{{ site.docs_version }}/getting-started/javascript/#util). +- Toast are opt-in for performance reasons, so **you must initialize them yourself**. +- Toast will auto hide if you do not specify `autohide: false` + +Got all that? Great, let's see how they work with some examples. + ## Examples A basic toast can include a header (though it doesn't strictly need one) with whatever contents you like. The header is also `display: flex`, so `.mr-auto` and `.ml-auto` can be used for easy pushing of content, as well as all our flexbox utilities. @@ -167,3 +177,116 @@ You can also get fancy with flexbox utilities. {% endcapture %} {% include example.html content=example %} + +## JavaScript behavior + +### Usage + +Initialize toasts via JavaScript: + +{% highlight js %} +$('.toast').toast(option) +{% endhighlight %} + +### Options + +Options can be passed via data attributes or JavaScript. For data attributes, append the option name to `data-`, as in `data-animation=""`. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDefaultDescription
animationbooleantrueApply a CSS fade transition to the toast
autohidebooleantrueAuto hide the toast
delaynumber | object + { show: 0, hide: 500 } + +

Delay showing and hiding the toast (ms)

+

If a number is supplied, delay is applied to both hide/show

+

Object structure is: delay: { "show": 500, "hide": 100 }

+
+ +### Methods + +{% include callout-danger-async-methods.md %} + +#### `$().toast(options)` + +Attaches a toast handler to an element collection. + +#### `.toast('show')` + +Reveals an element's toast. **Returns to the caller before the toast has actually been shown** (i.e. before the `shown.bs.toast` event occurs). +You have to manually call this method, instead your toast won't show. + +{% highlight js %}$('#element').toast('show'){% endhighlight %} + +#### `.toast('hide')` + +Hides an element's toast. **Returns to the caller before the toast has actually been hidden** (i.e. before the `hidden.bs.toast` event occurs). You have to manually call this method if you made `autohide` to `false`. + +{% highlight js %}$('#element').toast('hide'){% endhighlight %} + +#### `.toast('dispose')` + +Hides an element's toast. Your toast will remain on the DOM but won't show anymore. + +{% highlight js %}$('#element').toast('dispose'){% endhighlight %} + +### Events + + + + + + + + + + + + + + + + + + + + + + + + + + +
Event TypeDescription
show.bs.toastThis event fires immediately when the show instance method is called.
shown.bs.toastThis event is fired when the toast has been made visible to the user.
hide.bs.toastThis event is fired immediately when the hide instance method has been called.
hidden.bs.toastThis event is fired when the toast has finished being hidden from the user.
+ +{% highlight js %} +$('#myToast').on('hidden.bs.toast', function () { + // do something… +}) +{% endhighlight %}