Skip to content

Instantly share code, notes, and snippets.

@ibolmo
Created February 23, 2010 01:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ibolmo/311724 to your computer and use it in GitHub Desktop.
Save ibolmo/311724 to your computer and use it in GitHub Desktop.
(function(){
Class.Mutators.jQuery = function(name){
var self = this;
jQuery.fn[name] = function(arg){
var args = Array.prototype.slice.call(arguments, 1);
if ($type(arg) == 'string'){
var instance = $(this).data(name);
if (instance) instance[arg](args); // ????
} else {
$(this).data(name, new self(this.selector, jQuery.extend(self.prototype.options, arg)));
}
};
};
})();
var Person = new Class({
Implements: Options,
options: {
height: 'tall',
weight: 'fat'
},
jQuery: 'Person', // must be after options definition
initialize: function(selector, options){
this.setOptions(options);
this.jqueryObject = jQuery(selector);
},
dance: function(whichDance){
// dance the whichDance
},
combust: function(){
// combust
}
});
// instantiate the class
var instance = new Person('#dude',{ height: 'short' });
jQuery('#dude').Person({ height: 'short' });
// call methods
instance.dance('salsa');
jQuery('#dude').Person('dance','salsa');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment