Next, we can add the code that will insert our plugin into the jQuery namespace so that it can be called like other jQuery methods. Add the following code directly above the last line in the code we just added:
$.fn.extend({ tranzify: function(userConfig) { var config = (userConfig) ? $.extend({}, $.tranzify.defaults, userConfig) : $.tranzify.defaults; config.selector = "#" + this.attr("id"); config.multi = parseInt(this.width()) / config.transitionWidth; $.tranzify.createUI(config); return this; } });
jQuery provides the fn.extend()
method specifically for adding new methods that can be chained to the jQuery()
function, which is how most plugins are created. We defined a function as the value of the sole property of an object passed to the extend()
method. We also specified that the method may take one argument, which may be a configuration object passed into the method by whoever...