diff options
author | Pierre Vanduynslager <pierre.denis.vanduynslager@gmail.com> | 2017-03-29 00:43:16 +0300 |
---|---|---|
committer | Johann-S <johann.servoire@gmail.com> | 2017-03-29 00:43:15 +0300 |
commit | 48c5efa4c3c439d8720b8475ec3e372c6974a12a (patch) | |
tree | 927c262f444f4aaeb0f598cf35ab7b1b385ae76a /docs | |
parent | ce0e2f8e76dade4b6ec9d6eb541c6988739f0653 (diff) |
Fix JS components console error "Error: <Component> is transitioning"
Diffstat (limited to 'docs')
-rw-r--r-- | docs/_includes/callout-danger-async-methods.md | 7 | ||||
-rw-r--r-- | docs/components/carousel.md | 9 | ||||
-rw-r--r-- | docs/components/collapse.md | 9 | ||||
-rw-r--r-- | docs/components/modal.md | 3 | ||||
-rw-r--r-- | docs/components/navs.md | 3 | ||||
-rw-r--r-- | docs/components/popovers.md | 3 | ||||
-rw-r--r-- | docs/components/tooltips.md | 3 | ||||
-rw-r--r-- | docs/getting-started/javascript.md | 55 |
8 files changed, 69 insertions, 23 deletions
diff --git a/docs/_includes/callout-danger-async-methods.md b/docs/_includes/callout-danger-async-methods.md new file mode 100644 index 0000000000..f7a76aa4d3 --- /dev/null +++ b/docs/_includes/callout-danger-async-methods.md @@ -0,0 +1,7 @@ +{% callout danger %} +#### Asynchronous methods and transitions + +All API methods are **asynchronous** and start a **transition**. They returns to the caller as soon as the transition is started but **before it ends**. In addition, a method call on a **transitioning component will be ignored**. + +[See our Javascript documentation for more informations.]({{ site.baseurl }}/getting-started/javascript/#content) +{% endcallout %} diff --git a/docs/components/carousel.md b/docs/components/carousel.md index 5649dfac9a..405aee18cb 100644 --- a/docs/components/carousel.md +++ b/docs/components/carousel.md @@ -229,6 +229,9 @@ Options can be passed via data attributes or JavaScript. For data attributes, ap ### Methods +{% capture callout-include %}{% include callout-danger-async-methods.md %}{% endcapture %} +{{ callout-include | markdownify }} + #### `.carousel(options)` Initializes the carousel with an optional options `object` and starts cycling through items. @@ -249,15 +252,15 @@ Stops the carousel from cycling through items. #### `.carousel(number)` -Cycles the carousel to a particular frame (0 based, similar to an array). +Cycles the carousel to a particular frame (0 based, similar to an array). **Returns to the caller before the target item has been shown** (i.e. before the `slid.bs.carousel` event occurs). #### `.carousel('prev')` -Cycles to the previous item. +Cycles to the previous item. **Returns to the caller before the previous item has been shown** (i.e. before the `slid.bs.carousel` event occurs). #### `.carousel('next')` -Cycles to the next item. +Cycles to the next item. **Returns to the caller before the next item has been shown** (i.e. before the `slid.bs.carousel` event occurs). ### Events diff --git a/docs/components/collapse.md b/docs/components/collapse.md index 370cb760ef..0a49db562f 100644 --- a/docs/components/collapse.md +++ b/docs/components/collapse.md @@ -178,6 +178,9 @@ Options can be passed via data attributes or JavaScript. For data attributes, ap ### Methods +{% capture callout-include %}{% include callout-danger-async-methods.md %}{% endcapture %} +{{ callout-include | markdownify }} + #### `.collapse(options)` Activates your content as a collapsible element. Accepts an optional options `object`. @@ -190,15 +193,15 @@ $('#myCollapsible').collapse({ #### `.collapse('toggle')` -Toggles a collapsible element to shown or hidden. +Toggles a collapsible element to shown or hidden. **Returns to the caller before the collapsible element has actually been shown or hidden (i.e. before the `shown.bs.collapse` or `hidden.bs.collapse` event occurs). #### `.collapse('show')` -Shows a collapsible element. +Shows a collapsible element. **Returns to the caller before the collapsible element has actually been shown** (i.e. before the `shown.bs.collapse` event occurs). #### `.collapse('hide')` -Hides a collapsible element. +Hides a collapsible element. **Returns to the caller before the collapsible element has actually been hidden** (i.e. before the `hidden.bs.collapse` event occurs). ### Events diff --git a/docs/components/modal.md b/docs/components/modal.md index a4e28bcec5..19254b8808 100644 --- a/docs/components/modal.md +++ b/docs/components/modal.md @@ -547,6 +547,9 @@ Options can be passed via data attributes or JavaScript. For data attributes, ap ### Methods +{% capture callout-include %}{% include callout-danger-async-methods.md %}{% endcapture %} +{{ callout-include | markdownify }} + #### `.modal(options)` Activates your content as a modal. Accepts an optional options `object`. diff --git a/docs/components/navs.md b/docs/components/navs.md index 047eb22054..e47a5a9e6c 100644 --- a/docs/components/navs.md +++ b/docs/components/navs.md @@ -404,6 +404,9 @@ To make tabs fade in, add `.fade` to each `.tab-pane`. The first tab pane must a ### Methods +{% capture callout-include %}{% include callout-danger-async-methods.md %}{% endcapture %} +{{ callout-include | markdownify }} + #### $().tab Activates a tab element and content container. Tab should have either a `data-target` or an `href` targeting a container node in the DOM. diff --git a/docs/components/popovers.md b/docs/components/popovers.md index ec5b4970d3..5f26e4bbd3 100644 --- a/docs/components/popovers.md +++ b/docs/components/popovers.md @@ -277,6 +277,9 @@ Options for individual popovers can alternatively be specified through the use o ### Methods +{% capture callout-include %}{% include callout-danger-async-methods.md %}{% endcapture %} +{{ callout-include | markdownify }} + #### `$().popover(options)` Initializes popovers for an element collection. diff --git a/docs/components/tooltips.md b/docs/components/tooltips.md index eaab24da51..a8b251c09a 100644 --- a/docs/components/tooltips.md +++ b/docs/components/tooltips.md @@ -254,6 +254,9 @@ Options for individual tooltips can alternatively be specified through the use o ### Methods +{% capture callout-include %}{% include callout-danger-async-methods.md %}{% endcapture %} +{{ callout-include | markdownify }} + #### `$().tooltip(options)` Attaches a tooltip handler to an element collection. diff --git a/docs/getting-started/javascript.md b/docs/getting-started/javascript.md index b6a38fb7a2..d65fba0985 100644 --- a/docs/getting-started/javascript.md +++ b/docs/getting-started/javascript.md @@ -36,6 +36,18 @@ Alternatively, to target a specific plugin, just include the plugin's name as a $(document).off('.alert.data-api') {% endhighlight %} +## Events + +Bootstrap provides custom events for most plugins' unique actions. Generally, these come in an infinitive and past participle form - where the infinitive (ex. `show`) is triggered at the start of an event, and its past participle form (ex. `shown`) is triggered on the completion of an action. + +All infinitive events provide [`preventDefault()`](https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault) functionality. This provides the ability to stop the execution of an action before it starts. + +{% highlight js %} +$('#myModal').on('show.bs.modal', function (e) { + if (!data) return e.preventDefault() // stops modal from being shown +}) +{% endhighlight %} + ## Programmatic API We also believe you should be able to use all Bootstrap plugins purely through the JavaScript API. All public APIs are single, chainable methods, and return the collection acted upon. @@ -54,32 +66,41 @@ $('#myModal').modal('show') // initializes and invokes show immed Each plugin also exposes its raw constructor on a `Constructor` property: `$.fn.popover.Constructor`. If you'd like to get a particular plugin instance, retrieve it directly from an element: `$('[rel="popover"]').data('popover')`. -### Default settings -You can change the default settings for a plugin by modifying the plugin's `Constructor.DEFAULTS` object: +### Asynchronous functions and transitions + +All programmatic API methods are **asynchronous** and returns to the caller once the transition is started but **before it ends**. +In order to execute an action once the transition is complete, you can listen to the corresponding event. {% highlight js %} -$.fn.modal.Constructor.DEFAULTS.keyboard = false // changes default for the modal plugin's `keyboard` option to false +$('#myCollapse').on('shown.bs.collapse', function (e) { + // Action to execute once the collapsible area is expanded +}) {% endhighlight %} -## No conflict +In addition a method call on a **transitioning component will be ignored**. +{% highlight js %} +$('#myCarousel').on('slid.bs.carousel', function (e) { + $('#myCarousel').carousel('2') // Will slide to the slide 2 as soon as the transition to slide 1 is finished +}) -Sometimes it is necessary to use Bootstrap plugins with other UI frameworks. In these circumstances, namespace collisions can occasionally occur. If this happens, you may call `.noConflict` on the plugin you wish to revert the value of. +$('#myCarousel').carousel('1') // Will start sliding to the slide 1 and returns to the caller +$('#myCarousel').carousel('2') // !! Will be ignored, as the transition to the slide 1 is not finished !! +{% endhighlight %} + +### Default settings +You can change the default settings for a plugin by modifying the plugin's `Constructor.Default` object: {% highlight js %} -var bootstrapButton = $.fn.button.noConflict() // return $.fn.button to previously assigned value -$.fn.bootstrapBtn = bootstrapButton // give $().bootstrapBtn the Bootstrap functionality +$.fn.modal.Constructor.Default.keyboard = false // changes default for the modal plugin's `keyboard` option to false {% endhighlight %} -## Events - -Bootstrap provides custom events for most plugins' unique actions. Generally, these come in an infinitive and past participle form - where the infinitive (ex. `show`) is triggered at the start of an event, and its past participle form (ex. `shown`) is triggered on the completion of an action. +## No conflict -All infinitive events provide [`preventDefault()`](https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault) functionality. This provides the ability to stop the execution of an action before it starts. +Sometimes it is necessary to use Bootstrap plugins with other UI frameworks. In these circumstances, namespace collisions can occasionally occur. If this happens, you may call `.noConflict` on the plugin you wish to revert the value of. {% highlight js %} -$('#myModal').on('show.bs.modal', function (e) { - if (!data) return e.preventDefault() // stops modal from being shown -}) +var bootstrapButton = $.fn.button.noConflict() // return $.fn.button to previously assigned value +$.fn.bootstrapBtn = bootstrapButton // give $().bootstrapBtn the Bootstrap functionality {% endhighlight %} ## Version numbers @@ -100,8 +121,8 @@ Bootstrap's plugins don't fall back particularly gracefully when JavaScript is d **Bootstrap does not officially support third-party JavaScript libraries** like Prototype or jQuery UI. Despite `.noConflict` and namespaced events, there may be compatibility problems that you need to fix on your own. {% endcallout %} -## Transitions +## Util -For simple transition effects, include `transition.js` once alongside the other JS files. If you're using the compiled (or minified) `bootstrap.js`, there is no need to include this—it's already there. +All Bootstrap Javascript depend on `util.js` and it has to be included alongside the other JS files. If you're using the compiled (or minified) `bootstrap.js`, there is no need to include this—it's already there. -Transition.js is a basic helper for `transitionEnd` events as well as a CSS transition emulator. It's used by the other plugins to check for CSS transition support and to catch hanging transitions. +`util.js` includes utility functions and a basic helper for `transitionEnd` events as well as a CSS transition emulator. It's used by the other plugins to check for CSS transition support and to catch hanging transitions. |