Posted By

realpeterz on 09/24/11


Tagged


Versions (?)

jQuery plugin boilderplate


 / Published in: jQuery
 

URL: http://jqueryboilerplate.com/

  1. ;(function($) {
  2.  
  3. $.pluginName = function(el, options) {
  4.  
  5. var defaults = {
  6. propertyName: 'value',
  7. onSomeEvent: function() {}
  8. },
  9.  
  10. plugin = this;
  11.  
  12. plugin.settings = {};
  13.  
  14. var init = function() {
  15. plugin.settings = $.extend({}, defaults, options);
  16. plugin.el = el;
  17. plugin.$el = $(el);
  18. // code goes here
  19. };
  20.  
  21. plugin.fooPublicMethod = function() {
  22. // code goes here
  23. };
  24.  
  25. var fooPrivateMethod = function() {
  26. // code goes here
  27. };
  28.  
  29. init();
  30.  
  31. }
  32.  
  33. })(jQuery);
  34.  
  35.  
  36. // Uages
  37.  
  38.  
  39. $(document).ready(function() {
  40.  
  41. // create a new instance of the plugin
  42. var myplugin = new $.pluginName($('#element'), {option: "value"});
  43.  
  44. // call a public method
  45. myplugin.fooPublicMethod();
  46.  
  47. // get the value of a public property
  48. myplugin.settings.property;
  49.  
  50. });

Report this snippet  

You need to login to post a comment.