Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

feat($compile): allow SVG and MathML templates via special type property #7265

Closed
wants to merge 1 commit into from

Conversation

caitp
Copy link
Contributor

@caitp caitp commented Apr 26, 2014

Previously, templates would always be assumed to be valid HTML nodes. In some cases, it is desirable to use SVG or MathML or some other language.

For the time being, this change is only truly meaningful for SVG elements, as MathML has very limited browser support. But in the future, who knows?


NOTE: It would be nice (and more extensible) to simply add a namespaceURI option to the directive, but unfortunately this would require potentially difficult changes to jqLite.

This approach seemed much simpler, and would be more directly useful to persons wanting to use SVG content in a directive template, without a wrapping <svg> element. Additionally, it's much easier to simply write "svg" than a full namespace URI, so it's more approachable in this fashion as well.

…perty

Previously, templates would always be assumed to be valid HTML nodes. In some cases, it is
desirable to use SVG or MathML or some other language.

For the time being, this change is only truly meaningful for SVG elements, as MathML has
very limited browser support. But in the future, who knows?
@mary-poppins
Copy link

Thanks for the PR! Please check the items below to help us merge this faster. See the contributing docs for more information.

  • Uses the issue template (#7265)

If you need to make changes to your pull request, you can update the commit with git commit --amend.
Then, update the pull request with git push -f.

Thanks again for your help!

@caitp caitp added this to the 1.3.0 milestone Apr 27, 2014
@caitp
Copy link
Contributor Author

caitp commented Apr 28, 2014

@vojtajina It's pretty small, but it does include a new API feature, so that's the one thing that might be problematic.

Pretty small though, most of this code is tests.

@vojtajina
Copy link
Contributor

@caitp Just to make sure I understand this...
For each directive, we let the browser instantiate the DOM from the HTML first and then do the magic with it (clone if inside ng-repeat, append to document, remove etc...)
Browser won't construct proper SVG DOM nodes unless it is inside <svg> and thus we need to wrap the template first (and immediately use only the children of <svg>), right?

@@ -1813,6 +1827,20 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
}


function wrapTemplate(type, template) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just an idea: This is not really wrapping, it's constructing DOM (in the case of SVG/Math). How about we make it to construct DOM from HTML even for regular templates and call it constructDOMfromHTML or somethin...

Anyway, just a comment, feel free to ignore this one...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, if someone wants to come up with a better/more descriptive name for it, I don't have a problem with it. I think it's a good point.

My thinking is that it's (maybe) wrapping the template in a specific DOM node, so I called it wrapTemplate() --- but it is true that that's a bit of a misnomer.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

recastTemplate, maybe-perhaps? I know I haven't contributed as of yet, but I saw this in my inbox....

To Vojta's point, when I first read the line of code, I thought I would need to shed an enclosure . Reading the comments on the PR put me on the right track.

@caitp
Copy link
Contributor Author

caitp commented Apr 29, 2014

Yeah. createElementNS would get around it, but it would complicate jqLite too much to do it that way, so I think it's all we can do

@vojtajina
Copy link
Contributor

LGTM.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants