Hi
I've developed a my custom gallery plugin to add it into an article.
I know there is the plugin loadmodule to load a module into an article, but I don't like to use this solution
However there is a problem of priority about addStyleSheet, addScript and addSCriptDeclaration.
The behavior should be like for the module, if I use addStyleSheet, addScript and addSCriptDeclaration inside a module its files will call after the template css, js files
instead with the plugins it doesn't happen, in fact the jquery is loaded after these plugin files and the gallery doesn't work. The css files are load at the top of the rest files and the same for the js files.
I'm using joomla 3.4.1
thanks
bye
Labels |
Added:
?
|
Without templates manipulating the order, the media is displayed in a "first in first out" manner. As plugins such as the loadmodule plugin get triggered before a component layout is rendered, it could have the first media loaded. The component is fully processed before modules are triggered, so that's why module media is loaded after.
As for your plugin media being loaded before jQuery, you need to ensure you're calling the method to load it before your scripts to ensure it gets loaded first; it isn't automatically loaded on each request but it's pretty hard to not load it with the core platform.
thanks mbabker
joomla should find a solution to avoid problems like this giving priority to load before template files, using a particular function to manage these files.
I load these files from onContentPrepare, is there another function that I can use to load them after that phase?
bye
You refer to template files, but you mean those loaded by components?
The template itself can easily force its files to load prior or after the other files.
As said by Michael, if you need jQuery to work in your plugin, make sure you load it before loading the file that needs it. Joomla will make sure the same file only gets loaded once.
hi Bakual
jquery is loaded from theme index.php, but I'd like to know if I can load the plugin files like a module after the others
if I use addScript to load a jquery from the plugin the other loaded from the theme is not overrided or excluded
....plugins/content/maogalleryview/js/jquery.min.js
....templates/maofree-theme/js/jui/jquery.min.js
I'll study this little guide
http://joomla.stackexchange.com/questions/325/whats-the-difference-between-jhtmlscript-and-doc-addscript
also try this: https://docs.joomla.org/J3.x:Javascript_Frameworks
All the assets that joomla provides have a specific call, if you do it in another way things could get nasty
thanks dgt41
JHtml::_('jquery.framework');
or use an override solution with js/jui is the same (with the second mode I can decide which jquery version to use), but in both cases the plugin files are loaded before others.
....plugins/content/maogalleryview/js/jquery.min.js
....templates/maofree-theme/js/jui/jquery.min.jsJHtml::_('jquery.framework');
or use an override solution with js/jui is the same (with the second mode I can decide which jquery version to use), but in both cases the plugin files are loaded before others.
Neither the plugin nor the template should provide its own jQuery. Use the one shipped with Joomla and load that one also in the plugin (as Michael suggested). That should fix your issue. Otherwise you get jQuery loaded more than once and in various versions for sure. You don't want that.
If you for whatever reason need a different jQuery version, override it in your template. But still call the original one. Joomla will detect the override and load that one.
JHtml::_('jquery.framework');
is the way to load the jQuery shipped with Joomla. Don't use another way. It's bound to fail sooner than later.
Thanks
Yes using JHtml::_('jquery.framework'); in both files (index.php and plugin php) I get the jquery override.
To be picky there would be another small problem, using addStyleSheet to load a css file from this plugin, this file go over css theme files giving some css priority problem. However this is not very important
thanks a lot
bye
Yesssssssssssss
I've found the solution for both type of files
In the theme it is necessary only to use
JHtml::('behavior.framework');
instead into the plugins it is necessary to load these files from onBeforeCompileHead and not from onContentPrepare. In this mode css and js files will load after theme and module files. From the plugin is not necessary to use JHtml::('jquery.framework'); do it only to be sure that jquery is loaded
public function onBeforeCompileHead()
{
// Application Object
$app = JFactory::getApplication();
// Front only
if ($app instanceof JApplicationSite) {
$doc = JFactory::getDocument();
$doc->addStyleSheet(JURI::base().'plugins/content/maogalleryview/css/maogalleryview.css', $type = 'text/css', $media = 'screen,projection');
$doc->addScript(JURI::base().'plugins/content/maogalleryview/js/slider.mini.js', 'text/javascript');
}
}
byeeeeeeeee
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2015-04-13 07:58:43 |
Hi
to reproduce this issue is necessary only to put two files (1 css and 1 js) into a default plugin (ex. loadmodule), then load these files from its main php file; then look the page source of a page to see where these files are loaded in the header
thanks