Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function($) {
- var methods = {
- init: function( options ) {
- // iterate and reformat each matched element
- return this.each(function() {
- var $this = $(this),
- opts = $.extend({}, $.fn.PLUGIN_NAME.defaults, options),
- data = $this.data('PLUGIN_NAME');
- // If the plugin hasn't been initialized yet
- if ( ! data ) {
- // do all your main awesomeness in here...
- // attach
- $this.data('PLUGIN_NAME', {
- target : $this,
- opts: opts
- });
- };
- });
- },
- update: function() {
- // each method must loop through all selected elements and return 'this'.
- return this.each(function() {
- if(window.console) window.console.log('update called.');
- });
- }
- };
- // main plugin declaration:
- $.fn.PLUGIN_NAME = function( method ) {
- if ( methods[method] ) {
- return methods[method].apply( this, Array.prototype.slice.call( arguments, 1 ));
- } else if ( typeof method === 'object' || ! method ) {
- return methods.init.apply( this, arguments );
- } else {
- $.error( 'Method ' + method + ' does not exist on jQuery.PLUGIN_NAME' );
- };
- };
- // defaults
- $.fn.PLUGIN_NAME.defaults = {
- optionA: true
- // etc...
- };
- $.fn.PLUGIN_NAME.publicfunc = function() { return "jquery.PLUGIN_NAME public function. "; };
- })(jQuery);
Add Comment
Please, Sign In to add comment