Skip to content
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

Use SVG Namespace for SVG Elements #5957

Merged
merged 5 commits into from
Dec 8, 2019

Conversation

rockerBOO
Copy link
Contributor

  • Replaces createElement with createElementNS for SVG elements.
  • Replaces setAttribute with setAttributeNS for SVG attributes.

Doing some code quality checks and found this suggestion.

https://webhint.io/docs/user-guide/hints/hint-create-element-svg/
http://zhangwenli.com/blog/2017/07/26/createelementns/

Side note, dist/fabric.js and .gitattributes are not intentional to this request.

@asturur
Copy link
Member

asturur commented Nov 14, 2019

Hi @rockerBOO, thanks for the PR.
To remove the non intentional files,
run git checkout master dist and then commit again. This will remove the changes to the dist folder.

the file .gitattributes you can just do git rm .gitattributes

Can you explain what exactly will change with this different way to set the attributes?

Also i think it would be nice to have the SVG namespace defined on the fabric object like

fabric.svgNS = 'http://www.w3.org/2000/svg'

So that we do not have to repeat it all over the place.

@rockerBOO
Copy link
Contributor Author

This change is for consistency. The setAttributeNS further increases consistency with applying the correct SVG element attribute from the namespace, instead of a unknown HTML element attribute . The actual behavior may conflict with HTML or other namespaces.

We apply the namespace in all other examples (through raw SVG files) but the behavior of these tests may change as browser adaptions implement fallback behavior differently. As all the tests pass without changing the tests, we can assume most browsers fallback appropriately currently.

I can make the modifications shortly.

@asturur
Copy link
Member

asturur commented Dec 1, 2019

@rockerBOO let me know if you can make the changes, or give me the write auth on the branch i'll move it forward

@rockerBOO
Copy link
Contributor Author

I believe I have given you write access.

Updating to this would be the last step.

fabric.svgNS = 'http://www.w3.org/2000/svg'

@asturur asturur merged commit 1fdb025 into fabricjs:master Dec 8, 2019
@asturur
Copy link
Member

asturur commented Dec 8, 2019

i'll do the change on top of your, since is easier to me. Less fiddling with git.

@asturur asturur mentioned this pull request Dec 28, 2019
ickata pushed a commit to ickata/fabric.js that referenced this pull request Jul 27, 2021
* Use SVG Namespace for createElement of SVG elements

* Updating to use setAttributeNS

* Reverting line endings... I hope

* Fixing linter errors

* Resetting dist/ and removing .gitattributes
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants