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

Added 'async' optional param to 'regClientScript' and 'regClientStartupScript' #14527

Open
wants to merge 2 commits into
base: 3.x
from
Open
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -1548,9 +1548,11 @@ public function regClientCSS($src, $media = null) {
* tag of an HTML response.
* @param boolean $plaintext Optional param to treat the $src as plaintext
* rather than assuming it is JavaScript.
* @param string $async String literal 'async' or 'defer' which is added
* as attribute to html script tag
* @return void
*/
public function regClientStartupScript($src, $plaintext= false) {
public function regClientStartupScript($src, $plaintext= false, $async='') {

This comment has been minimized.

Copy link
@Alroniks

Alroniks Apr 3, 2019

Collaborator

Only two params allowed - async and defer, so we should add check if passed param is correct or just make it possible to turn it into a boolean parameter.

This comment has been minimized.

Copy link
@DettRoxx

DettRoxx Apr 3, 2019

Author

fixed. now params checks correct values

This comment has been minimized.

Copy link
@JoshuaLuckers

JoshuaLuckers Apr 3, 2019

Collaborator

We should add an attributes parameter. The script tag can also have other attributes like id.

This comment has been minimized.

Copy link
@Mark-H

Mark-H Apr 3, 2019

Collaborator

There are also other methods available (e.g. regClientHTML) so I don't think we need an option for every possibility here.

This comment has been minimized.

Copy link
@JoshuaLuckers

JoshuaLuckers Apr 4, 2019

Collaborator

I was thinking about something like this:

public function regClientStartupScript($src, $plaintext= false, $attributes = [])

$attributes = ['async', 'defer', 'id' => ['test'], 'etc'];

This comment has been minimized.

Copy link
@DettRoxx

DettRoxx Apr 4, 2019

Author

but for what? i opened w3 specs for 'script' tag:
we see:

image

This comment has been minimized.

Copy link
@JoshuaLuckers

JoshuaLuckers Apr 4, 2019

Collaborator

You are referring to W3 schools. Not the w3 specs.
See this list of supported attributes.
This also includes all global attributes.

if (!empty ($src) && !array_key_exists($src, $this->loadedjscripts)) {
if (isset ($this->loadedjscripts[$src]))
return;
@@ -1560,7 +1562,7 @@ public function regClientStartupScript($src, $plaintext= false) {
} elseif (strpos(strtolower($src), "<script") !== false) {
$this->sjscripts[count($this->sjscripts)]= $src;
} else {
$this->sjscripts[count($this->sjscripts)]= '<script type="text/javascript" src="' . $src . '"></script>';
$this->sjscripts[count($this->sjscripts)]= '<script type="text/javascript" src="' . $src . '" '.htmlentities($async).'></script>';
}
}
}
@@ -1572,9 +1574,11 @@ public function regClientStartupScript($src, $plaintext= false) {
* tag in an HTML response.
* @param boolean $plaintext Optional param to treat the $src as plaintext
* rather than assuming it is JavaScript.
* @param string $async String literal 'async' or 'defer' which is added
* as attribute to html script tag
* @return void
*/
public function regClientScript($src, $plaintext= false) {
public function regClientScript($src, $plaintext= false, $async='') {
if (isset ($this->loadedjscripts[$src]))
return;
$this->loadedjscripts[$src]= true;
@@ -1583,7 +1587,7 @@ public function regClientScript($src, $plaintext= false) {
} elseif (strpos(strtolower($src), "<script") !== false) {
$this->jscripts[count($this->jscripts)]= $src;
} else {
$this->jscripts[count($this->jscripts)]= '<script type="text/javascript" src="' . $src . '"></script>';
$this->jscripts[count($this->jscripts)]= '<script type="text/javascript" src="' . $src . '" '.htmlentities($async).'></script>';
}
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.