-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improvements to namespaces and attributes in serialization #20
base: master
Are you sure you want to change the base?
Conversation
Attributes can now be get and set through both elem.[attr] or elem.getAttribute("[attr]"). Added test-case that shows this behaviour
Ie elem.style.backgroundColor="xxx" now translate to style="background-color: xxx; ". Test-cases added to test this behavior
The namespace-id shouldn't be part of the attribute-name. Test-case updated
that's not how the DOM works. |
@@ -97,13 +97,13 @@ DOMElement.prototype.setAttributeNS = | |||
function _Element_setAttributeNS(namespace, name, value) { | |||
var colonPosition = name.indexOf(":") | |||
var localName = colonPosition > -1 ? name.substr(colonPosition + 1) : name | |||
var attributes = this._attributes[namespace] || (this._attributes[namespace] = {}) | |||
attributes[localName] = value | |||
var attributes = namespace === null ? this : (this._attributes[namespace] || (this._attributes[namespace] = {})) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We cannot write to this
. We must write to this._attributes['default-namespace']
or something. We can even have this._attributes
and this._nsAttributes
Other then props vs attributes the rest looks good to me. |
Well, at least for HTML documents, and supported attributes is does. E.g el = document.createElement('div')
el.id = "foo"
el.getAttribute("id") === "foo" // <- true I considered having a white-list of attributes that if the namespaceURI was the html-namespace, then have this behaviour, but I figured it would start pushing this project away from being a minimal DOM implementation. But if you don't want this behaviour, then I'll remove that commit, add a commit that fixes serialisation of things like el = document.createElement('div')
el.foo = "bar"
el.setAttribute("foo", "baz") and force-push to this feature-branch to update the PR. The problem with the code above is that it would serialise to -M. |
The problem you are running into is the need to have a property -> attribute mapping. Because You also need deduping, i.e. if an attribute is written once dont write it again. I recommend:
However let's not simplify the problem down to "attributes and properties are the same" that is a wrong implementation. I'd rather have an incomplete or subset implementation then a wrong one. |
Hi,
I started out by adding test-cases for the serialisation, and found a few issues once I compared to how browsers (ehh, phantomjs) does it. I found a few discrepancies that I have addressed. Additionally I ensured that
elem.[attr]
is equivalent toelem.getAttribute("[attr]")
.So the new or fixed features are:
elem.[attr]
is equivalent toelem.getAttribute("[attr]")
elem.style.backgroundColor
and other CSS properties that include hyphens are now serialised correctlyKnown differences between min-document and browsers:
document.createElement('input').getAttribute('type')
isnull
in browsers, buttext
in min-document. This is because in both browsers and min-document,document.createElement('input').type
istext
- ie, in browsers there is a difference between.type
and.getAttribute('type');
.document.createElement('input')
is serialised as<input>
in browsers, and<input type="text">
in min-document. This is the same issue as the previous discrepancy.Kind regards
Morten