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

Allow arbitrarily nested <use> elements #117

Closed
wants to merge 5 commits into from

Conversation

shawnbot
Copy link
Collaborator

@shawnbot shawnbot commented May 18, 2016

This PR addresses the use case (heh) for <use> elements that aren't direct descendants of their SVG element, e.g.

<svg>
  <a xlink:href="foo.html">
    <use xlink:href="bar.svg#symbol"/>
  </a>
</svg>

The changes allow for this by removing checks for direct "ancestry" (/svg/i.test(svg.nodeName)) and perform replacements on the <use> element's parent, which also makes it easier to style those elements with CSS descendent selectors.

We've added a test to test/index.html that works, and the code passes linting muster. We've ensured that the validate() and fallback() callbacks still get the SVG element as their second argument, so those should still work as expected—though some tests for those would be very welcome.

@shawnbot shawnbot changed the title Allow <use> elements in arbitrary parents Allow arbitrarily nested <use> elements May 18, 2016
@shawnbot
Copy link
Collaborator Author

shawnbot commented Jun 3, 2016

Hey @jonathantneal, is there anything I can do to move this along? I've also offered to help in #101 if you want to make me a contributor.

@shawnbot shawnbot self-assigned this Jun 15, 2016
@shawnbot
Copy link
Collaborator Author

shawnbot commented Aug 8, 2016

Anyone want to review this one for me? @jonathantneal?

@shawnbot
Copy link
Collaborator Author

I'd like to use element-closest instead of the inline getSVGAncestor() function here, but we're not set up for browserification of CJS modules yet. That's something to do re: #60 and #114 in a future update.

id: id
});

// prepare the xhr ready state change event
loadreadystatechange(xhr);
} else {
// embed the local id into the svg
embed(svg, document.getElementById(id));
embed(parent, document.getElementById(id));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Minor: would it be better to pass in both the svg and parent so that we don't have to search through the DOM again? Its likely that svg and use are close together, but its would be more efficient this way. You would have to change the obj being passed into xhr._embeds as well.

@@ -199,3 +202,14 @@ function svg4everybody(rawopts) {
oninterval();
}
}

function getSVGAncestor(node) {
var svg = node;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Very minor: I think leaving it as node is clearer

Copy link
Collaborator

@timeiscoffee timeiscoffee left a comment

Choose a reason for hiding this comment

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

dist will need to be rebuilt before merge :)

@shawnbot
Copy link
Collaborator Author

Thanks for the review, @timeiscoffee! I gave you access to the branch just in case you have time to get to this before I do.

@timeiscoffee
Copy link
Collaborator

@shawnbot which branch did you give me the access to? I don't see it unfortunately :(

@shawnbot
Copy link
Collaborator Author

@timeiscoffee you should have write access to this fork's use-parent branch. I think that if you can click on the pencil icon on this page then all's good?

@timeiscoffee
Copy link
Collaborator

@shawnbot I tried to push to that use-parent branch, but got not authorized error. Trying to edit that README gives me:

You’re editing a file in a project you don’t have write access to. Submitting a change to this file will write it to a new branch in your fork timeiscoffee/svg4everybody, so you can send a pull request..

@shawnbot
Copy link
Collaborator Author

Derf, maybe that feature only works for user forks and not org forks. Sorry! I'm happy to close this PR if you have fixes ready.

@timeiscoffee
Copy link
Collaborator

Sure, I would be happy to :)

@timeiscoffee
Copy link
Collaborator

Closing as per above discussion, since #132 has been merged

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