Revision: 65284
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at November 15, 2013 00:13 by rickygri
Initial Code
/* * Plugin template */ (function(window, $){ var Plugin = function(elem, options){ this.elem = elem; this.$elem = $(elem); this.options = options; }; Plugin.prototype = { defaults: { message: 'Hello world!' }, init: function() { this.config = $.extend({}, this.defaults, this.options); this.displayMessage(); return this; }, displayMessage: function() { alert(this.config.message); } }; Plugin.defaults = Plugin.prototype.defaults; $.fn.plugin = function(options) { return this.each(function() { new Plugin(this, options).init(); }); }; window.Plugin = Plugin; })(window, jQuery); /* * Use plugin */ //Set the message per instance: $('#elem').plugin({ message: 'Goodbye World!' }); var p = new Plugin(document.getElementById('elem'), { message: 'Goodbye World!' }).init(); //Or, set the global default message: Plugin.defaults.message = 'Goodbye World!';
Initial URL
http://markdalgleish.com/2011/05/creating-highly-configurable-jquery-plugins/
Initial Description
Uses the object prototype to extend data. Instantiate as an object and use as specified below (bottom of the code)
Initial Title
jQuery Plugin template
Initial Tags
template, jquery
Initial Language
JavaScript