Prototype: Add optional third parameter "camlized" to Element.setStyle, for optimized performance if style names are known to be camelCased. [Thomas Fuchs]

This commit is contained in:
Thomas Fuchs 2007-03-02 12:36:09 +00:00
parent 91dd60c5a2
commit aa7ba0d4ff
3 changed files with 14 additions and 2 deletions

View File

@ -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]

View File

@ -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;
},

View File

@ -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);