Skip to content

Commit

Permalink
Merge pull request #467 from hardbap/zepto
Browse files Browse the repository at this point in the history
---

Patch from @gregorymostizky for #327 with tests.
  • Loading branch information
madrobby committed Apr 4, 2012
2 parents 5f52009 + c711f8d commit 5f4eebd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/zepto.js
Original file line number Diff line number Diff line change
Expand Up @@ -432,16 +432,25 @@ var Zepto = (function() {
}
},
css: function(property, value){
if (value === undefined && typeof property == 'string') {
if (value === undefined && typeof property == 'string')
return (
this.length == 0
? undefined
: this[0].style[camelize(property)] || getComputedStyle(this[0], '').getPropertyValue(property)
)
}
: this[0].style[camelize(property)] || getComputedStyle(this[0], '').getPropertyValue(property))

var css = ''
for (key in property) css += dasherize(key) + ':' + maybeAddPx(key, property[key]) + ';'
if (typeof property == 'string') css = dasherize(property) + ":" + maybeAddPx(property, value)
for (key in property)
if(typeof property[key] == 'string' && property[key] == '')
this.each(function(){ this.style.removeProperty(dasherize(key)) })
else
css += dasherize(key) + ':' + maybeAddPx(key, property[key]) + ';'

if (typeof property == 'string')
if (value == '')
this.each(function(){ this.style.removeProperty(dasherize(property)) })
else
css = dasherize(property) + ":" + maybeAddPx(property, value)

return this.each(function(){ this.style.cssText += ';' + css })
},
index: function(element){
Expand Down
7 changes: 7 additions & 0 deletions test/zepto.html
Original file line number Diff line number Diff line change
Expand Up @@ -1090,6 +1090,13 @@ <h1>Zepto DOM unit tests</h1>
var div = $('#get_style_element')
t.assertEqual('48px', div.css('font-size'))
t.assertEqual('rgb(0, 0, 0)', div.css('color'))

$('#some_element').css('color', '')
t.assertEqual('', el.style.color)

$('#some_element').css({'margin-top': '', 'marginBottom': ''})
t.assertEqual('', el.style.marginTop)
t.assertEqual('', el.style.marginBottom)
},

testCSSOnNonExistElm: function (t) {
Expand Down

0 comments on commit 5f4eebd

Please sign in to comment.