Bootstrap plugin overview
The components discussed in the previous Layout Components chapter are just the beginning. Bootstrap comes with 12 jQuery plug-ins, which extend the functionality and add more interactivity to the site. Even if you’re not an advanced JavaScript developer, you can start learning Bootstrap’s JavaScript plugin. Using the Bootstrap Data API, most plugins can be triggered without writing any code.
There are two ways for the site to reference the Bootstrap plug-in:
Separate reference: Use Bootstrap’s individual *.js document. Some plugins and CSS components depend on other plugins. If you reference plugins individually, make sure you understand the dependencies between those plugins first.
Compile (and simultaneously) reference : use bootstrap.js or the minified version of bootstrap.min.js.
Do not try to reference both files at the same time, because both bootstrap.js and bootstrap.min.js contain all plugins.
data attribute
You can use all Bootstrap plugins just through the data attribute API without writing a single line of JavaScript code. This is a first-class API in Bootstrap and should be your first choice.
Then again, there may be situations where this feature needs to be turned off. Therefore, we also provide a way to turn off the data attribute API, that is, to unblock the event bound to the document with the data-api namespace. Like the following:
- such as To close a specific plug-in, you only need to add the name of the plug-in as the namespace before the data-api namespace, as shown below:
All methods can accept an optional options object as a parameter, or a string representing a specific method, or without any parameters (in this case, the plug-in will be initialized to the default behavior), as shown below :
$("#myModal").modal()
// Initialized to not support the keyboard .modal({ keyboard: false })
// Initialize and call immediately show
$("#myModal").modal('show')
attribute also exposes its original constructor: $.fn.popover.Constructor. If you want to get an instance of a specific plug-in, you can get it directly through the page element:
$('[rel=popover]').data('popover').Sometimes Bootstrap plug-ins may need to be used with other UI frameworks. In this case, a namespace conflict may occur. If this unfortunately happens, you can restore its original value by calling the plugin's
.noConflictmethod.
// Return the value assigned before $.fn.button$.fn.bootstrapBtn = bootstrapButton
Bootstrap provides custom events for the unique behavior of most plugins. Generally speaking, these events come in two forms:
- verb infinitive
: This is triggered at the start of the event. For example ex: show. Infinitive events provide the preventDefault function. This makes it possible to stop the execution of an operation before the event starts.
})
- Past participle form
: This will happen after the action is executed is triggered. For example ex: shown.