Elxis CMS Forum

Support => Elxis 4.x/5.x DEV => Topic started by: seadhna on January 30, 2013, 20:23:03

Title: different showHead for categories and articles - i.e. Jquery call
Post 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?
Title: Re: different showHead for categories and articles - i.e. Jquery call
Post by: datahell on January 30, 2013, 22:22:38
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)
Title: Re: different showHead for categories and articles - i.e. Jquery call
Post by: seadhna on January 31, 2013, 12:39:48
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?
Title: Re: different showHead for categories and articles - i.e. Jquery call
Post by: datahell on January 31, 2013, 13:12:55
This happens because you load jquery wrong.

Why don't you read the documentation (https://www.elxis.net/docs/developers/libraries/elxisdocument.html)?
Quote
...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.
Title: Re: different showHead for categories and articles - i.e. Jquery call
Post by: seadhna on February 04, 2013, 14:10:29
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?
Title: Re: different showHead for categories and articles - i.e. Jquery call
Post by: datahell on February 04, 2013, 19:03:49
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();
Title: Re: different showHead for categories and articles - i.e. Jquery call
Post by: seadhna on July 15, 2013, 21:41:10
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.
Title: Re: different showHead for categories and articles - i.e. Jquery call
Post by: seadhna on July 15, 2013, 21:50:35
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?
Title: Re: different showHead for categories and articles - i.e. Jquery call
Post by: datahell on July 15, 2013, 21:50:46
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:

Code: [Select]
<?php 
//.....
$eLang eFactory::getLang();
$eDoc eFactory::getDocument();
$elxis eFactory::getElxis();

$eDoc->addJQuery();

elxisloader::loadFile(&#39;templates/delta/includes/delta.class.php&#39;);
$delta = new templateDelta();

echo 
$eDoc->getDocType()."\n";
?>

<html<?php echo $eDoc->htmlAttributes(); ?>>
......
Title: Re: different showHead for categories and articles - i.e. Jquery call
Post by: seadhna on July 15, 2013, 22:34:37
Thanks! Is there a similar way to always add colorbox js and css?
Title: Re: different showHead for categories and articles - i.e. Jquery call
Post by: datahell on July 15, 2013, 23:21:58
Yes, load Elxis built-in lightbox (colorbox):

eFactory::getDocument()->loadLightbox();
or
$eDoc->loadLightbox();

Note: You must first load jquery to use colorbox. So:

Code: [Select]
<?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) :

Code: [Select]
$js = '$(".test").colorbox({rel:\'test\', slideshow:true, slideshowAuto:true, slideshowSpeed:4000, loop:true});';
$eDoc->addDocReady($js);

And your html:
Code: [Select]
<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>
Title: Re: different showHead for categories and articles - i.e. Jquery call
Post by: seadhna on July 15, 2013, 23:30:19
Fantastic - thanks!