Skip to content

Commit 78f4139

Browse files
Prevent infinite loop in IE 9-10 when calling getStyle('opacity') on an element. (jbedard, Andrew Dupont)
1 parent 317ed7a commit 78f4139

File tree

2 files changed

+27
-14
lines changed

2 files changed

+27
-14
lines changed

src/prototype/dom/dom.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2891,7 +2891,7 @@
28912891
value = element.currentStyle[style];
28922892
}
28932893

2894-
if (style === 'opacity')
2894+
if (style === 'opacity' && !STANDARD_CSS_OPACITY_SUPPORTED)
28952895
return getOpacity_IE(element);
28962896

28972897
if (value === 'auto') {

test/unit/dom_test.js

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -198,34 +198,35 @@ new Test.Unit.Runner({
198198

199199
testElementMethodInsert: function() {
200200
$('element-insertions-main').insert({before:'some text before'});
201-
this.assert(getInnerHTML('element-insertions-container').startsWith('some text before'));
201+
this.assert(getInnerHTML('element-insertions-container').startsWith('some text before'), 'some text before');
202202
$('element-insertions-main').insert({after:'some text after'});
203-
this.assert(getInnerHTML('element-insertions-container').endsWith('some text after'));
203+
this.assert(getInnerHTML('element-insertions-container').endsWith('some text after'), 'some text after');
204204
$('element-insertions-main').insert({top:'some text top'});
205-
this.assert(getInnerHTML('element-insertions-main').startsWith('some text top'));
205+
this.assert(getInnerHTML('element-insertions-main').startsWith('some text top'), 'some text top');
206206
$('element-insertions-main').insert({bottom:'some text bottom'});
207-
this.assert(getInnerHTML('element-insertions-main').endsWith('some text bottom'));
207+
this.assert(getInnerHTML('element-insertions-main').endsWith('some text bottom'), 'some text bottom');
208208

209209
$('element-insertions-main').insert('some more text at the bottom');
210-
this.assert(getInnerHTML('element-insertions-main').endsWith('some more text at the bottom'));
210+
this.assert(getInnerHTML('element-insertions-main').endsWith('some more text at the bottom'),
211+
'some more text at the bottom');
211212

212213
$('element-insertions-main').insert({TOP:'some text uppercase top'});
213-
this.assert(getInnerHTML('element-insertions-main').startsWith('some text uppercase top'));
214+
this.assert(getInnerHTML('element-insertions-main').startsWith('some text uppercase top'), 'some text uppercase top');
214215

215216
$('element-insertions-multiple-main').insert({
216217
top:'1', bottom:2, before: new Element('p').update('3'), after:'4'
217218
});
218-
this.assert(getInnerHTML('element-insertions-multiple-main').startsWith('1'));
219-
this.assert(getInnerHTML('element-insertions-multiple-main').endsWith('2'));
220-
this.assert(getInnerHTML('element-insertions-multiple-container').startsWith('<p>3</p>'));
221-
this.assert(getInnerHTML('element-insertions-multiple-container').endsWith('4'));
219+
this.assert(getInnerHTML('element-insertions-multiple-main').startsWith('1'), '1');
220+
this.assert(getInnerHTML('element-insertions-multiple-main').endsWith('2'), '2');
221+
this.assert(getInnerHTML('element-insertions-multiple-container').startsWith('<p>3</p>'), '<p>3</p>');
222+
this.assert(getInnerHTML('element-insertions-multiple-container').endsWith('4'), '4');
222223

223224
$('element-insertions-main').update('test');
224225
$('element-insertions-main').insert(null);
225226
$('element-insertions-main').insert({bottom:null});
226-
this.assertEqual('test', getInnerHTML('element-insertions-main'));
227+
this.assertEqual('test', getInnerHTML('element-insertions-main'), 'should insert nothing when called with null');
227228
$('element-insertions-main').insert(1337);
228-
this.assertEqual('test1337', getInnerHTML('element-insertions-main'));
229+
this.assertEqual('test1337', getInnerHTML('element-insertions-main'), 'should coerce to string when called with number');
229230
},
230231

231232
testNewElementInsert: function() {
@@ -988,14 +989,26 @@ new Test.Unit.Runner({
988989
$('op3').setStyle({opacity: 0});
989990
this.assertEqual(0, $('op3').getStyle('opacity'), 'get opacity on #op3');
990991

991-
if(navigator.appVersion.match(/MSIE/)) {
992+
// Opacity feature test borrowed from Modernizr.
993+
var STANDARD_CSS_OPACITY_SUPPORTED = (function() {
994+
var DIV = document.createElement('div');
995+
DIV.style.cssText = "opacity:.55";
996+
var result = /^0.55/.test(DIV.style.opacity);
997+
DIV = null;
998+
return result;
999+
})();
1000+
1001+
if (!STANDARD_CSS_OPACITY_SUPPORTED) {
1002+
// Run these tests only on older versions of IE. IE9 and 10 dropped
1003+
// support for filters and therefore fail these tests.
9921004
this.assertEqual('alpha(opacity=30)', $('op1').getStyle('filter'));
9931005
this.assertEqual('progid:DXImageTransform.Microsoft.Blur(strength=10)alpha(opacity=30)', $('op2').getStyle('filter'));
9941006
$('op2').setStyle({opacity:''});
9951007
this.assertEqual('progid:DXImageTransform.Microsoft.Blur(strength=10)', $('op2').getStyle('filter'));
9961008
this.assertEqual('alpha(opacity=0)', $('op3').getStyle('filter'));
9971009
this.assertEqual(0.3, $('op4-ie').getStyle('opacity'));
9981010
}
1011+
9991012
// verify that value is still found when using camelized
10001013
// strings (function previously used getPropertyValue()
10011014
// which expected non-camelized strings)

0 commit comments

Comments
 (0)