473,385 Members | 2,069 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

problem with tool tip prototype

Hey I'm using this tooltip which uses prototype 1.6.1.js

Expand|Select|Wrap|Line Numbers
  1. /*
  2.  * Copyright (c) 2006 Jonathan Weiss <jw@innerewut.de>
  3.  *
  4.  * Permission to use, copy, modify, and distribute this software for any
  5.  * purpose with or without fee is hereby granted, provided that the above
  6.  * copyright notice and this permission notice appear in all copies.
  7.  *
  8.  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9.  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10.  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11.  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13.  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14.  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15.  */
  16.  
  17.  
  18. /* tooltip-0.2.js - Small tooltip library on top of Prototype 
  19.  * by Jonathan Weiss <jw@innerewut.de> distributed under the BSD license. 
  20.  *
  21.  * This tooltip library works in two modes. If it gets a valid DOM element 
  22.  * or DOM id as an argument it uses this element as the tooltip. This 
  23.  * element will be placed (and shown) near the mouse pointer when a trigger-
  24.  * element is moused-over.
  25.  * If it gets only a text as an argument instead of a DOM id or DOM element
  26.  * it will create a div with the classname 'tooltip' that holds the given text.
  27.  * This newly created div will be used as the tooltip. This is usefull if you 
  28.  * want to use tooltip.js to create popups out of title attributes.
  29.  * 
  30.  *
  31.  * Usage: 
  32.  *   <script src="/javascripts/prototype.js" type="text/javascript"></script>
  33.  *   <script src="/javascripts/tooltip.js" type="text/javascript"></script>
  34.  *   <script type="text/javascript">
  35.  *     // with valid DOM id
  36.  *     var my_tooltip = new Tooltip('id_of_trigger_element', 'id_of_tooltip_to_show_element')
  37.  *
  38.  *     // with text
  39.  *     var my_other_tooltip = new Tooltip('id_of_trigger_element', 'a nice description')
  40.  *
  41.  *     // create popups for each element with a title attribute
  42.  *    Event.observe(window,"load",function() {
  43.  *      $$("*").findAll(function(node){
  44.  *        return node.getAttribute('title');
  45.  *      }).each(function(node){
  46.  *        new Tooltip(node,node.title);
  47.  *        node.removeAttribute("title");
  48.  *      });
  49.  *    });
  50.  *    
  51.  *   </script>
  52.  * 
  53.  * Now whenever you trigger a mouseOver on the `trigger` element, the tooltip element will
  54.  * be shown. On o mouseOut the tooltip disappears. 
  55.  * 
  56.  * Example:
  57.  * 
  58.  *   <script src="/javascripts/prototype.js" type="text/javascript"></script>
  59.  *   <script src="/javascripts/scriptaculous.js" type="text/javascript"></script>
  60.  *   <script src="/javascripts/tooltip.js" type="text/javascript"></script>
  61.  *
  62.  *   <div id='tooltip' style="display:none; margin: 5px; background-color: red;">
  63.  *     Detail infos on product 1....<br />
  64.  *   </div>
  65.  *
  66.  *   <div id='product_1'>
  67.  *     This is product 1
  68.  *   </div>
  69.  *
  70.  *   <script type="text/javascript">
  71.  *     var my_tooltip = new Tooltip('product_1', 'tooltip')
  72.  *   </script>
  73.  *
  74.  * You can use my_tooltip.destroy() to remove the event observers and thereby the tooltip.
  75.  */
  76.  
  77. var Tooltip = Class.create();
  78. Tooltip.prototype = {
  79.   initialize: function(element, tool_tip) {
  80.     var options = Object.extend({
  81.       default_css: false,
  82.       margin: "0px",
  83.         padding: "5px",
  84.         backgroundColor: "#d6d6fc",
  85.         min_distance_x: 5,
  86.       min_distance_y: 5,
  87.       delta_x: 0,
  88.       delta_y: 0,
  89.       zindex: 1000
  90.     }, arguments[2] || {});
  91.  
  92.     this.element      = $(element);
  93.  
  94.     this.options      = options;
  95.  
  96.     // use the supplied tooltip element or create our own div
  97.     if($(tool_tip)) {
  98.       this.tool_tip = $(tool_tip);
  99.     } else {
  100.       this.tool_tip = $(document.createElement("div")); 
  101.       document.body.appendChild(this.tool_tip);
  102.       this.tool_tip.addClassName("tooltip");
  103.       this.tool_tip.appendChild(document.createTextNode(tool_tip));
  104.     }
  105.  
  106.     // hide the tool-tip by default
  107.     this.tool_tip.hide();
  108.  
  109.     this.eventMouseOver = this.showTooltip.bindAsEventListener(this);
  110.     this.eventMouseOut   = this.hideTooltip.bindAsEventListener(this);
  111.     this.eventMouseMove  = this.moveTooltip.bindAsEventListener(this);
  112.  
  113.     this.registerEvents();
  114.   },
  115.  
  116.   destroy: function() {
  117.     Event.stopObserving(this.element, "mouseover", this.eventMouseOver);
  118.     Event.stopObserving(this.element, "mouseout", this.eventMouseOut);
  119.     Event.stopObserving(this.element, "mousemove", this.eventMouseMove);
  120.  
  121.   },
  122.  
  123.   registerEvents: function() {
  124.     Event.observe(this.element, "mouseover", this.eventMouseOver);
  125.     Event.observe(this.element, "mouseout", this.eventMouseOut);
  126.     Event.observe(this.element, "mousemove", this.eventMouseMove);
  127.   },
  128.  
  129.   moveTooltip: function(event){
  130.       Event.stop(event);
  131.       // get Mouse position
  132.     var mouse_x = Event.pointerX(event);
  133.       var mouse_y = Event.pointerY(event);
  134.  
  135.       // decide if wee need to switch sides for the tooltip
  136.       var dimensions = Element.getDimensions( this.tool_tip );
  137.       var element_width = dimensions.width;
  138.       var element_height = dimensions.height;
  139.  
  140.       if ( (element_width + mouse_x) >= ( this.getWindowWidth() - this.options.min_distance_x) ){ // too big for X
  141.           mouse_x = mouse_x - element_width;
  142.           // apply min_distance to make sure that the mouse is not on the tool-tip
  143.           mouse_x = mouse_x - this.options.min_distance_x;
  144.       } else {
  145.           mouse_x = mouse_x + this.options.min_distance_x;
  146.       }
  147.  
  148.       if ( (element_height + mouse_y) >= ( this.getWindowHeight() - this.options.min_distance_y) ){ // too big for Y
  149.           mouse_y = mouse_y - element_height;
  150.         // apply min_distance to make sure that the mouse is not on the tool-tip
  151.           mouse_y = mouse_y - this.options.min_distance_y;
  152.       } else {
  153.           mouse_y = mouse_y + this.options.min_distance_y;
  154.       } 
  155.  
  156.       // now set the right styles
  157.       this.setStyles(mouse_x, mouse_y);
  158.   },
  159.  
  160.  
  161.   showTooltip: function(event) {
  162.     Event.stop(event);
  163.     this.moveTooltip(event);
  164.       new Element.show(this.tool_tip);
  165.   },
  166.  
  167.   setStyles: function(x, y){
  168.     // set the right styles to position the tool tip
  169.       Element.setStyle(this.tool_tip, { position:'absolute',
  170.                                          top:y + this.options.delta_y + "px",
  171.                                          left:x + this.options.delta_x + "px",
  172.                                         zindex:this.options.zindex
  173.                                        });
  174.  
  175.       // apply default theme if wanted
  176.       if (this.options.default_css){
  177.             Element.setStyle(this.tool_tip, { margin:this.options.margin,
  178.                                                                padding:this.options.padding,
  179.                                               backgroundColor:this.options.backgroundColor,
  180.                                                               zindex:this.options.zindex
  181.                                              });    
  182.       }    
  183.   },
  184.  
  185.   hideTooltip: function(event){
  186.       new Element.hide(this.tool_tip);
  187.   },
  188.  
  189.   getWindowHeight: function(){
  190.     var innerHeight;
  191.       if (navigator.appVersion.indexOf('MSIE')>0) {
  192.           innerHeight = document.body.clientHeight;
  193.     } else {
  194.           innerHeight = window.innerHeight;
  195.     }
  196.     return innerHeight;    
  197.   },
  198.  
  199.   getWindowWidth: function(){
  200.     var innerWidth;
  201.       if (navigator.appVersion.indexOf('MSIE')>0) {
  202.           innerWidth = document.body.clientWidth;
  203.     } else {
  204.           innerWidth = window.innerWidth;
  205.     }
  206.     return innerWidth;    
  207.   }
  208.  
  209. }
  210.  
is called tooltipv0.2.js
I'm sure you've heard about it, the thing is that I'm having a little problem

I'm using one tooltip already and it works just fine and it displays everything correctly...
But I need to create a new tooltip when I right click an image and it is showing the tooltip but I need it to stay so I can edit the info inside the tooltip... Is just a table with check boxes.... I've tried everything in modifying the tooltip v02 but came up with nothing more than errors...

any help would be greatly appreciated in advance... this is the code that i have on the html file...

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. document.observe("dom:loaded", function() {    
  3.     $$(".tool").each(function(node){
  4.           var my_tooltip = new Tooltip(node.readAttribute('id'), 'tooltip-'+node.readAttribute('id'))
  5.     });
  6.  
  7. });        
  8. </script>
  9.  
and each div in the code has a name (eg. tt1) and then the table or code for each one is tooltip-tt1 for example



and then
May 14 '10 #1
1 2349
acoder
16,027 Expert Mod 8TB
If you need to stay, then don't hide the tooltip onmouseout (line 110). Hide it onclick (e.g. a close link/button, or clicking on the page outside the tooltip boundaries).

Alternatively, use another tooltip which already has this feature.
May 15 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: hardrock | last post by:
Hello! I'm working with the prototype library version 1.4.0 and having a strange error lately. When I want to make an Ajax.Updater call, it basically works. But as soon as I put the call into...
31
by: Tony | last post by:
I just noticed that prototype.js is one of the files in the Ajax.NET distribution - I'm pretty concerned about this. Does anyone know if this is the same "prototype.js" that is not well-liked...
1
by: Gerry Vandermaesen | last post by:
Hi, Consider the following code: var Foo = Class.create(); Foo.prototype = { initialize: function() { this.bar = "Hello world"; },
1
by: thefarmer | last post by:
hello guys, I'm a newbie in this C++ world, can somebody help me to find a solution to my problem in this program: while ( message (answer , "yes") != 0) after compiling the program, theres an...
8
by: Chad Burggraf | last post by:
Hi all, I'm brand new to this newsgroup. I've been reading the FAQ's and some other documentation submitted by regulars of the group (such as "Javascript Best Practices" at...
8
by: James Black | last post by:
I am working on my own pop up calendar, mainly because the one I am currently using crashes the Safari browser at times. So, I want to verify that what I am doing will work, in that I want to be...
6
by: libsfan01 | last post by:
Hi all Im trying to use prototype for an xmlhttprequest, but it doesn't seem to be working cross-browser. Is there someway of getting it to be IE6 compatible (active x)? here's my code so...
6
by: Murray Hopkins | last post by:
Hi. THE QUESTION: How do I get a reference to my Object when processing an event handler bound to an html element ? CONTEXT: Sorry if it is a bit long. I am developing a JS calendar tool....
3
omerbutt
by: omerbutt | last post by:
hi there i have downloaded a prototype tooltip from http://www.nickstakenburg.com/projects/prototip/ the logic it uses is to call the script after creating the <div> for example i am using the...
15
by: MartinRinehart | last post by:
The FAQ shows a mod to String.prototype adding trim, trimRight and trimLeft. Flanagan states, "There is a strong argument against extending built- in types with your own methods; if you do so,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.