Skip to content

Instantly share code, notes, and snippets.

@cowboy
Created February 22, 2010 19:48
Show Gist options
  • Save cowboy/311415 to your computer and use it in GitHub Desktop.
Save cowboy/311415 to your computer and use it in GitHub Desktop.
/*!
* jQuery iePseudoFix - v0.1 - 2/22/2010
* http://benalman.com/
*
* Copyright (c) 2010 "Cowboy" Ben Alman
* Dual licensed under the MIT and GPL licenses.
* http://benalman.com/about/license/
*/
(function($){
'$:nomunge'; // Used by YUI compressor.
var map = {
hover: [ 'mouseover', 'mouseout' ],
active: [ 'mousedown', 'mouseup' ]
};
$.fn.iePseudoFix = function( options ) {
var that = this;
function get_elems( elem ) {
return options.no_parents ? $(elem) : $(elem).parents().andSelf();
};
if ( $.browser.msie ) {
$.each( map, function(k,v){
var namespace = '.iepf-' + k,
class_name = options[k];
if ( class_name !== undefined ) {
that.die( namespace );
if ( class_name ) {
that
.live( v[0] + namespace, function(e){
get_elems(this).addClass( class_name );
})
.live( v[1] + namespace, function(e){
get_elems(this).removeClass( class_name );
});
}
}
});
}
return this;
};
})(jQuery);
// Usage:
//
// == CSS ==
//
// li:hover, li.hoverz {
// background: #afa;
// }
//
// li:active, li.activez {
// background: #0a0;
// }
//
// == JS ==
//
// $('li').iePseudoFix({ hover: 'hoverz', active: 'activez' });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment