Drupal 6 Help with drupal_add_js / jquery_plugin('cycle')

n00b0101 - June 1, 2009 - 23:42

I've been trying a million different things in order to get the jquery cycle plugin working on my Drupal site, and it includes the plugin, but the code that is meant to execute is nowhere to be found...

I've got the following modules installed and enabled:
jquery update
jquery plugins

In my template.php file, I have:
jquery_plugin_add('cycle');

In my page.tpl.php file, I have (immediately after the tag):

<!-- header stuff, but omitted here... -->

<body>
<?php

drupal_add_js
(' $(document).ready(function() {
                $("#header-images").cycle("fade");
});'
,
       
'inline'
);

?>


<div id="page">
     <div id="header">
      <?php if ($logo) { ?><a href="<?php print $front_page ?>" title="<?php print t('Home') ?>"><img src="<?php print $logo ?>" alt="<?php print t('') ?>" /></a><?php } ?>
      <?php if ($site_slogan) { ?><div class='site-slogan'><?php print $site_slogan ?></div><?php } ?>
      <?php if (isset($secondary_links)) { ?><?php print theme('links', $secondary_links, array('class' => 'links', 'id' => 'subnavlist')) ?><?php } ?>
      <?php if (isset($primary_links)) { ?><?php print theme('links', $primary_links, array('class' => 'links', 'id' => 'navlist')) ?><?php } ?>
      <?php print $header; ?>
     
      <div id="header-images">
           <img src="/sites/all/themes/x/images/blue.png" />
           <img src="/sites/all/themes/x/images/red.png" />
      </div>
     </div>

...

And, my info file looks like this:

; $Id: jfwd.info,v 1.0 2007/06/08 05:50:57 jf Exp $
name = x
description = Draft theme
version = 1.0
core = 6.x
base theme = zen
stylesheets[all][] = style.css
scripts[] = x.js

I can see that it's correctly including the plugin file:
<script src="/sites/all/modules/jquery_plugin/jquery.cycle.min.js?y" type="text/javascript">

But, it doesn't look like it's picking up the drupal_add_js function just after the body tag?

<body id="thmr_779" class="tableHeader-processed thmr_call">
<div id="page">
<div id="header">
<div id="header-images">
<img width="874" height="165" src="/sites/all/themes/x/images/blue.png"/>
<img width="874" height="165" src="/sites/all/themes/x/images/red.png"/>
</div>
</div>

You might want to look at the

nevets - June 2, 2009 - 02:48

You might want to look at the Rotor Banner module which integrates the cycle plugin with views.

Tried Rotor Banner and the

n00b0101 - June 2, 2009 - 06:13

Tried Rotor Banner and the Views Rotator, but neither seems to work... In fact, it doesn't appear to be uploading the image at all...

AFAIK, you can't add

blueflowers - June 2, 2009 - 17:24

AFAIK, you can't add drupal_add_js to page.tpl.php as the scripts in HEAD are already processed via bootstrap.

Instead of drupal_add_js simply write it out as javascript

<script type="text/javascript">
  $(document).ready(function() {
    $("#header-images").cycle("fade");
  });
</script>

You'll also want to put this either in the HEAD portion of your HTML or at the very bottom, depending on your preference.

Hope that helps!

Fourth Wall Media
Toronto, Canada

 
 

Drupal is a registered trademark of Dries Buytaert.