? Success

User tests: Successful: Unsuccessful:

avatar phproberto
phproberto
30 Nov 2014

This solves #5254

Issue description

I was checking core.js and noticed that we have added there some jQuery code in functions:

Joomla.renderMessages
and
Joomla.removeMessages

They are mainly used on install and overrider but also third part developers can be using them.

We officially support jQuery & Mootools even being migrating to jQuery. Adding that code causes that developers that want to use only Mootools are forced to load jQuery.

So we have to convert them to plain JS.

How to test

As it's hard to test message rendering in installation & language overrides here is some code that you can use. You have to add this code before applying the patch and test it before and after the patch to be sure that it's working the same.

I will explain how to put testing code in the articles view ( administrator/components/com_content/views/articles/tmpl/default.php). Around line 54 add:

JText::script('ERROR');
JText::script('MESSAGE');
JFactory::getDocument()->addScriptDeclaration('
    jQuery(document).ready(function() {
        jQuery(".js-test").click(function(){
            var messages = {
                "message": ["Message one", "Message two"],
                "error": ["Error one", "Error two"]
            };
            Joomla.renderMessages(messages);
        });
        jQuery(".js-test-clear").click(function(){
            Joomla.removeMessages();
        });


    });
');

Then before line 66 (after the main container tag) add the buttons that will trigger the actions:

<a class="btn btn-success js-test" href="#">Render messages</a>
<a class="btn btn-danger js-test-clear" href="#">Clear messages</a>

You will see something like:
buttons

  • Clicking on the Render messages button should display the messages.
  • Clicking on the Clear messages button should remove the messages.

View with the messages loaded:

messages

avatar phproberto phproberto - open - 30 Nov 2014
avatar jissues-bot jissues-bot - change - 30 Nov 2014
Labels Added: ?
avatar dgt41
dgt41 - comment - 30 Nov 2014

@test success
screen shot 2014-11-30 at 4 33 29
screen shot 2014-11-30 at 4 33 38

When deleting the msgs we end up with a lot of white space, I guess this happens only in the test env?

avatar phproberto phproberto - change - 30 Nov 2014
The description was changed
avatar phproberto
phproberto - comment - 30 Nov 2014

In fact it was a chrome bug :(

Thanks for testing it should work now.

avatar dgt41
dgt41 - comment - 30 Nov 2014

will retest in the morning

avatar Fedik Fedik - test_item - 30 Nov 2014 - Tested successfully
avatar Fedik
Fedik - comment - 30 Nov 2014

test
works good :+1:

avatar dgt41
dgt41 - comment - 30 Nov 2014

@test success

screen shot 2014-11-30 at 3 33 40
screen shot 2014-11-30 at 3 33 25

avatar wilsonge
wilsonge - comment - 30 Nov 2014

Can we remove the call to jQuery in JHtmlBehaviour::core(); as part of this then please?

avatar dgt41
dgt41 - comment - 30 Nov 2014

@wilsonge But JHtmlBehaviour::core(); is out in the wild and people might use it to load both core+jquery. We can introduce JHtmlBehaviour::joomla(); or something else for clean core.
My 2c on this

avatar Bakual
Bakual - comment - 30 Nov 2014

Can we remove the call to jQuery in JHtmlBehaviour::core(); as part of this then please?

If core.js doesn't need jQuery anymore, then remove the call to jQuery.

But JHtmlBehaviour::core(); is out in the wild and people might use it to load both core+jquery. We can introduce JHtmlBehaviour::joomla(); or something else for clean core.

Nah. JHtmlBehaviour::core(); is supposed to load core.js. It happens to depend on jQuery for now, but if developer depend on it loading jQuery, then they are wrongly doing that.
It's the same thing we have with MooTools. Developers should always load their dependencies and not trust that other code does that for you.

avatar dgt41
dgt41 - comment - 30 Nov 2014

@wilsonge @Bakual Removing https://github.com/joomla/joomla-cms/blob/staging/libraries/cms/html/behavior.php#L88 didn’t broke something, so I guess you are both right here!

avatar phproberto
phproberto - comment - 30 Nov 2014

Good catch @wilsonge :)

I think this is perfect now.

avatar dgt41
dgt41 - comment - 30 Nov 2014

@phproberto don’t commit this one yet… I am sending you a PR...

avatar dgt41
dgt41 - comment - 30 Nov 2014

@phproberto you have a pr: phproberto#8

avatar zero-24 zero-24 - change - 1 Dec 2014
Category JavaScript
avatar phproberto
phproberto - comment - 3 Dec 2014

I merged @dgt41's PR :+1:

avatar Bakual
Bakual - comment - 4 Dec 2014

Merged, thanks!

avatar phproberto phproberto - change - 4 Dec 2014
Status Pending Closed
Closed_Date 0000-00-00 00:00:00 2014-12-04 07:22:27
avatar phproberto phproberto - close - 4 Dec 2014

Add a Comment

Login with GitHub to post a comment