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
Javascript Console displays "Test".
Javascript Console displays "Test" two times. If one looks at the source code, the Jquery script is added two times.
Joomla 3.8 (Tested on two different sites upgraded from 3.7.5). PHP 7.0.20. Chrome browser.
I haven't seen any issue outside of modules added inside articles. It would affect Javascript with no jQuery too.
Labels |
Added:
?
|
Category | ⇒ | JavaScript |
Status | New | ⇒ | Discussion |
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
@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.
@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.
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.
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.
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
Status | Discussion | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2017-09-30 05:54:09 |
Closed_By | ⇒ | joomla-cms-bot |
Closed_By | joomla-cms-bot | ⇒ | franz-wohlkoenig |
Set to "closed" on behalf of @franz-wohlkoenig by The JTracker Application at issues.joomla.org/joomla-cms/17999
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.