Skip to content

Instantly share code, notes, and snippets.

@adamwdraper
Last active February 11, 2024 22:23
Show Gist options
  • Save adamwdraper/2951011 to your computer and use it in GitHub Desktop.
Save adamwdraper/2951011 to your computer and use it in GitHub Desktop.
AMD jQuery plugin template
// Uses AMD or browser globals to create a jQuery plugin.
/**
* Name - jQuery Plugin
*
* Version: 0.0.1 (5/25/2012)
* Requires: jQuery v1.7+
*
* Copyright (c) 2011 User - http://github.com/username
* Under MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*/
(function (factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['jquery'], factory);
} else {
// Browser globals
factory(jQuery);
}
}(function ($) {
var $this;
var methods = {
init : function( options ) {
return this.each(function(){
var $this = $(this),
data = $this.data('initialized');
if ( ! data ) {
$this = $(this);
$this.data('initialized', true);
}
});
},
value: function() {
},
set: function(value) {
},
reset: function() {
}
};
$.fn.inputGrid = 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' );
}
};
}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment