Yeap, have been trying to grasp how to use this modules plug-ins, and especially Tooltip, by reading issues posted under this module, but no, I think it's not quite clear on how to implement it in a nodes content. Can some one please try to explain how to do this?

Thanks in advance.

Comments

jaxpax’s picture

No one?

heavy_engineer’s picture

Add this to the bottom of your template.php in your theme dir

   jquery_plugin_add('tooltip');

Or create a module and load it from that.

jaxpax’s picture

thanks a bunch but nothing really happens when hovering the image...

1. I added <?php jquery_plugin_add('tooltip');?> in the bottom of node.tpl.php
2. I uploaded tools.tooltip-1.1.3.js and tools.tooltip-1.1.3.css in jqueri_plugin folder
3. The tooltip plugin putting jquery.tooltip.min.js is in jqueri_plugin folder.
4. I added the following lines in node content area:

<!-- the tooltip --><div id="demotip">
	&nbsp;</div>
<!-- and the triggers --><div id="demo">
	<img src="http://www.my-site.net/sites/default/files/site-graphics/my-image.gif" title="The tooltip text #1" /></div>

The tooltip script is invoked according to the source in the browser: <script type="text/javascript" src="/sites/all/modules/jquery_plugin/jquery.tooltip.min.js?S"></script>

ludo1960’s picture

I think you must put the code in template.tpl.php and not node.tpl.php as this wont work!

jaxpax’s picture

Thanks for the reply.
I put the code in the template.php file (couldn't find template.tpl.php in my themes folder) but still nothing happens. :(

What about the other steps I explained that I did, are they correct?
I know I'm a little bit stubborn about knowing how to fix this, because It's very important to me. It's quite frustrating having to stand beside and watch all the great things one can do with jQuery and not being able to get it to work, so I hope you guys bare with me a little bit longer. =)

jghyde’s picture

This module was built to be added as a dependency for other modules by module developers. Theme developers can still use it, but you have to make the jquery_add_plugin() call before the page.tpl.php loads. In this case, the best way is to call the jquery_plugin_add($plugin) in the node.tpl.php template. Then, all features of the particular jquery tools module are available on the page with that particular node.tpl.php.

If you'd like more control, you can ignore this plugin in lieu of adding the call for the plugin into the *.info of the theme, and store the *js modules in the sites/all/themes/[theme-name] directory.

jaimealsilva’s picture

For a theme put the function call in the template.php file, outside any function.

scottsawyer’s picture

I should be understanding this, but alas, I am still struggling. So far, I have in my template.php:

jquery_add_plugin('tooltip');

and in the header of my page.tpl.php

	<script type="text/javascript">
	<!--//--><![CDATA[//><!--
	  $(document).ready(function(){
	    $(".social-links a[title]").tooltip();
		});
		//--><!]]>
	</script>

So far, no results. What I am looking for is a tooltip when the mouse hovers over an anchor in an unordered list with class="social-links".

Thank you in advance for any help :)

scottsawyer’s picture

Ok, found the first error: should be jquery_plugin_add('tooltip'); not, jquery_add_plugin('tooltip'); what that syntax!

So now I see I am loading the tooltip plugin, but it is still not firing with my document ready function.

I have tried using the javascript inline and in the header in my page.tpl.php.

Any help would be great.

mogop’s picture

I get error

Parse error: parse error, expecting `'&'' or `T_VARIABLE' in G:\wamp\www\sweetdreams\sites\all\themes\sweetdreams\template.php on line 155

when I put jquery_plugin_add('tooltip'); in my template.tpl.php (using ZEN theme) and also I add jquery.tools.min.js in my .info file

novakov’s picture

Version: 6.x-1.9 » 7.x-1.0
Assigned: Unassigned » novakov

could not get to work it too
Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting '&' or T_VARIABLE in ...node.tpl.php / template.php

trevorleenc’s picture

having the same issue as scottsawyer

here is the code in my template.php

jquery_plugin_add('tooltip');
drupal_add_js(' $(document).ready(function() {
          $("[title]").tooltip();
          });',
         'inline'
);

this "should" kick off the tooltip for anything on my page that has a title...I also have the css code in my stylesheet, but nothing seems to be appearing.

.tooltip {
	display:none;
	background: #000;
	font-size:12px;
	height:70px;
	width:160px;
	padding:25px;
	color:#fff;	
}
jghyde’s picture

trevor--

I disagree with the concept of placing this function outside of, say, a preprocess function. It gets called like 400 times when you do that--very inefficient! Here is a suggestion of how to use it more Drupaly:

Drupal 6 Example

<?php
/**
 *  Where 'templateName' == the name of your template
 *  preprocess the node
 */
function templateName_preprocess_node(&$vars) {
  // further restrict to just 'story' node types (optional)
  if ($vars['node']->type == 'story') {
    // Check to make sure the module is enabled to prevent site crashes
    if (module_exists('jquery_plugin') {
      jquery_plugin_add('tooltip');
      drupal_add_js(' $(document).ready(function() {
            $("[title]").tooltip();
            });',
           'inline'
      );
    }
  }
}
?>

Drupal 7 requires a different way to call the jQuery selector. The D7 jQuery protects the '$' function character so other javascript libraries can use it.

Drupal 7 example:

<?php
/**
 *  Where 'templateName' == the name of your template
 *  preprocess the node
 */
function templateName_preprocess_node(&$vars) {
  // further restrict to just 'story' node types (optional)
  if ($vars['node']->type == 'story') {
    // Check to make sure the module is enabled to prevent site crashes
    if (module_exists('jquery_plugin') {
      jquery_plugin_add('tooltip');
      drupal_add_js('
      (function($) { 
        $(document).ready(function() {
          $("[title]").tooltip();
         });
      })(jQuery);',
           'inline'
      );
    }
  }
}
?>

Note the change to the jQuery inline script to enclose your regular jQuery function in the '$' declaration:

(function($) { 
  // .. regular 'ol jQuery code here...
})(jQuery);
AndrejT’s picture

I wish to use a jQuery Countdown Script in maintenance mode page (Drupal 7).
How can I add this script to that page?

Thanks in advance.

ZPRaven’s picture

I used "Drupal 7 example" (from jghyde) - no results. Only blank page. What's the problem?

woop_light’s picture

This seems like a wonderful module. Any chance someone might be able to spell out (in painful detail) how to configure the simplest jquery function -- such as putting a tooltip on the site logo? It would help a lot of someone described exactly where to put the code. I think if some of us could just see how the pieces fit together we would be able to run with it!

This helped me see how everyone can be configured: http://drupal.org/project/jq4dat

woop

bluestarstudios’s picture

Can somebody please help out here? I followed the steps. I can easily get this to work in Drupal 6, but no success in Drupal 7. Here's my template.php file:

/**
 * Add javascript files for Tooltip.
 */
drupal_add_library('jquery_plugin', 'tooltip');
drupal_add_js(' jQuery(document).ready(function() {
         jQuery(".locked").tooltip("#tooltip");
         });',
        'inline'
);

In my nodes I have a field that has a class="locked". Additionally I have a block that has my tooltip content
<div id="tooltip">My Tooltip Content</div>
Finally I have this in my css

/* tooltip styling. by default the element to be styled is .tooltip  */
#tooltip {
	display:none;
	background:transparent url('images/black_arrow.png');
	font-size:12px;
	height:70px;
	width:160px;
	padding:25px;
	color:#fff;	
}

The trigger seems to initialize something, however it totally doesn't get the tooltip to show. Instead it renders the remaining JS on the page inoperable. Do I need to use JQuery Update to use Tooltip? Or do i need to download any additional libraries?

THANKS!

gagarine’s picture

#13 is wrong for D7 and you will end up with a blank page. The JS is also not good, you should not use document.ready anymore for D7 see http://drupal.org/node/756722.

D7 example:

    drupal_add_library('jquery_plugin', 'cycle');

drupal_add_library() is a Drupal core function the first param is alway going to be jquery_plugin and the seconde the name of the plugin you want to load.

No need to download anything more than this module, plugins are packaged inside.

I disagree with the concept of placing this function outside of, say, a preprocess function. It gets called like 400 times when you do that--very inefficient! Here is a suggestion of how to use it more Drupaly:

This is not right. If you call the function inside your template.php outside any function your code is going to be called only one single time. But if you call it inside a preprocess function he can be called more than one time (like preprocess_node).

loopy1492’s picture

Issue summary: View changes

I am losing my bananas.

I have installed this module.

I have added the following to my theme__preprocess_html function:

drupal_add_library('jquery_plugin', 'tooltip');

I have installed the jQuery Update module.

I have this in a node and BOTH of the alerts work, but not the tooltip. What am I doing wrong?

<table class="descriptiontable">
    <thead>
        <tr>
            <th class="help" title="Hello from th 1">Head 1</th>
            <th class="help" title="Hello from th 2">Head 2</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td class="help" title="Hello from td 1">Data 1</td>
            <td class="help" title="Hello from td 2.  I am a longer description to give you an idea of what I look like.">Data 2</td>
        </tr>
    </tbody>
</table>
<script type="text/javascript">
    alert("hello from script");
    (function ($) {
        $( '.descriptiontable').tooltip({
        });
        alert($('body').html());     
    })(jQuery);
</script>
loopy1492’s picture

Got it to work. I had to downgrade to jQuery 1.7. Go figure.