Use jQuery with typolight howto

User-contributed tutorials, tips and tricks

Use jQuery with typolight howto

Postby Vera » Sun Feb 21, 2010 10:35 am

More often people ask if jQuery can be used with TYPOlight (instead of Mootools). Because this is possible and even easy to do I wrote this short tutorial based on this original topic

Required files
You need to download some files:
jQuery from http://www.jQuery.com
the lightbox from http://warren.mesozen.com/jquery-lightbox/

I attached the files I used in this tutorial, you'll be sure to have the same files I did when writing this.

If you download the latest jquery release you need to change filenames in the code later on in this tutorial.

File location
The downloaded jquery file needs to be placed in the directory: /typolight_root/plugins/jquery
The lightbox files go into: /typolight_root/plugins/jquery/lightbox
(also see attached file)

Template change
Copy /typolight_root/system/modules/frontend/templates/fe_page.tpl into /typolight_root/templates. Changes you make to this file will be used instead of the original.

Edit the file and look for the mootools scripts which we'll remove or comment out to be sure. So comment out or remove the following two lines:
Code: Select all
<script type="text/javascript" src="plugins/mootools/mootools-core.js"></script>
<script type="text/javascript" src="plugins/mootools/mootools-more.js"></script>

Directly below these two lines add:
Code: Select all
<link rel="stylesheet" href="plugins/jquery/lightbox/css/lightbox.css" type="text/css" media="screen" />
<script type="text/javascript" src="plugins/jquery/jquery-1.2.6.pack.js"></script>
<script type="text/javascript" src="plugins/jquery/lightbox/jquery.lightbox.js"></script>
<script type="text/javascript" >
   // accordion functionality
   accordionOpenFirst = true;
   accordionSpeed = 'slow';
   $(document).ready(function() {
      // hide all
      $('.ce_accordion .accordion').hide();

      // open first accordion item
      if ( accordionOpenFirst ) {
         $('.ce_accordion:first').find('.toggler').toggleClass('opened').end()
            .find('.toggler ~ .accordion').slideDown();
      }

      // add onclick event for toggler
      $('.ce_accordion .toggler').click(function() {
         if ( $(this).parent().find('.toggler ~ .accordion').is(":hidden") ) {
            $('.toggler ~ .accordion').slideUp(accordionSpeed);
            $(this).parent().find('.toggler').toggleClass('opened').end()
               .find('.toggler ~ .accordion').slideDown(accordionSpeed);
         } else {
            $('.toggler ~ .accordion').slideUp(accordionSpeed);
         }
      });
   });

   // lightbox functionality
   $(document).ready(function(){
      $("a[rel*=lightbox]").lightbox();
   });
</script>
note: You can also add this code to the page layout under "Additional <head> tags" rather the changing the main template itself. Though I haven't tested if this works with the two mootools lines that are in the default template...

TL backend changes
The only change in the backend is to check if the page layouts include any mootools templates. If so; uncheck them all.

Things to consider
  • This code does not include the tablesort, however; Ruud mentions in the original topic he wrote the code for it. So if you need the tablesort, ask him...
  • You can take out the accordion code if you do not plan on using it.
  • You can also put the code into a js file and include that in the header.
  • TL might change, I tested this with TL 2.8

Have fun using jQuery!
Attachments
typolight_jquery.zip
(27.92 KiB) Downloaded 61 times
Last edited by Vera on Mon Feb 22, 2010 12:24 pm, edited 1 time in total.
User avatar
Vera
User
 
Posts: 200
Joined: Mon Jun 29, 2009 8:28 am

Re: Use jQuery with typolight howto

Postby ramjet » Sun Feb 21, 2010 10:58 am

Excellent Vera. Thank you very much. :D
ramjet
User
 
Posts: 536
Joined: Sat Jun 20, 2009 12:24 pm

Re: Use jQuery with typolight howto

Postby Ben » Tue Feb 23, 2010 9:01 am

Thanks for putting this tutorial together, Vera. I think many people will find it helpful, especially since you've consolidated all the info into one place.
User avatar
Ben
Contao team
 
Posts: 496
Joined: Wed Jun 10, 2009 7:45 pm
Location: Atlanta, Georgia

Re: Use jQuery with typolight howto

Postby Vera » Sun Mar 14, 2010 12:40 pm

I just wanted to say that jquery 1.4.2 seems to have a bug in the attribute selector. If the selector for attributes contains a dot (ex a[href*=typolight.org]) then this seems to be a problem.

There are two versions of the lightbox script, both claim version nr 0.5 and both claim the same creation date in the comments. If you have the one that around line 412 has a line similar to the one I wrote down below, then you should alter that line...

I changed line 412 in the lightbox js file into the following to make it work as originally designed:
var src = $("script[src*='jquery.lightbox.js']").first().attr('src')
User avatar
Vera
User
 
Posts: 200
Joined: Mon Jun 29, 2009 8:28 am

Re: Use jQuery with typolight howto

Postby vickhoff » Tue Apr 27, 2010 2:41 pm

Im totally new on Typolight, so just to be sure...
I have to inactivate Mootools in order to activate jQuery?
vickhoff
User
 
Posts: 1
Joined: Tue Apr 27, 2010 2:36 pm

Re: Use jQuery with typolight howto

Postby Ben » Tue Apr 27, 2010 6:51 pm

No - you don't have to get rid of mootools to get jQuery working. I use the 2 libraries at the same time quite often.
User avatar
Ben
Contao team
 
Posts: 496
Joined: Wed Jun 10, 2009 7:45 pm
Location: Atlanta, Georgia

Re: Use jQuery with typolight howto

Postby nvisioncurtis » Thu Jun 17, 2010 5:59 pm

This is great, thanks!

I'm assuming that any jQuery plugin can be used with these same steps. I plan on trying this with a different jQuery plugin (ad-gallery).
nvisioncurtis
User
 
Posts: 75
Joined: Fri Dec 11, 2009 4:01 pm
Location: New York, NY USA

Re: Use jQuery with typolight howto

Postby Toflar » Fri Jun 18, 2010 11:05 am

The only thing you have to remember is to load the Mootools library first and then jQuery and shift it into the noConflict-Mode :)
User avatar
Toflar
User
 
Posts: 96
Joined: Fri Jun 19, 2009 5:30 pm
Location: Lyss, Switzerland

Re: Use jQuery with typolight howto

Postby ernestmcd » Wed Jul 28, 2010 1:25 pm

Vera:

Thanks for taking the time to post this tutorial, it is very helpful.

It looks like the source code for the light box has moved several times recently, the current code is available as of this post date at GitHub:

http://github.com/krewenki/jquery-lightbox/

Thanks!
ernestmcd
User
 
Posts: 32
Joined: Tue Sep 08, 2009 8:21 pm
Location: Snellville, GA


Return to User tutorials

Who is online

Users browsing this forum: No registered users