Skip to content

Assign attrs to created script element #3

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

Merged
merged 1 commit into from
Apr 5, 2018

Conversation

eerikson
Copy link
Contributor

@eerikson eerikson commented Apr 5, 2018

Need this feature to allow optional crossOrigin on behance. However, might be nice for any user of this package to define arbitrary properties on <script />.

var doc = document
var tag = 'script'
var firstScript
var el
el = doc.createElement(tag)
firstScript = doc.getElementsByTagName(tag)[0]
if (attrs) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Placement is important here—we want to control & possibly overwrite async, src, onload, etc

Copy link

@mmase mmase Apr 5, 2018

Choose a reason for hiding this comment

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

could you make attrs = {} by default and then just simply (with no conditional):

Object.assign(el, attrs);

Copy link
Owner

Choose a reason for hiding this comment

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

Please keep in mind that we're not using babel here, so let's keep compatibility to IE11.

Copy link

Choose a reason for hiding this comment

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

carry on!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah im trying to keep it old school in this PR.

var doc = document
var tag = 'script'
var firstScript
var el
return new Promise(function (resolve, reject) {
el = doc.createElement(tag)
firstScript = doc.getElementsByTagName(tag)[0]
if (attrs) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ditto for above

@eerikson eerikson force-pushed the AllowArbitraryPropsOnScriptEl branch from f4ba9fb to 2556a05 Compare April 5, 2018 15:38
Copy link
Owner

@nemtsov nemtsov left a comment

Choose a reason for hiding this comment

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

Nice!

@eerikson eerikson merged commit f0a9d4c into nemtsov:master Apr 5, 2018
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.

3 participants