?
avatar uGE70
uGE70
20 Sep 2017

Steps to reproduce the issue

Add the following jQuery script into /modules/mod_custom/tmpl/default.php
$js = "
jQuery(document).ready(function() {
console.log('Test');
});
";
JFactory::getDocument()->addScriptDeclaration($js);

Publish ONLY ONE instance of the custom module

Add the custom module inside the content of an article even uncategorized with the Add module button

Expected result

Javascript Console displays "Test".

Actual result

Javascript Console displays "Test" two times. If one looks at the source code, the Jquery script is added two times.

System information (as much as possible)

Joomla 3.8 (Tested on two different sites upgraded from 3.7.5). PHP 7.0.20. Chrome browser.

Additional comments

I haven't seen any issue outside of modules added inside articles. It would affect Javascript with no jQuery too.

avatar uGE70 uGE70 - open - 20 Sep 2017
avatar joomla-cms-bot joomla-cms-bot - change - 20 Sep 2017
Labels Added: ?
avatar joomla-cms-bot joomla-cms-bot - labeled - 20 Sep 2017
avatar franz-wohlkoenig franz-wohlkoenig - change - 20 Sep 2017
Category JavaScript
avatar uGE70 uGE70 - change - 20 Sep 2017
The description was changed
avatar uGE70 uGE70 - edited - 20 Sep 2017
avatar aardgoose
aardgoose - comment - 20 Sep 2017

Similar problem with 3.8 (upgraded from a clean 3.7.5 install)

Plugin is executed twice for a page, resulting in duplicate script entries.
(occurs with either routing mode)

Possibly related, with operations being triggered twice?


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/17999.

avatar franz-wohlkoenig franz-wohlkoenig - change - 20 Sep 2017
Status New Discussion
avatar uGE70 uGE70 - change - 20 Sep 2017
The description was changed
avatar uGE70 uGE70 - edited - 20 Sep 2017
avatar uGE70 uGE70 - change - 21 Sep 2017
The description was changed
avatar uGE70 uGE70 - edited - 21 Sep 2017
avatar Fedik
Fedik - comment - 21 Sep 2017

it is expected behavior,
$doc->addScriptDeclaration() called twice, so your script added twice.

It always worked like that, and do not relate specifically to 3.8

avatar franz-wohlkoenig
franz-wohlkoenig - comment - 21 Sep 2017

@Fedik is this "calling twice" same Reason for #18016?

avatar Fedik
Fedik - comment - 21 Sep 2017

It is different.

In current issue, @uGE70 made:

Publish at least two instances of the custom module

so the module loaded twice and so his code called twice. that is expected.

avatar uGE70
uGE70 - comment - 21 Sep 2017

@Fedik Sorry, I changed it for the sake of reproducing the issue and it was an error to do so for the behavior you're mentioning, but I have really an issue with a datatables script loaded twice (that's why I remarked it, datatables scripts can't be instanced twice). I will try to clarify.

avatar Fedik
Fedik - comment - 21 Sep 2017

@uGE70
It would be the same issue, only when you have ONE instance of the module, but your code added twice.

but then need more detailed info, how to reproduce it

avatar uGE70
uGE70 - comment - 21 Sep 2017

@Fedik I have several scripts into one instance of modules called twice after the Joomla 3.8 upgrade. My code is calling them once. What I did wrong was to assume my report could reproduce the issue with the custom module example. Sorry for that. I will try to clarify the issue.

avatar uGE70 uGE70 - change - 21 Sep 2017
The description was changed
avatar uGE70 uGE70 - edited - 21 Sep 2017
avatar uGE70
uGE70 - comment - 21 Sep 2017

Ok, I updated my report. The error does happen if there's one instance of the module inside an article. When I put my modules in the template positions instead of the content of the articles, the scripts are called once as they should. Thanks for your patience.

avatar uGE70 uGE70 - change - 21 Sep 2017
The description was changed
avatar uGE70 uGE70 - edited - 21 Sep 2017
avatar mdmamde
mdmamde - comment - 29 Sep 2017

i have a similar problem with jux-timeline module,A code like this gets added to head script several times, when using {loadposition } in content. Using the module in other modul-position is ok.

$document->addScriptDeclaration('
jQuery(document).ready(function($){
$("#jux_tl'.$module->id.'").juxtimeline();
});
');

Full of Hope i tested:
#18066
Not working...

Reverted back to Joomla 3.7.5 modul is working.

avatar mdmamde
mdmamde - comment - 29 Sep 2017

n9iels commented 3 days ago
@Bakual is right. Unless there is another point where onContentPrepare is called, this event won't be fired if the fields plugin is disabled

shows expected result in 3.8.0+#18066

avatar franz-wohlkoenig
franz-wohlkoenig - comment - 29 Sep 2017

@mdmamde didn't get your Comments: First you post "#18066 not working", above "shows expected result in 3.8.0" > can you please explain?

avatar mdmamde
mdmamde - comment - 29 Sep 2017

CASE1.)Joomla 3.8.0+#18066+fieldsplugin enabled=module yuxtimeline does not work(multiple scripts in head from plugin)
CASE2.)Joomla 3.8.0+#18066+fieldsplugin disabled=module yuxtimeline works (only single js script in head per module-id)

CASE3.)Also i tried this scenario:
Joomla 3.8.0+( without changes #18066)+fieldsplugin disabled=does not work, multiple scripts from module in head

CASE4.) Joomla 3.7.5=module works

avatar uGE70
uGE70 - comment - 29 Sep 2017

I tested the fix #18066 and it solved my issue. Thanks for your work.

avatar franz-wohlkoenig
franz-wohlkoenig - comment - 30 Sep 2017

@mdmamde please open an new Issue as the original Issue is solved as stated above so this Issue is closed.

avatar joomla-cms-bot joomla-cms-bot - change - 30 Sep 2017
Status Discussion Closed
Closed_Date 0000-00-00 00:00:00 2017-09-30 05:54:09
Closed_By joomla-cms-bot
avatar joomla-cms-bot joomla-cms-bot - close - 30 Sep 2017
avatar franz-wohlkoenig franz-wohlkoenig - change - 30 Sep 2017
Closed_By joomla-cms-bot franz-wohlkoenig
avatar joomla-cms-bot
joomla-cms-bot - comment - 30 Sep 2017

Add a Comment

Login with GitHub to post a comment