Skip to content

Instantly share code, notes, and snippets.

@ralphholzmann
Created July 5, 2010 14:54
Show Gist options
  • Save ralphholzmann/464424 to your computer and use it in GitHub Desktop.
Save ralphholzmann/464424 to your computer and use it in GitHub Desktop.
// Opacity fixes for IE
var alphaRegex = /^alpha\(opacity=(\d+)\)$/i;
$.each(['fadeIn', 'fadeOut'], function(i, method){
var _fn = $.fn[method];
$.fn[method] = function(easing, callback) {
alert('here');
if ( $.browser.msie && ( ! this[0].style.filter || alphaRegex.test( this[0].style.filter ))) {
if ($.isFunction(easing)) {
callback = easing;
easing = 'normal';
}
var _callback = callback;
callback = function(){
this.style.removeAttribute('filter');
(_callback || $.noop).call(this);
}
}
return _fn.call(this, easing, callback);
}
});
var _fadeTo = $.fn.fadeTo;
$.fn.fadeTo = function( duration, opacity, callback ){
if ( $.browser.msie && ( ! this[0].style.filter || alphaRegex.test( this[0].style.filter )) && parseInt(opacity) == 1 ) {
var _callback = callback;
callback = function() {
this.style.removeAttribute('filter');
(_callback || $.noop).call(this);
}
}
return _fadeTo.call( this, duration, opacity, callback );
}
var _animate = $.fn.animate;
$.fn.animate = function() {
var args = [];
for ( var q = 0; q < arguments.length; q++ ) {
args.push(arguments[q]);
}
if ( $.browser.msie && 'opacity' in args[0] && ( ! this[0].style.filter || alphaRegex.test( this[0].style.filter )) && parseInt( args[0].opacity ) == 1 ) {
var i
, fn
, found = false;
for ( i = 1; i < args.length; i++ ) {
if ( $.isFunction( args[i] )) {
found = true;
break;
}
}
// If callback is a function
if ( found ) {
fn = args[i];
args[i] = function(){
this.style.removeAttribute('filter');
( fn || $.noop ).call(this);
}
// If callback is 'complete' in options object
} else if ( typeof args[1] == 'object' ) {
fn = args[1].complete;
args[1].complete = function(){
this.style.removeAttribute('filter');
( fn || $.noop ).call(this);
};
} else {
args.push(function() {
this.style.removeAttribute('filter');
});
}
}
return _animate.apply( this, args );
}
var _css = $.fn.css;
$.fn.css = function (){
var args = arguments
, result = _css.apply(this, arguments);
if (
$.browser.msie
&& this.length
&& ( ! this[0].style.filter || alphaRegex.test( this[0].style.filter ))
&& (
(typeof args[0] == 'object' && 'opacity' in args[0] && parseInt( args[0].opacity ) == 1)
|| (args[0] == 'opacity' && parseInt( args[1] ) == 1))
) {
this[0].style.removeAttribute('filter');
}
return result;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment