Created
August 21, 2012 15:06
-
-
Save johnpolacek/3416310 to your computer and use it in GitHub Desktop.
jQuery Plugin Boilerplate
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
/* | |
PluginName - Plug In Description | |
by John Polacek (@johnpolacek) | |
Dual licensed under MIT and GPL. | |
Dependencies: jQuery | |
*/ | |
;(function($) { | |
$.pluginName = function(el, options) { | |
var defaults = { | |
propertyName: 'value', | |
onSomeEvent: function() {} | |
} | |
var plugin = this; | |
plugin.settings = {} | |
var init = function() { | |
plugin.settings = $.extend({}, defaults, options); | |
plugin.el = el; | |
// code goes here | |
} | |
plugin.foo_public_method = function() { | |
// code goes here | |
} | |
var foo_private_method = function() { | |
// code goes here | |
} | |
init(); | |
} | |
})(jQuery); | |
/* In the HTML demo page: | |
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> | |
<script>window.jQuery || document.write('<script src="js/jquery-1.7.2.min.js"><\/script>')</script> | |
<script> | |
$(document).ready(function() { | |
// create a new instance of the plugin | |
var myplugin = new $.pluginName($('#element')); | |
// call a public method | |
myplugin.foo_public_method(); | |
// get the value of a public property | |
myplugin.settings.property; | |
</script> | |
}); | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment