Skip to content

Commit

Permalink
dom/element/attributes: some fixes for name polyfills
Browse files Browse the repository at this point in the history
  • Loading branch information
meh committed Feb 4, 2014
1 parent 0dfd47b commit 1e07e0f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
10 changes: 5 additions & 5 deletions opal/browser/dom/element/attributes.rb
@@ -1,14 +1,14 @@
module Browser; module DOM; class Element < Node

class Attributes
@@normalize = {}
@@normalize = `{}`

This comment has been minimized.

Copy link
@dlee

dlee Feb 4, 2014

Contributor

Is this just an optimization? Why didn't the ruby hash work?

This comment has been minimized.

Copy link
@meh

meh Feb 4, 2014

Author Member

Yes, it's just an optimization, I might have to cut back with the indirection and not caching various things (like Element#attributes) when I start doing some benchmarks.

Most of the time that hash is empty, and maybe it's not such a good idea to have the worst case influence the best case.


if Browser.supports? 'Element.className'
@@normalize[:class] = :className
`#@@normalize['class'] = 'className'`
end

if Browser.supports? 'Element.htmlFor'
@@normalize[:for] = :htmlFor
`#@@normalize['for'] = 'htmlFor'`
end

attr_reader :namespace
Expand All @@ -20,7 +20,7 @@ def initialize(element, options)
end

def [](name, options = {})
name = @@normalize[name] || name
name = `#@@normalize[name] || name`

if namespace = options[:namespace] || @namespace
`#@native.getAttributeNS(#{namespace.to_s}, #{name.to_s}) || nil`
Expand All @@ -30,7 +30,7 @@ def [](name, options = {})
end

def []=(name, value, options = {})
name = @@normalize[name] || name
name = `#@@normalize[name] || name`

if namespace = options[:namespace] || @namespace
`#@native.setAttributeNS(#{namespace.to_s}, #{name.to_s}, #{value})`
Expand Down
4 changes: 2 additions & 2 deletions opal/browser/support.rb
Expand Up @@ -122,15 +122,15 @@ def self.supports?(feature)

when 'Element.for'
%x{
var div = document.createElement("div");
var div = document.createElement("label");
div.setAttribute('for', 'x');
return div.htmlFor === 'x';
}

when 'Element.htmlFor'
%x{
var div = document.createElement("div");
var div = document.createElement("label");
div.setAttribute('htmlFor', 'x');
return div.htmlFor === 'x';
Expand Down

0 comments on commit 1e07e0f

Please sign in to comment.