Just like the customization for components, it is also possible to customize the behavior of the Bootstrap plugins.
To illustrate that, let's consider the Bootstrap Modal. This plugin is one of the most used among the others. The Modal is able to create a separated flow in your web page without changing the context.
Let's create an input and a button and make the button open the modal when clicked. What we are expecting here is when the user inputs the GitHub username at the input, we will get the info in the GitHub open API and show some basic info at the Modal. For this, create the following code in the sandbox page:
<!-- Button trigger modal -->
<input id="github-username" type="text" class="form-control" placeholder="Type your github username here">
<button type="button" class="btn btn-success btn-lg btn-block" data-toggle="modal" data-target="#githubModal">
Launch demo modal
</button>
<!-- Modal -->
<div class="modal fade" id="githubModal" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title"></h4>
</div>
<div class="modal-body">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-success">Save changes</button>
</div>
</div>
</div>
</div>Refresh the web page and you will see the input followed by a button. When you click on it, the Modal will show. The Modal is completely empty; to interact with that, we will play with some JavaScript.
In the code, let's use the Bootstrap event show.bs.modal, which will be triggered whenever a Modal is shown (like we discussed previously):
$('#githubModal).on('show.bs.modal', function (e) {
var $element = $(this),
url = 'https://api.github.com/users/{username}';
});Inside the function, we defined two variables. The $element corresponds to the triggered element, in this case it is the modal #githubModal. The url is the endpoint for the GitHub API. We will replace the {username} parameter on the string based on the text passed at the input by doing that:
$('#githubModal).on('show.bs.modal', function (e) {
var $element = $(this),
url = 'https://api.github.com/users/{username}';
url = url.replace(/{username}/, $('#github-username').val());
});Then, we must make a request to the API to retrieve the user info. To do so, we must make a GET request to the API, which will return us a JSON.
To make it clear, JSON is an open standard format to transmit data as a set of key-values. It is widely used to transfer data from web services and APIs, such as GitHub.
Moving on, to make the request to the server, we use the function $.get from jQuery. Pass a URL and a callback function with the JSON data object returned from the server:
$('#githubModal').on('show.bs.modal', function (e) {
var $element = $(this),
url = 'https://api.github.com/users/{username}';
$.get(url, function(data) {
console.log(data);
});
});If everything is working so far, refresh your web browser, type your username on the input, and click on the button. After the modal opens, check your console terminal and you must see the data from the request, as shown in the following screenshot:

Now, it would be good if we parse the data and displayed some information on the modal. For that, let's use the same principle for replace the url variable. Along with the variables, let's add other ones related to the template.
We want to create a template with two columns, the left one the user avatar image from the object and some basic info on the right. So, add the highlighted lines in your JavaScript:
$('#githubModal').on('show.bs.modal', function (e) {
var $element = $(this),
url = 'https://api.github.com/users/{username}',
title = 'Hi, my name is {name}',
content = '' +
'<div class="row">' +
'<img src="{img}" class="col-sm-3">' +
'<p class="col-sm-9" id="bio">{bio}</p>' +
'</div>',
bio = '' +
'At moment I have {publicRepo} public repos ' +
'and {followers} followers.\n' +
'I joined Github on {dateJoin}';
$.get(url, function(data) {
console.log(data);
});
});Here, we created three template variables that we will replace with the data from the get request. Inside the get function, let's replace the variables and create our final template.
The principle is the same as what we applied to the url, just replace the key, which is surrounded by curly brackets, with the value on data:
$('#githubModal').on('show.bs.modal', function (e) {
var $element = $(this),
url = 'https://api.github.com/users/{username}',
title = 'Hi, my name is {name}',
content = '' +
'<div class="row">' +
'<img src="{img}" class="col-sm-3">' +
'<p class="col-sm-9" id="bio">{bio}</p>' +
'</div>',
bio = '' +
'At moment I have {publicRepo} public repos ' +
'and {followers} followers.\n' +
'I joined Github on {dateJoin}';
url = url.replace(/{username}/, $('#github-username').val());
$.get(url, function(data) {
title = title.replace(/{name}/, data.name);
bio = bio.replace(/{publicRepo}/, data.public_repos)
.replace(/{followers}/, data.followers)
.replace(/{dateJoin}/, data.created_at.split('T')[0]);
content = content.replace(/{img}/, data.avatar_url)
.replace(/{bio}/, bio);
$element.find('.modal-title').text(title);
$element.find('.modal-body').html(content);
});
});After all the replacements, we set the parsed template variables to the modal. We query the title to find the .modal-title and insert the text inside, while we insert the HTML for .modal-body.
The difference here is that we can pass an HTML or a simple text to jQuery. Take care when you pass an HTML to ensure that your HTML is not degenerated. That might cause issues for your client. So, pay attention when you want to set just a text, like for .modal-title, or a valid html, like for .modal-body.
On the browser, type your GitHub username on the input, press the button, and you should see a nice modal, such as the one in the next screenshot:

So, we saw how to interact more with the Bootstrap plugins while customizing it for our own tasty.
Remember that the Bootstrap events exist for every Bootstrap plugin. They are friendly and can be very handy while interacting with the plugins, like in this case, to execute some action when the Modal shows.