Usted está aquí: Inicio Tech Blog Having two jquery versions in one Plone

Having two jquery versions in one Plone

Quick and dirty hack to have the default jquery (1.4) and another updated jquery on the same site.

Intro

I'm working on a site that uses a lot of galleries made with Jquerytools. Once the galleries grew up, a small bug appared: after the 15th or 16th element, the gallery started to jump. That can be fixed by upgrading to a new version of jquery. Initially, I just dropped the new minified version of jQuery into one of my skin folders on my theme.Solved!

Well, not that easy. One add-on I'm planning to add to the site started to work funny. With the default jquery from plone it behaves just nice. So, in the meanwhile, to make things work, Plone has to serve jQuery 1.7 for galleries and the plain old jQuery 1.4 for the rest of the site.

How to do it

  • Place the minified jQuery 1.7 to some skin folder in your theme. Do not name it jquery.js, otherwise it will override the one that Plone ships out of the box.
  • Open ZMI and on portal_javascripts add a new entry for the js file. Here is how it looks.

    js_registry

    The position is important. Place it just before or after jquery.js. Don't leave it on the bottom.

  • Next thing is the condition: request/use_new_jquery. This can be acompished in the a view class. For example:
    class CatalogFolderView(grok.View):
        """                                                                                                                      
        Catalog view for books, audios or dvd's                                                                                  
        """
        grok.context(IATUnifiedFolder)
        grok.template('catalog_view')
        grok.name('folder_catalog_view')
    
        def update(self):
    	super(CatalogFolderView, self).update()
    	#hack hack to be able to use jquery 1.7 on new                                                                       
            self.request.set('use_new_jquery', True)
    
    
  • Restart plone and reload. Once test are done, you can go to portal_setup un the ZMI and download the portal_js settings.
Acciones de Documento

Comentarios (0)