Skip to content

Instantly share code, notes, and snippets.

@ryan5500
Created May 12, 2010 08:01
Show Gist options
  • Save ryan5500/398319 to your computer and use it in GitHub Desktop.
Save ryan5500/398319 to your computer and use it in GitHub Desktop.
DOM <-> Object bridge with jQuery.fn.extend (Alex Sexton's way)
(function($) {
//papa crock's code
if (typeof Object.create !== 'function') {
Object.create = function(o) {
var F = function(){};
F.prototype = o;
return new F();
};
}
var hoverClass = {
_init: function(options, elem) {
this.options = $.extend(this.options, options);
this.$elem = $(elem);
this.eventify();
},
options: {
hoverClass: 'megaHover'
},
eventify: function() {
var obj = this;
this.$elem.hover(function() {
$(this).toggleClass(obj.options.hoverClass);
});
},
};
$.fn.extend({
hoverClass: function(options) {
return this.each(function() {
var myHoverClass = Object.create(hoverClass);
myHoverClass.init(options, this);
$(this).data('hoverClass', myHoverClass);
});
}
});
})(jQuery);
$(function() {
$('h1').hoverClass();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment