Creating additional plugin methods
We are almost finishing our plugin. Now, it's time to add some methods to be called in the plugin, just like you can call .carousel('pause')
on Bootstrap Carousel for instance.
When we were creating the plugin base, we created a class Plugin
, which is the definition of the plugin. This part of the code is pretty common across the plugins and it is used on every native Bootstrap plugin:
function Plugin(option) { var args = arguments; [].shift.apply(args); return this.each(function () { var $this = $(this), data = $this.data('bootstrap-carousel'), options = $.extend({}, BootstrapCarousel.DEFAULTS, $this.data(), typeof option == 'object' && option), value; if (!data) { $this.data('bootstrap-carousel', (data = new BootstrapCarousel(this, options))); } if (typeof option == 'string') { if (data[option] instanceof Function) { value...