-
-
Notifications
You must be signed in to change notification settings - Fork 468
[Enhancement] Add parentElement parameter to use/ref method #126
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
Conversation
|
Also deeply useful for inserting css into shadow roots, any chance of this being merged in the near future ? |
worldsense-tms
left a comment
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.
A wild reviewer appears! Consider all my comments optional.
This change is really cool and would benefit my project tremendously.
| var styleElement = document.createElement("style"); | ||
| styleElement.type = "text/css"; | ||
| insertStyleElement(options, styleElement); | ||
| insertStyleElement(styleElement, parentElement, options); |
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.
I believe you need to call parentElement.ownerDocument.createElement() instead of document.createElement(). One alternative is to call adoptNode.
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.
Yeah, probably better change this.
| if (options.singleton) { | ||
| var styleIndex = singletonCounter++; | ||
| styleElement = singletonElement || (singletonElement = createStyleElement(options)); | ||
| styleElement = singletonElement || (singletonElement = createStyleElement(parentElement, options)); |
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.
When parentElement changes, the singletonElement should perhaps change as well?
|
@Craga89 Could you please close and reopen the PR to trigger the CLA Bot agian && rebase against current master 🙃 ? |
ekulabuhov
left a comment
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.
Needs to include some unit tests. Happy to help with that.
|
|
||
| Note: Behavior is undefined when `unuse`/`unref` is called more often than `use`/`ref`. Don't do that. | ||
|
|
||
| #### Iframe support |
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.
Might need more general header here
| if (options.insertAt === "top") { | ||
| if(!lastStyleElementInsertedAtTop) { | ||
| head.insertBefore(styleElement, head.firstChild); | ||
| parentElement.insertBefore(styleElement, parentElement.firstChild); |
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.
There's an overlap with #135 here.
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 are going to need to pick either #126 & #135.
1.) We have two features with overlapping functionality at a high level.
2.) #135 just needs tests and the author of this pull request hasn't responded
3.) #135 achieves the same thing using a method consistent with existing functionality
Before we start blowing up notification feeds for reviews / labeling and adding Issues to milestones we should be looking at open pull requests for duplication like this and chose what best solves the problem.
we should accept #135 and close #126
|
Closes #44 |
|
@d3viant0ne good points. Let's focus our efforts on getting #135 merged. |
Based on #65, rebased onto current master and cleaned up some-what. This allows the user to specify an optional
parentElementto inject thelink/styletag into at runtime, using theuse/refmethod:Useful for those of us rendering into
iframes!