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

Support custom type attribute in scriptLoader method with new parameter T/5434 #5435

Closed
wants to merge 3 commits into from

Conversation

matthandus
Copy link

@matthandus matthandus commented Feb 23, 2023

What is the purpose of this pull request?

New feature to support a custom type attribute on the rendered script tag from the method CKEDITOR.scriptLoader.load to better integrate with applications that may need this, like Drupal.

<script src="/path/to/script.js" type="module"></script>

Does your PR contain necessary tests?

New test named 'test load with custom type attribute' in /tests/core/scriptloader.js.

This PR contains

  • Unit tests
  • [N/A] Manual tests

Did you follow the CKEditor 4 code style guide?

Your code should follow the guidelines from the CKEditor 4 code style guide which helps keep the entire codebase consistent.

  • PR is consistent with the code style guide

What is the proposed changelog entry for this pull request?

* [#5434](https://github.com/ckeditor/ckeditor4/issues/5434): Support custom type attribute in scriptLoader method with new parameter.

What changes did you make?

Added a new parameter named 'typeAttribute' to the load method on CKEDITOR.scriptLoader that is default to 'text/javascript'. This will allow Drupal developers to set the custom type attribute of 'module' on the script tag when needed. Also added a new test to confirm the custom parameter works.

Which issues does your PR resolve?

Closes #5434.

Support custom type attributes on the rendered script tag using a new typeAttribute parameter that defaults to 'text/javascript'.
Test that the new custom type attribute is detected using the new typeAttribute parameter on the scriptLoader.load method.
@Comandeer Comandeer self-assigned this Mar 2, 2023
Copy link
Member

@Comandeer Comandeer left a comment

Choose a reason for hiding this comment

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

Hi, @matthandus , and thanks for your contribution!

The solution you propose works well if the load() method gets only one script URL to load. However, it can also take an array of scripts:

CKEDITOR.scriptLoader.load( [
	'script1.js',
	'script2.js',
	'script3.js'
] );

How would the typeAttribute parameter work in such a case?

Additionally, I'm wondering about the use cases of loading modules via the CKEditor's script loader instead of creating the `script` element in vanilla JS – could you provide an example?

Comment on lines +53 to +54
* @param {String} [typeAttribute] Set a custom type attribute on the
* script tag. Defaults to `text/javascript`.
Copy link
Member

Choose a reason for hiding this comment

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

To indicate the default value of the parameter, please use the [key=value] syntax – it's automatically recognized by our documentation generator and transformed into appropriate information about the default value:

Suggested change
* @param {String} [typeAttribute] Set a custom type attribute on the
* script tag. Defaults to `text/javascript`.
* @param {String} [typeAttribute='text/javascript'] Set a custom `type` attribute on the
* script tag.

Comment on lines +65 to +66
if ( !typeAttribute )
typeAttribute = 'text/javascript';
Copy link
Member

Choose a reason for hiding this comment

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

In newer code we use braces. There are absent in this file due to its age (in older code we were often omitting them):

Suggested change
if ( !typeAttribute )
typeAttribute = 'text/javascript';
if ( !typeAttribute ) {
typeAttribute = 'text/javascript';
}

@@ -25,6 +25,23 @@ var tests = {
this.wait();
},

'test load with custom type attribute': function() {
Copy link
Member

Choose a reason for hiding this comment

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

The test fails in all browsers. The first reason is the usage of the script.$.attr() method. The script.$ property points to the native script element, so to get its type you can use script.$.type.

However, even after this change, the test still fails – probably due to the fact that the ../_assets/sample.js script is already added to the document and the findOne() method gets the first added script element with it. You should check the latest added script.

Additionally, this test won't work in Internet Explorer as it won't preserve the module value of the type attribute. I'm not sure if it's possible to create a test that would work there. Could you check it and – if it's not possible – ignore the test there? For ignoring you could use a code similar to the one below:

if ( CKEDITOR.env.ie ) {
	assert.ignore();
}

@github-actions
Copy link

It's been a while since we last heard from you. We are marking this pull request as stale due to inactivity. Please provide the requested feedback or the pull request will be closed after next 7 days.

@github-actions github-actions bot added the stale The issue / PR will be closed within the next 7 days of inactivity. label Mar 17, 2023
@matthandus
Copy link
Author

Hello, just reviewing the feedback now. I will respond soon. Thank you!

@github-actions github-actions bot removed the stale The issue / PR will be closed within the next 7 days of inactivity. label Mar 24, 2023
@github-actions
Copy link

github-actions bot commented Apr 8, 2023

It's been a while since we last heard from you. We are marking this pull request as stale due to inactivity. Please provide the requested feedback or the pull request will be closed after next 7 days.

@github-actions github-actions bot added the stale The issue / PR will be closed within the next 7 days of inactivity. label Apr 8, 2023
@github-actions
Copy link

There was no activity regarding this pull request in the last 14 days. We're closing it for now. Still, feel free to provide us with requested feedback so that we can reopen it.

@github-actions github-actions bot added the pr:frozen ❄ The pull request on which work was suspended due to various reasons. label Apr 15, 2023
@github-actions github-actions bot closed this Apr 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr:frozen ❄ The pull request on which work was suspended due to various reasons. stale The issue / PR will be closed within the next 7 days of inactivity.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support custom type attribute in scriptLoader method with new parameter
2 participants