Skip to content

Instantly share code, notes, and snippets.

@goesbysteve
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save goesbysteve/99e1470e1a0df7723b77 to your computer and use it in GitHub Desktop.
Save goesbysteve/99e1470e1a0df7723b77 to your computer and use it in GitHub Desktop.
jQuery plugin bootstrap
/**
* Created by stevegibbings on 09/08/2014.
*/
(function($, window, document, undefined){
"use strict";
// plugin object
var Example = {
name: 'example',
init: function(options, elem) {
var self = this;
self.elem = elem;
self.$elem = $(elem);
self.options = $.extend({}, $.fn.example.options, options);
// Instance properties
// self.example = 'example';
}/*,
// public function
example: function() {
}
*/
};
// Attach plugin to jQuery.fn and iterate jQuery object
$.fn.example = function(options) {
return this.each(function(){
var example = Object.create(Example);
example.init(options, this);
example.$elem.data(example.name, example);
});
};
// Mutable plugin options
// Allows default options to be reset for all instances outside of the plugin
// example - $.fn.example.options['example'] = 'example';
$.fn.example.options = {
};
})(jQuery,window,document);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment