Created
April 30, 2012 08:01
-
-
Save creativeaura/2556401 to your computer and use it in GitHub Desktop.
jQuery Plugin Template
This file contains 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
// jQuery Plugin Boilerplate | |
// A boilerplate for jumpstarting jQuery plugins development | |
;(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); | |
/* | |
* Usage for the plugin | |
*/ | |
$(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; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment