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

Implement load handlers #50

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
04aabf5
numbered attributes
kt-12 Mar 10, 2023
e366d5d
onload script
kt-12 Mar 10, 2023
0fafd88
fix bug
kt-12 Mar 10, 2023
386022e
sprintf issue with \n
kt-12 Mar 11, 2023
fe7acc0
phpcs fixes
kt-12 Mar 11, 2023
394405f
print template loader script
kt-12 Mar 11, 2023
cc5dace
\n to EOL
kt-12 Mar 11, 2023
b558f34
Loading the script before other script
kt-12 Mar 13, 2023
f04a246
temp commit
kt-12 Mar 14, 2023
b5f4df4
check if any delayed inline scripts
kt-12 Mar 15, 2023
d9a0f39
Merge add_text_template to implement_load_handlers
kt-12 Mar 15, 2023
d110556
add new line
kt-12 Mar 16, 2023
b6b7022
backward compatibility
kt-12 Mar 16, 2023
9e8c378
update test utility and scripts.
kt-12 Mar 16, 2023
ffc40c1
php cs fixes
kt-12 Mar 16, 2023
8af918c
fix csfix issue
kt-12 Mar 16, 2023
d952da5
Update test message.
kt-12 Mar 21, 2023
b71b557
Update test comment
kt-12 Mar 21, 2023
479d656
Update test error message
kt-12 Mar 21, 2023
968d5b7
change function names
kt-12 Mar 21, 2023
ad9d9c3
Merge branch 'enhancement/implement_load_handlers' of https://github.…
kt-12 Mar 21, 2023
326555d
use unregister column
kt-12 Mar 22, 2023
6187dd1
Merge branch 'enhancement/add_text_template' into enhancement/impleme…
kt-12 Mar 22, 2023
1321d6f
avoid removal of jquery libraries
kt-12 Mar 23, 2023
66ab60c
Dataprovider doc block.
kt-12 Mar 23, 2023
bbdad37
doc block change
kt-12 Mar 23, 2023
966be0c
Update src/wp-includes/class-wp-scripts.php
kt-12 Mar 28, 2023
dcbf0af
Update doc text
kt-12 Mar 31, 2023
8e08454
Merge branch 'enhancement/add_text_template' into enhancement/impleme…
kt-12 Mar 31, 2023
b3f7225
fix type_attr no there issue
kt-12 Mar 31, 2023
4df5288
adding description
kt-12 Mar 31, 2023
264853c
broke standalone script test to multiple function
kt-12 Mar 31, 2023
556ae91
non-standalone after script test broken
kt-12 Mar 31, 2023
d4be88d
before standalone test broken
kt-12 Mar 31, 2023
180a6ae
non standalone with before and defer
kt-12 Mar 31, 2023
4d0140d
used function instead of arrow function.
kt-12 Mar 31, 2023
a5b83a4
single condition
kt-12 Mar 31, 2023
0269128
put back handle
kt-12 Mar 31, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/wp-includes/script-loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -1846,15 +1846,15 @@ function wp_just_in_time_script_localization() {

/**
* Prints a loader script if there is text/template registered script.
*
* When injected in DOM, this script converts any text/template script
*
* When injected in DOM, this script converts any text/template script
* associated with a handle to type/javascript and execute them.
*/
function wp_print_template_loader_script() {
$wp_scripts = wp_scripts();
if ( $wp_scripts->has_delayed_inline_script() ) {
$output = <<<JS
let wpLoadAfterScripts = ( handle ) => {
function wpLoadAfterScripts() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

You still need to accept a handle param, right?

Copy link
Author

Choose a reason for hiding this comment

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

Fixed.

let scripts = document.querySelectorAll(`[type="text/template"][data-wp-executes-after="\${handle}"]`);
scripts.forEach( (script) => {
script.setAttribute("type","text/javascript");

Choose a reason for hiding this comment

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

Suggested change
script.setAttribute("type","text/javascript");

WP use $this->type_attr for script type. Please correct me if i miss anything.

Copy link
Author

Choose a reason for hiding this comment

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

@mukeshpanchal27 this is the JS code for modifying type after a script is loaded on the DOM. So we can't use $this->type_attr

Expand Down
6 changes: 3 additions & 3 deletions tests/phpunit/tests/dependencies/scripts.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function test_non_standalone_and_standalone_after_script_combined() {
$output = get_echo( 'wp_print_scripts' );
$expected = <<<EXP
<script type='text/javascript' id='wp-executes-after-js'>
let wpLoadAfterScripts = ( handle ) => {
function wpLoadAfterScripts() {
let scripts = document.querySelectorAll(`[type="text/template"][data-wp-executes-after="\${handle}"]`);
scripts.forEach( (script) => {
script.setAttribute("type","text/javascript");
Expand Down Expand Up @@ -153,7 +153,7 @@ public function test_non_standalone_after_inline_script_with_defer_main_script()
$output = get_echo( 'wp_print_scripts' );
$expected = <<<EXP
<script type='text/javascript' id='wp-executes-after-js'>
let wpLoadAfterScripts = ( handle ) => {
function wpLoadAfterScripts() {
let scripts = document.querySelectorAll(`[type="text/template"][data-wp-executes-after="\${handle}"]`);
scripts.forEach( (script) => {
script.setAttribute("type","text/javascript");
Expand Down Expand Up @@ -186,7 +186,7 @@ public function test_non_standalone_after_inline_script_with_async_main_script()
$output = get_echo( 'wp_print_scripts' );
$expected = <<<EXP
<script type='text/javascript' id='wp-executes-after-js'>
let wpLoadAfterScripts = ( handle ) => {
function wpLoadAfterScripts() {
let scripts = document.querySelectorAll(`[type="text/template"][data-wp-executes-after="\${handle}"]`);
scripts.forEach( (script) => {
script.setAttribute("type","text/javascript");
Expand Down