Created
July 24, 2014 13:48
-
-
Save pulse00/3a15eaea2a7b1c9b9d01 to your computer and use it in GitHub Desktop.
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
var __slice = [].slice; | |
(function($, window) { | |
var MyPlugin; | |
MyPlugin = (function() { | |
MyPlugin.prototype.defaults = { | |
paramA: 'foo', | |
paramB: 'bar' | |
}; | |
function MyPlugin(el, options) { | |
this.options = $.extend({}, this.defaults, options); | |
this.$el = $(el); | |
} | |
MyPlugin.prototype.myMethod = function(echo) { | |
return this.$el.html(this.options.paramA + ': ' + echo); | |
}; | |
return MyPlugin; | |
})(); | |
return $.fn.extend({ | |
myPlugin: function() { | |
var args, option; | |
option = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : []; | |
return this.each(function() { | |
var $this, data; | |
$this = $(this); | |
data = $this.data('myPlugin'); | |
if (!data) { | |
$this.data('myPlugin', (data = new MyPlugin(this, option))); | |
} | |
if (typeof option === 'string') { | |
return data[option].apply(data, args); | |
} | |
}); | |
} | |
}); | |
})(window.jQuery, window); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment