2

I have all my js files in a folder under my custom theme:

htdocs/themes/<mytheme>/js

I load all these js files in 'mytheme.info' in this way:

scripts[] = js/<script1.js>
scripts[] = js/<script2.js>

All the javascript files are correctly loaded and are shown in the source code when I access the website.

In order to implement the tabs method I added jQuery and jQuery-UI libraries:

jquery-1.7.2.min.js
jquery-ui-1.8.21.custom.min.js

I have also added my 'custom.js' file with the code for implementing the tab method from jQuery-UI:

$(function() {
    $( "#tabs" ).tabs();
});   

These three .js files also load properly and appear in the source code of the webpage.

In one of my modules I added the sample code in order to create the tabs:

<div class="demo">

<div id="tabs">
    <ul>
        <li><a href="#tabs-1">Nunc tincidunt</a></li>
        <li><a href="#tabs-2">Proin dolor</a></li>
        <li><a href="#tabs-3">Aenean lacinia</a></li>
    </ul>
    <div id="tabs-1">
        <p>Proin elit arcu, rutrum commodo, vehicula tempus, commodo a, risus. Curabitur nec arcu. Donec sollicitudin mi sit amet mauris. Nam elementum quam ullamcorper ante. Etiam aliquet massa et lorem. Mauris dapibus lacus auctor risus. Aenean tempor ullamcorper leo. Vivamus sed magna quis ligula eleifend adipiscing. Duis orci. Aliquam sodales tortor vitae ipsum. Aliquam nulla. Duis aliquam molestie erat. Ut et mauris vel pede varius sollicitudin. Sed ut dolor nec orci tincidunt interdum. Phasellus ipsum. Nunc tristique tempus lectus.</p>
    </div>
    <div id="tabs-2">
        <p>Morbi tincidunt, dui sit amet facilisis feugiat, odio metus gravida ante, ut pharetra massa metus id nunc. Duis scelerisque molestie turpis. Sed fringilla, massa eget luctus malesuada, metus eros molestie lectus, ut tempus eros massa ut dolor. Aenean aliquet fringilla sem. Suspendisse sed ligula in ligula suscipit aliquam. Praesent in eros vestibulum mi adipiscing adipiscing. Morbi facilisis. Curabitur ornare consequat nunc. Aenean vel metus. Ut posuere viverra nulla. Aliquam erat volutpat. Pellentesque convallis. Maecenas feugiat, tellus pellentesque pretium posuere, felis lorem euismod felis, eu ornare leo nisi vel felis. Mauris consectetur tortor et purus.</p>
    </div>
    <div id="tabs-3">
        <p>Mauris eleifend est et turpis. Duis id erat. Suspendisse potenti. Aliquam vulputate, pede vel vehicula accumsan, mi neque rutrum erat, eu congue orci lorem eget lorem. Vestibulum non ante. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Fusce sodales. Quisque eu urna vel enim commodo pellentesque. Praesent eu risus hendrerit ligula tempus pretium. Curabitur lorem enim, pretium nec, feugiat nec, luctus a, lacus.</p>
        <p>Duis cursus. Maecenas ligula eros, blandit nec, pharetra at, semper at, magna. Nullam ac lacus. Nulla facilisi. Praesent viverra justo vitae neque. Praesent blandit adipiscing velit. Suspendisse potenti. Donec mattis, pede vel pharetra blandit, magna ligula faucibus eros, id euismod lacus dolor eget odio. Nam scelerisque. Donec non libero sed nulla mattis commodo. Ut sagittis. Donec nisi lectus, feugiat porttitor, tempor ac, tempor vitae, pede. Aenean vehicula velit eu tellus interdum rutrum. Maecenas commodo. Pellentesque nec elit. Fusce in lacus. Vivamus a libero vitae lectus hendrerit hendrerit.</p>
    </div>
</div>

</div><!-- End demo -->



<div class="demo-description" style="display: none; ">
<p>Click tabs to swap between content that is broken into logical sections.</p>
</div><!-- End demo-description -->

Wich appears in the webpage but without format, meaning, without implementing the .tabs method from jQuery.

Also the console doesn't output any error messages.

This is the link to the jQueryUI Tabs demo:

JQuery Tabs Demo

Any idea what am I missing here?

3 Answers 3

2

It's very, very unlikely that you'll get jQuery 1.7 to work with Drupal 6. I haven't even heard of anyone getting it properly* set up in Drupal 7 as yet.

The question is...why do you need to? Drupal 6 comes with jQuery built-in, and you can get that up to v1.3.2 with the jQuery Update module. Since 1.3.2 is the minimum required version for jQuery UI 1.8.21 you should be good to go with that.

I'd advise installing the jQuery UI module; it makes it very easy to include the required libraries in your page requests.

* I've heard of people getting close, but there's always something that doesn't work properly.

0

Apart from what Clive focused.

You are missing $(document).ready() in your custom.js file.

(function($) {
  $(document).ready(function(){
    $( "#tabs" ).tabs();
  });
})(jQuery);

The other way can be adding js code in page footer by calling drupal_add_js in your custom module.

drupal_add_js('$("#tabs").tabs();', 'inline', 'footer');
1
  • 2
    $(function() { is an alias of $(document).ready(function(){ so both will work (see jQuery ready() docs). +1 for including the closure (always a good idea), but it's not strictly necessary in Drupal 6 :)
    – Clive
    Commented Jun 22, 2012 at 14:58
0

I think your problem was the conflict beetween the native Drupal 6 jQuery and the 1.7.3 added in theme. You can, via preprocess, delete the native Drupal 6 jQuery and substitute it with jQuery 1.7.3

Try this code:

function <your-theme-name>_preprocess_page(&$vars) {
  // get all defined scripts as an array 
  $scripts = drupal_add_js();

  // get jQuery core parameters
  $jQuery = $scripts['core']['misc/jquery.js']; 

  // remove jQuery
  unset($scripts['core']['misc/jquery.js']);

  // prepend jQuery to core scripts array
  $scriptsCore = array_reverse($scripts['core'], true);
  $scriptsCore[path_to_theme().'/js/jquery-1.7.2.min.js'] = $jQuery;
  $scriptsCore = array_reverse($scriptsCore, true); 

  // replace core scripts
  $scripts['core'] = $scriptsCore;
} 

You have to delete jquery-1.7.2.min.js in your your-theme-name.info

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.