Created
October 25, 2010 10:41
-
-
Save gcoop/644756 to your computer and use it in GitHub Desktop.
jQuery Plugin Template Code
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
(function (window, document, $, undefined) { | |
var dataKey = 'MyPlugin'; | |
var methods = { | |
init: function (opts) { | |
var defaults = { | |
'offset': 0 | |
}, o = $.extend(defaults, opts); | |
return this.each(function () { | |
var $this = $(this), | |
data = $(this).data(dataKey); | |
if (!data) { | |
// Setup | |
$this.data(dataKey, { | |
offset: o.offset, | |
visible: false | |
}); | |
} | |
}); | |
} | |
} | |
$.fn.MyPlugin = function (method) { | |
if ( methods[method] ) { | |
return methods[method].apply( this, Array.prototype.slice.call( arguments, 1 )); | |
} else if ( typeof method === 'object' || ! method ) { | |
return methods.init.apply( this, arguments ); | |
} else { | |
$.error( 'Method ' + method + ' does not exist on jQuery.tooltip' ); | |
} | |
} | |
})(this, this.document, jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment