Last active
August 29, 2015 14:05
-
-
Save goesbysteve/99e1470e1a0df7723b77 to your computer and use it in GitHub Desktop.
jQuery plugin bootstrap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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