Defining the plugin methods
Now that we have our plugin well declared, we must fill the logic for it. We will create methods inside the prototype
to create this behavior. We will only show this portion of the plugin code here.
The first method that we will create is init()
. We will call it later to start the plugin. Before that, we have a few steps:
Initial verifications
Assigning the plugin elements and prerequisites
Loading the original Bootstrap template
Starting the Bootstrap plugin
The initialize method and plugin verifications
Actually, we have only one requirement from the Bootstrap original carousel plugin: the outmost div
must have an id
. Let's create the init
function while making this assertion:
BootstrapCarousel.prototype = { init: function () { if(!this.$element.attr('id')){ throw 'You must provide an id for the Bootstrap Carousel element.'; } this.$element.addClass('slide carousel'); } };
Therefore, we check if the element has the attribute id
using this.$element...