Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Bootstrap Plugins Overview

Bootstrap Plugins Overview

In the previous Layout widgets chapter, the components discussed are just the beginning. Bootstrap comes with 12 jQuery plugins that extend functionality and add more interactivity to a site. Even if you are not an advanced JavaScript developer, you can start learning Bootstrap's JavaScript plugins. With the Bootstrap Data API (Bootstrap Data API), most plugins can be triggered without writing any code.

There are two ways for a site to reference Bootstrap plugins:

All plugins depend on jQuery, so jQuery must be included before the plugin files. Please visit bower.json to see the jQuery versions currently supported by Bootstrap.

The data attribute

- To disable a specific plugin, simply prefix the data-api namespace with the plugin's name as the namespace, as shown below:
$(document).off('.alert.data-api')

Programmatic API

We provide a pure JavaScript API for all Bootstrap plugins. All public APIs support individual or chained calls and return the collection of elements they operate on (note: consistent with jQuery's calling style). For example:



$(".btn.danger").button("toggle").addClass("fat")

All methods can accept an optional options object as a parameter, or a string representing a specific method, or no parameters at all (in which case the plugin is initialized with default behavior), as shown below:



// Initialize to default behavior

$("#myModal").modal()    

 // Initialize as keyboard unsupported

$("#myModal").modal({ keyboard: false })  

// Initialize and immediately call show

$("#myModal").modal('show')                

Each plugin also exposes its raw constructor on the Constructor property:$.fn.popover.Constructor. If you want to get an instance of a specific plugin, you can get it directly through the page element:



 $('[rel=popover]').data('popover').

Avoiding Namespace Conflicts

Sometimes Bootstrap plugins may need to be used together with other UI frameworks. In such cases, namespace conflicts may occur. If this unfortunately happens, you can call the plugin's .noConflict method to restore its original value.



// Return the value assigned before $.fn.button

var bootstrapButton = $.fn.button.noConflict() 

// Assign Bootstrap functionality to $().bootstrapBtn

$.fn.bootstrapBtn = bootstrapButton            

Events

Bootstrap provides custom events for the unique behaviors of most plugins. Generally, these events come in two forms:

- **Past Participle Form**: this is triggered after the action has been executed. For example *ex: shown*.