Last active
December 10, 2015 20:58
-
-
Save bencooling/4491412 to your computer and use it in GitHub Desktop.
Blank template of jQuery plugin
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 | |
* 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