Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Usage:
- $('selector').pluginname();
- $('selector').pluginname('update', { txt : 'text' });
- $('selector').pluginname('destroy');
- */
- ;
- (function($) {
- var __pluginName = 'pluginname';
- var Obj = function($self, opt) {
- this.$self = $self;
- this.opt = $.extend({
- }, opt);
- this.init();
- };
- Obj.prototype = {
- init : function() {
- },
- destroy : function() {
- this.$self.removeData(__pluginName);
- },
- update : function(opt) {
- this.opt = $.extend(this.opt, opt);
- }
- };
- $.fn[__pluginName] = function(opt, param) {
- return this.each(function() {
- var $self = $(this);
- var obj;
- if(!!(obj = $self.data(__pluginName))) {
- if(typeof opt === 'string' && !!obj[opt])
- obj[opt](param);
- else
- obj.update(opt);
- } else {
- $self.data(__pluginName, new Obj($self, opt));
- }
- });
- }
- })(jQuery);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement