Advertisement
Guest User

Untitled

a guest
Apr 25th, 2014
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. (function( $ ){
  2. var methods = {
  3. init: function() {
  4. $(this).scroll(function(evt) {
  5. $(evt.target).data('options', Math.random());
  6. console.log($(evt.target).data('options'));
  7. });
  8. },
  9. get: function() {
  10. return $(this).data('options');
  11. }
  12. };
  13.  
  14. $.fn.myPlugin = function(method) {
  15. return this.each(function() {
  16. if ( methods[method] ) {
  17. return methods[method].apply( this, Array.prototype.slice.call( arguments, 1 ));
  18. }
  19. else if ( typeof method === 'object' || ! method )
  20. return methods.init.apply( this, arguments );
  21. else
  22. $.error( 'Method ' + method + ' is not declared for jQuery.myPlugin' );
  23. })
  24. };
  25. })(jQuery);
  26.  
  27. $(document).myPlugin();
  28.  
  29. var data = $(document).myPlugin('get');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement