Created
May 12, 2010 08:01
-
-
Save ryan5500/398319 to your computer and use it in GitHub Desktop.
DOM <-> Object bridge with jQuery.fn.extend (Alex Sexton's way)
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($) { | |
//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