Guest User

Untitled

a guest
Jul 17th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. (function($) {
  2.  
  3. var methods = {
  4. init: function( options ) {
  5. // iterate and reformat each matched element
  6. return this.each(function() {
  7. var $this = $(this),
  8. opts = $.extend({}, $.fn.PLUGIN_NAME.defaults, options),
  9. data = $this.data('PLUGIN_NAME');
  10.  
  11. // If the plugin hasn't been initialized yet
  12. if ( ! data ) {
  13.  
  14. // do all your main awesomeness in here...
  15.  
  16. // attach
  17. $this.data('PLUGIN_NAME', {
  18. target : $this,
  19. opts: opts
  20. });
  21.  
  22. };
  23. });
  24. },
  25. update: function() {
  26. // each method must loop through all selected elements and return 'this'.
  27. return this.each(function() {
  28. if(window.console) window.console.log('update called.');
  29. });
  30. }
  31. };
  32.  
  33. // main plugin declaration:
  34. $.fn.PLUGIN_NAME = function( method ) {
  35. if ( methods[method] ) {
  36. return methods[method].apply( this, Array.prototype.slice.call( arguments, 1 ));
  37. } else if ( typeof method === 'object' || ! method ) {
  38. return methods.init.apply( this, arguments );
  39. } else {
  40. $.error( 'Method ' + method + ' does not exist on jQuery.PLUGIN_NAME' );
  41. };
  42. };
  43.  
  44. // defaults
  45. $.fn.PLUGIN_NAME.defaults = {
  46. optionA: true
  47. // etc...
  48. };
  49.  
  50. $.fn.PLUGIN_NAME.publicfunc = function() { return "jquery.PLUGIN_NAME public function. "; };
  51.  
  52. })(jQuery);
Add Comment
Please, Sign In to add comment