Skip to content

Instantly share code, notes, and snippets.

@bencooling
Last active December 10, 2015 20:58
Show Gist options
  • Save bencooling/4491412 to your computer and use it in GitHub Desktop.
Save bencooling/4491412 to your computer and use it in GitHub Desktop.
Blank template of jQuery plugin
/*
* jQuery plugin boilerplate
* By Ben Cooling
* 2013
*
* Description:
* Internal operations available as public api
* Construct & Deconstruct methods
* Working with Ajax responses as promise objects
*
* Usage:
* $(selector).pluginName()
*
*/
(function($){
$.fn.pluginName = function(options){
var o = {
tpl : '<div class="{{class}}"></div>';
// Returns: HTML
getTpl : function() {
return $.ajax({ url: settings.getTplUrl });
},
// Returns: JSON
getContent : function(data){
return $.ajax({
type: 'POST',
url : settings.getContentUrl,
data: data
});
},
open : function($this){
var tpl = o.tpl.replace({{class}}, 'some-class');
},
close : function($this){
},
construct : function($this){
},
deconstruct : function($this){
}
},
defaults = {
getTplUrl : '/template.html',
getContentUrl : '/content.json',
},
settings = $.extend(defaults, options);
o.construct( $(this) );
window.pluginName = o; // Internal operations available as public api (programmatically invoke functionality)
return this;
}
})(window.jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment