Skip to content

Commit

Permalink
Merge branch 'css-empty-collection'
Browse files Browse the repository at this point in the history
  • Loading branch information
mislav committed Jul 12, 2016
2 parents 72869d8 + 92fdae3 commit a9444f0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
13 changes: 7 additions & 6 deletions src/zepto.js
Original file line number Diff line number Diff line change
Expand Up @@ -691,13 +691,14 @@ var Zepto = (function() {
},
css: function(property, value){
if (arguments.length < 2) {
var computedStyle, element = this[0]
if(!element) return
computedStyle = getComputedStyle(element, '')
if (typeof property == 'string')
return element.style[camelize(property)] || computedStyle.getPropertyValue(property)
else if (isArray(property)) {
var element = this[0]
if (typeof property == 'string') {
if (!element) return
return element.style[camelize(property)] || getComputedStyle(element, '').getPropertyValue(property)
} else if (isArray(property)) {
if (!element) return
var props = {}
var computedStyle = getComputedStyle(element, '')
$.each(property, function(_, prop){
props[prop] = (element.style[camelize(prop)] || computedStyle.getPropertyValue(prop))
})
Expand Down
18 changes: 11 additions & 7 deletions test/zepto.html
Original file line number Diff line number Diff line change
Expand Up @@ -1660,13 +1660,17 @@ <h1>Zepto Core unit tests</h1>
},

testCSSOnNonExistingElement: function (t) {
var errorWasRaised = false
try {
var color = $('.some-non-exist-elm').css('color')
} catch (e) {
errorWasRaised = true
}
t.assert(!errorWasRaised)
var el = $('.some-non-exist-elm')
t.assertUndefined(el.css('color'))
},

testCSSBatchSetOnNonExistingElementReturnsSelf: function (t) {
var el = $('.some-non-exist-elm')
var ret = el.css({
'border': '2px solid #000',
'color': 'rgb(0,255,0)'
})
t.assertIdentical(ret, el)
},

testHtml: function(t){
Expand Down

0 comments on commit a9444f0

Please sign in to comment.