Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Proper support for CSS style property.

  • Loading branch information...
commit d9e7dd2cb63ef50729b9edb10280438d44864b32 1 parent ab32231
@assaf assaf authored
Showing with 46 additions and 0 deletions.
  1. +2 −0  CHANGELOG.md
  2. +14 −0 lib/zombie/jsdom_patches.coffee
  3. +30 −0 spec/css.coffee
View
2  CHANGELOG.md
@@ -5,6 +5,8 @@ zombie.js-changelog(7) -- Changelog
Support origin in websockets (Glen Mailer)
+Proper support for CSS style `opacity` property.
+
## Version 0.12.1 2011-12-06
View
14 lib/zombie/jsdom_patches.coffee
@@ -65,3 +65,17 @@ HTML.languageProcessors.javascript = (element, code, filename)->
window.run code, filename
catch error
raise element, filename, __filename, null, error
+
+
+# Support for opacity style property.
+Object.defineProperty HTML.CSSStyleDeclaration.prototype, "opacity",
+ get: ->
+ return @_opacity || ""
+ set: (opacity)->
+ if opacity
+ opacity = parseFloat(opacity)
+ unless isNaN(opacity)
+ @_opacity = opacity.toString()
+ else
+ delete @_opacity
+
View
30 spec/css.coffee
@@ -0,0 +1,30 @@
+{ vows: vows, assert: assert, brains: brains, Browser: Browser } = require("./helpers")
+
+
+vows.describe("CSS").addBatch(
+ "opacity":
+ topic: ->
+ brains.get "/styled", (req, res)-> res.send """
+ <body><div id="styled"></div></body>
+ """
+ browser = new Browser
+ browser.wants "http://localhost:3003/styled", =>
+ @callback null, browser.query("#styled").style
+
+ "should be formatted string": (style)->
+ style.opacity = .55
+ assert.typeOf style.opacity, "string"
+ assert.equal style.opacity, "0.55"
+ "should not accept non-numbers": (style)->
+ style.opacity = ".46"
+ style.opacity = "four-six"
+ assert.equal style.opacity, "0.46"
+ "should default to empty string": (style)->
+ style.opacity = 1.0
+ style.opacity = undefined
+ assert.equal style.opacity, ""
+ style.opacity = null
+ assert.equal style.opacity, ""
+
+
+).export(module)
Please sign in to comment.
Something went wrong with that request. Please try again.