Creating a plugin template
Creating jQuery plugins has become very popular over the years, and there are many articles and discussions online about plugin creation best practices. Many of these articles discuss in depth how to create a plugin template that can be used as the starting point for any jQuery plugin. This recipe will show you how to create your own jQuery plugin template that will be used throughout this chapter.
Getting ready
Inside the chapter8
folder that was created earlier, create a JavaScript file called jquery.plugin-template.js
.
How to do it…
To create a basic plugin template that will form the basis of all the plugins used within this chapter, add the following code to jquery.plugin-template.js
:
;(function ($) { var name = 'pluginName'; Plugin.prototype = { defaults: { } }; // The actual plugin constructor function Plugin(element, options) { var $scope = this; $scope.$element = $(element); $scope.element = element...