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

Fixes #15086 - window load inside ready state will not be triggered #15087

Closed
wants to merge 1 commit into from
Closed

Conversation

alexantr
Copy link
Contributor

@alexantr alexantr commented Nov 3, 2017

Q A
Is bugfix? yes
New feature? no
Breaks BC? no
Tests pass? yes/no (for 7.1 stopped)
Fixed issues #15086

@alexantr alexantr changed the title Fixes #15086 Fixes #15086 - window load inside ready state will not be triggered Nov 3, 2017
@samdark samdark added this to the 2.0.13.1 milestone Nov 3, 2017
@samdark samdark requested a review from SilverFire November 3, 2017 16:23
@@ -604,7 +604,7 @@ protected function renderBodyEndHtml($ajaxMode)
$lines[] = Html::script($js, ['type' => 'text/javascript']);
}
if (!empty($this->js[self::POS_LOAD])) {
$js = "jQuery(function ($) {\n$(window).on('load', function () {\n" . implode("\n", $this->js[self::POS_LOAD]) . "\n});\n});";
$js = "jQuery(window).on('load', function () {\n" . implode("\n", $this->js[self::POS_LOAD]) . "\n});";
Copy link
Member

Choose a reason for hiding this comment

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

Hmm... Shouldn't it be just "jQuery(function($) {\n" . implode("\n", $this->js[self::POS_LOAD]) . "\n});"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

jQuery(function($) { }); - when DOM is ready
jQuery(window).on('load', function() { }); - when content is fully loaded

Copy link
Member

Choose a reason for hiding this comment

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

Ah, OK.

Copy link
Member

Choose a reason for hiding this comment

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

I see that we are nesting the calls unnecessarily here but as far as I understand DOM ready event comes before window load event. if we register the handler inside of the DOM ready event, why does it have no effect?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In version 3 the ready handler fires asynchronously.

You can check code:

jQuery(function ($) {
  console.log('ready');
  $(window).on('load', function () {
    console.log('load in ready');
  });
});
jQuery(window).on('load', function () {
  console.log('load');
});

With jQuery 2.2.4 you will see:

ready
load
load in ready

With jQuery 3.2.1 you will see:

load
ready

No "load in ready" anymore.

jquery/jquery#3194 (comment)
jquery/jquery#3197

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just wanted to make $ working even jQuery.noConflict() is enabled. But missed this great change in jQuery API. The best way to fix this bug - rollback my proposal in #14620

@samdark samdark added JS JavaScript related type:bug Bug labels Nov 3, 2017
Copy link
Member

@samdark samdark left a comment

Choose a reason for hiding this comment

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

Merge master in, add changelog and it's done.

@SilverFire
Copy link
Member

Merged: 2246786

@SilverFire SilverFire closed this Nov 5, 2017
@SilverFire
Copy link
Member

Thank you!

@SilverFire SilverFire self-assigned this Nov 5, 2017
@alexantr alexantr deleted the patch-1 branch May 14, 2019 08:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
JS JavaScript related type:bug Bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants