Created
October 30, 2011 21:29
-
-
Save coffindragger/1326462 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
(function($) { | |
var PLUGIN = "" //TODO: The name of the plugin | |
var methods = { | |
init: function (config) { | |
var options = { | |
//TODO: Default Options | |
} | |
$.extend(options, config) | |
return this.each(function() { | |
var $this = $(this), | |
data = $this.data(PLUGIN); | |
if (!data) { | |
data = { | |
//instance variables | |
target: $this, | |
}; | |
$this.data(PLUGIN, data); | |
//TODO: Constructor | |
} | |
}); | |
}, | |
destroy: function() { | |
return this.each(function() { | |
var $this = $(this), | |
data = $this.data(PLUGIN); | |
//TODO: Destructor | |
// remove data | |
$this.removeData(PLUGIN); | |
//unbind namespaced events | |
$(window).unbind('.'+PLUGIN); | |
}); | |
}, | |
//TODO: Class Methods | |
}; | |
$.fn[PLUGIN] = 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); | |
} | |
} | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment