Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function( $ ){
- var methods = {
- init: function() {
- $(this).scroll(function(evt) {
- $(evt.target).data('options', Math.random());
- console.log($(evt.target).data('options'));
- });
- },
- get: function() {
- return $(this).data('options');
- }
- };
- $.fn.myPlugin = function(method) {
- return this.each(function() {
- 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 + ' is not declared for jQuery.myPlugin' );
- })
- };
- })(jQuery);
- $(document).myPlugin();
- var data = $(document).myPlugin('get');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement