diff --git a/CHANGELOG b/CHANGELOG index 60a3c6e..dd8e961 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Add optional third parameter "camlized" to Element.setStyle, for optimized performance if style names are known to be camelCased. [Thomas Fuchs] + * Fix a bug in the simulated hasAttribute for IE due to getAttributeNode sometimes returning null. [sam] * Optimize Element.getStyle and add new Element.getOpacity method. Special case IE and Opera getStyle methods. Closes #7648. [Tobie Langel, Thomas Fuchs] diff --git a/src/dom.js b/src/dom.js index b4eaa02..a342f62 100644 --- a/src/dom.js +++ b/src/dom.js @@ -315,7 +315,7 @@ Element.Methods = { return $(element).getStyle('opacity'); }, - setStyle: function(element, styles) { + setStyle: function(element, styles, camelized) { element = $(element); var elementStyle = element.style; @@ -323,7 +323,8 @@ Element.Methods = { if (property == 'opacity') element.setOpacity(styles[property]) else elementStyle[(property == 'float' || property == 'cssFloat') ? - (elementStyle.styleFloat === undefined ? 'cssFloat' : 'styleFloat') : property.camelize()] = styles[property]; + (elementStyle.styleFloat === undefined ? 'cssFloat' : 'styleFloat') : + (camelized ? property : property.camelize())] = styles[property]; return element; }, diff --git a/test/unit/dom.html b/test/unit/dom.html index 795b43f..57fecf6 100644 --- a/test/unit/dom.html +++ b/test/unit/dom.html @@ -630,6 +630,15 @@ assertEqual(0, $('style_test_3').getStyle('opacity')); }}, + testElementSetStyleCamelized: function() { with(this) { + $('style_test_3').setStyle({ marginTop: '30px'}, true); + assertEqual('30px', $('style_test_3').style.marginTop); + + // This would work if camelized parameter is false + $('style_test_3').setStyle({ 'margin-top': '20px'}, true); + assertEqual('30px', $('style_test_3').style.marginTop); + }}, + testElementSetOpacity: function() { with(this) { [0,0.1,0.5,0.999].each(function(opacity){ $('style_test_3').setOpacity(opacity);