Skip to content

Commit

Permalink
Remove opacity filter in IE if the opacity is 1.
Browse files Browse the repository at this point in the history
  • Loading branch information
Arian committed Feb 9, 2012
1 parent e65e04b commit ef71402
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Source/Element/Element.Style.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ var setOpacity = (hasOpacity ? function(element, opacity){
} : (hasFilter ? function(element, opacity){
var style = element.style;
if (!element.currentStyle || !element.currentStyle.hasLayout) style.zoom = 1;
if (opacity == null) opacity = '';
if (opacity == null || opacity == 1) opacity = '';
else opacity = 'alpha(opacity=' + (opacity * 100).limit(0, 100).round() + ')';
var filter = style.filter || element.getComputedStyle('filter') || '';
style.filter = reAlpha.test(filter) ? filter.replace(reAlpha, opacity) : filter + opacity;
Expand Down
14 changes: 9 additions & 5 deletions Specs/1.4client/Element/Element.Style.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('Element.Style', function(){

beforeEach(function(){
var className = String.uniqueID();
var style = this.style = document.createElement('style');
var style = this.style = $(document.createElement('style'));
style.type = 'text/css';
var definition = [
'.' + className + '{',
Expand Down Expand Up @@ -44,10 +44,14 @@ describe('Element.Style', function(){
});

it('should set/overwrite the opacity', function(){
this.element.setStyle('opacity', 1);
expect(this.element.getStyle('opacity')).toEqual(1);
this.element.setStyle('opacity', null);
expect(this.element.getStyle('opacity')).toEqual(0.5);
// this test is disabled in IE, because of the ugly aliasing with
// opacity we have to remove the filter in oldIE
if (document.html.style.filter == null || window.opera || Syn.browser.gecko){
this.element.setStyle('opacity', 1);
expect(this.element.getStyle('opacity')).toEqual(1);
this.element.setStyle('opacity', null);
expect(this.element.getStyle('opacity')).toEqual(0.5);
}
});

it('should remove the style by setting it to `null`', function(){
Expand Down

0 comments on commit ef71402

Please sign in to comment.