Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Remove UserAgent from DomHelper, replace with feature detection #50
UserAgent was required to construct a DomHelper, but the only thing it was used for is in setStyle to determine if we're in an old IE and need to use a different approach. I was using DomHelper in some code and finding it cumbersome to have a UserAgent instance around as well. This goal is better accomplished with a feature-detection approach anyway.
I've replaced the UserAgent arg with feature detection for getting/setting the style attribute. This is a very similar approach to the one that jQuery uses to detect the same feature.
This has the added side-effect of allowing many of the modules to no longer construct a UserAgent instance using the parser, since they only used it for the DomHelper, which simplifies things.
I had to make one additional change after using this in practice. Having the feature detection triggered in the constructor means that the JS environment has to have a DOM implementation just to construct a DomHelper. This makes it difficult to test in JS environements wrapped within other languages, like Johnson in Ruby.
Unfortunately, it means you have to remember to call a method on your DomHelper instance after instantiating it for normal use. I'm open to other suggestions on how to improve this.