Elxis CMS Forum
Support => Elxis 4.x/5.x DEV => Topic started by: seadhna on January 30, 2013, 20:23:03
-
Hi there,
the following lines do not appear in the 'showHead' on a category, but do appear on an article:
<link rel="stylesheet" href="http://www.icpdtaskforce.org/includes/js/jquery/colorbox/colorbox.css" type="text/css" />
<script type="text/javascript" src="http://www.icpdtaskforce.org/includes/js/jquery/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="http://www.icpdtaskforce.org/includes/js/jquery/colorbox/colorbox.js"></script>
Is there a way to make them to either never appear or always appear?
-
Elxis puts these lines in the <head> section only if an extension requested them. You should not remove them else the extension wont work.
I don't get why to add them in the head if they are not required but I will answer your question:
To load jQuery:
$eDoc = eFactory::getDocument();
$eDoc->addJQuery();
To load built-in lightbox (colorbox):
$eDoc = eFactory::getDocument();
$eDoc->loadLightbox();
The best place to put this code if you want these scripts to always be there is in your template's index.php file.
Related documentation on elxis docs: https://www.elxis.net/docs/developers/libraries/elxisdocument.html (https://www.elxis.net/docs/developers/libraries/elxisdocument.html)
-
Hi there,
thanks for the reply. So I have javascript in the head of the index.php that requires the jquery library. problem is that when i call the jquery library in index.php - it is then loaded twice in some parts of the site because it is also coming in as part of 'showHead' - but only in some places. this is causing problems. i'm wondering how to stop jquery being called ever as part of showHead?
-
This happens because you load jquery wrong.
Why don't you read the documentation (https://www.elxis.net/docs/developers/libraries/elxisdocument.html)?
...it is strongly recommended to use the addLibrary method as it provides some important features. The method will make sure that the link will be added only once. If different extensions load different versions of the same library Elxis will finally load only the latest one. $name is an identification name for the library (eg. mootools) and $version the library's version.
Use the addJQuery method and jquery will be shown in the head section only once!
Note: addJQuery is a shortcut for addLibrary method with the library options automatically configured.
-
Hi there, it is only being added once as part of showhead but I am also needing to add it manually in the parts of the site where it is not appearing, so I just want to call manually and don't want it to ever appear as part of showhead - is that possible?
-
I think that you don't understand...
You can add it manually the way I told you, the rest you say are wrong thoughts. It is just one line of code. This is the code to add it manually:
eFactory::getDocument()->addJQuery();
-
Hi again, I am still struggling with this I'm afraid. I have read the documentation but am still not sure what to do. I need the Jquery library to be called on every page of the site, but it is only being called for articles - not categories or the frontpage. Could you advise what I am doing wrong? Many thanks.
-
You mentioned earlier "Elxis puts these lines in the <head> section only if an extension requested them." - how do I 'request' them on every single page of the site?
-
Open your template's index.php file and before the html tag or echoing anything write this:
eFactory::getDocument()->addJQuery(); (or, if $eDoc is set, this: $eDoc->addJQuery(); )
That's it.
Example for default template Delta:
<?php
//.....
$eLang = eFactory::getLang();
$eDoc = eFactory::getDocument();
$elxis = eFactory::getElxis();
$eDoc->addJQuery();
elxisloader::loadFile('templates/delta/includes/delta.class.php');
$delta = new templateDelta();
echo $eDoc->getDocType()."\n";
?>
<html<?php echo $eDoc->htmlAttributes(); ?>>
......
-
Thanks! Is there a similar way to always add colorbox js and css?
-
Yes, load Elxis built-in lightbox (colorbox):
eFactory::getDocument()->loadLightbox();
or
$eDoc->loadLightbox();
Note: You must first load jquery to use colorbox. So:
<?php
$eDoc->addJQuery();
$eDoc->loadLightbox();
?>
To assign lightbox on a group of photos with class "test" use the code below (change "test" to whatever you like) :
$js = '$(".test").colorbox({rel:\'test\', slideshow:true, slideshowAuto:true, slideshowSpeed:4000, loop:true});';
$eDoc->addDocReady($js);
And your html:
<a href="big_image1.jpg" class="test"><img src="small_image1.jpg" alt="..." /></a>
<a href="big_image2.jpg" class="test"><img src="small_image2.jpg" alt="..." /></a>
<a href="big_image3.jpg" class="test"><img src="small_image3.jpg" alt="..." /></a>
-
Fantastic - thanks!