diff --git a/CHANGELOG b/CHANGELOG index b906e43..1945f7f 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,18 @@ *SVN* +* Make Element#setStyle accept a string argument of CSS rules. Deprecate uncamelized style property names when setting styles using an object (for performance reasons). Closes #9059. [Tobie Langel] + Examples: + $('id').setStyle('font-size: 12px; float: left; opacity: 0.5'); + $('id').setStyle({fontSize: '12px', cssFloat: 'left', opacity: 0.5}); + + !! BACKWARDS COMPATIBILITY CHANGE !! + + If you have code that looks like this: + $('id').setStyle({'font-size': '12px'}); + You need to replace it with either of the following: + $('id').setStyle({fontSize: '12px'}); + $('id').setStyle('font-size: 12px;'); + * Add Element#identify, which returns the element's ID if it exists, or sets and returns a unique, auto-generated ID (of the form "anonymous_element_" + auto-incremented digit) otherwise. Use this when you need to ensure an element has an ID. Closes #9012. [Jeff Watkins, sam, Tobie Langel] * Make Element#readAttribute work for cloned elements in IE. Closes #8481. [chem, Tobie Langel] diff --git a/src/dom.js b/src/dom.js index f2ab680..bfc19de 100644 --- a/src/dom.js +++ b/src/dom.js @@ -365,16 +365,20 @@ Element.Methods = { return $(element).getStyle('opacity'); }, - setStyle: function(element, styles, camelized) { + setStyle: function(element, styles) { element = $(element); - var elementStyle = element.style; - + var elementStyle = element.style, match; + if (typeof styles === 'string') { + element.style.cssText += ';' + styles; + return styles.include('opacity') ? + element.setOpacity(styles.match(/opacity:\s*(\d?\.?\d*)/)[1]) : element; + } for (var property in styles) if (property == 'opacity') element.setOpacity(styles[property]) else elementStyle[(property == 'float' || property == 'cssFloat') ? (elementStyle.styleFloat === undefined ? 'cssFloat' : 'styleFloat') : - (camelized ? property : property.camelize())] = styles[property]; + property] = styles[property]; return element; }, diff --git a/test/unit/dom.html b/test/unit/dom.html index b7dc397..39fe29c 100644 --- a/test/unit/dom.html +++ b/test/unit/dom.html @@ -223,6 +223,12 @@ +