jquery plugin skeleton, qunit friendly


/ Published in: Other
Save to your folder(s)



Copy this code and paste it in your HTML
  1. (function($) {
  2. var settings = {
  3. setting1: 'http://lunchguiden.labbplats.se/sok',
  4. setting2: 'baa'
  5. };
  6.  
  7. var $cache1, $cache2, $cache3,
  8. variable1, variable2;
  9.  
  10. var methods = {
  11. mock: function(replace, func) {
  12. methods[replace] = func;
  13. },
  14.  
  15. setup: function(options) {},
  16.  
  17. init: function( options ) {
  18. methods.setup(options);
  19.  
  20. this.each(function() {
  21.  
  22. });
  23.  
  24. return this;
  25. },
  26.  
  27. /*
  28. Delegate clicks
  29. */
  30.  
  31. delegateClick: function( $target ) {
  32. var id = $target.attr('id'),
  33. cls = $target.attr('class'),
  34. magicHappened = false;
  35.  
  36. (function(id){
  37. if (!id) { return; }
  38.  
  39. /*
  40. test id with regexp or $.hasClass
  41. */
  42.  
  43. })($target.attr('id'));
  44.  
  45. (function(cls){
  46. if (!cls) { return; }
  47.  
  48. /*
  49. test class with regexp or $.hasClass
  50. */
  51.  
  52. })($target.attr('class'));
  53.  
  54. return magicHappened;
  55. }
  56. };
  57.  
  58. var protoSlice = Array.prototype.slice;
  59.  
  60. $.fn.mktslideshow = function(method) {
  61. if ( methods[method] ) {
  62. return methods[method].apply( this, protoSlice.call( arguments, 1 ) );
  63. } else if ( typeof method === 'object' || ! method ) {
  64. return methods.init.apply( this, arguments );
  65. } else {
  66. $.error( 'Method ' + method + ' does not exist on jQuery.fn.mktslideshow' );
  67. }
  68. };
  69.  
  70. $.extend($.fn.mktslideshow, {
  71. defaults: settings
  72. });
  73. })(jQuery);

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.