balloons.html 9.63 KB
<html>
<head>
 <title>Balloon Tooltips</title>
 <script type="text/javascript" src="js/balloon.config.js"></script>
 <script type="text/javascript" src="js/balloon.js"></script>
 <script type="text/javascript" src="js/box.js"></script>
 <script type="text/javascript" src="js/yahoo-dom-event.js"></script> 
 <!-- Note: This CSS is specific to this page -- it is not required for balloon tooltips to work -->
 <style>
  .tt {
    background-color:lightsteelblue;
    color:blue;
    text-decoration:none;
    cursor:pointer;
  }
  .hidden {
    display:none;
  }
  pre {
    background-color:gainsboro;
    padding:10px;
    margin-left:20px;
    margin-right:20px;
    font-family:courier;
    font-size:90%;
  }
  b.y { background-color:yellow }
 </style>

 <script type="text/javascript">
   // white balloon with default configuration
   var balloon    = new Balloon;
   BalloonConfig(balloon,'GBubble');

   // plain balloon tooltip
   var tooltip  = new Balloon;
   BalloonConfig(tooltip,'GPlain');

   // fading balloon
   var fader = new Balloon;
   BalloonConfig(fader,'GFade');   

   // a plainer popup box
   var box         = new Box;
   BalloonConfig(box,'GBox');

   // a box that fades in/out
   var fadeBox     = new Box;
   BalloonConfig(fadeBox,'GBox');
   fadeBox.bgColor     = 'black';
   fadeBox.fontColor   = 'white';
   fadeBox.borderStyle = 'none';
   fadeBox.delayTime   = 200;
   fadeBox.allowFade   = true;
   fadeBox.fadeIn      = 750;
   fadeBox.fadeOut     = 200;

 </script>
</head>
<body>
<div style="border:1px solid blue;background:ivory;padding:10px;font-family:arial, sans-serif">
<img style="float:right" src="images/sample.png" width=300>
</span>
<span id="sheldon" style="display:none">
<center>
<img src="images/sheldon.jpg">
<br>mckays@cshl.edu
</center>
</span>
<br>
<ul>
<li>This page is a demonstration of <a href="http://www.gmod.org/wiki/index.php/Popup_Balloons">balloon.js</a>.</li>
<li>Contact <a href="mailto:mckays@cshl.edu">the author</a> for help.</li>
</ul> 
<p>
The balloon.js package is written in object-oriented JavaScript and allows you to add configurable balloon tooltips 
(AKA popup balloons, bubbles, rollover tooltips etc., etc.) to your website.  It is generic and is portable to most web sites.
<p>
The balloons are dynamically sized in both the vertical and horizontal dimensions and the left/right/up/down orientation
is calculated automatically based on the position of the cursor. Balloon contents can be provided locally in your own HTML or remotely via AJAX.
This package is open source and free to all as long as the copyright notice is retained.  See below for demonstrations and documentation.
</p>


<hr>
<h1 style="align:left">Demo:</h1>
<div style="border:1px solid black;width:90%;margin:auto">
<table cellpadding=3 style="width:100%">
<tr>
<th width=10% align=left rowspan=2>Demonstration:</th>
<th width=30% class="tt" style="border:1px solid black"
  onmouseover="balloon.showTooltip(event,'This is a balloon tooltip.  \
      It will vanish if you leave this box',0,250)">mouse over this box</th>
<th width=30% class="tt">
<span onmouseover="balloon.showTooltip(event,'Your are hovering, I said click me!')"
      onclick="balloon.showTooltip(event,'Your sticky message goes here.',1)">click me</span>
</th>
<th width=30% class="tt"><span onmouseover="tooltip.showTooltip(event,'This is a plain balloon.<br>Your message goes here!')">plainer balloon</span></th>
</tr>
<tr>
<th  class="tt"><span onmouseover="fader.showTooltip(event,'Your message goes here!')">fading balloon</span></th>
<th  class="tt"><span onmouseover="fadeBox.showTooltip(event,'Your message goes here!')">fading box</span></th>
<th  class="tt"><span onmouseover="box.showTooltip(event,'Your sticky message goes here!<br><a href=\'http://www.google.com\'>Your link goes here...</span>',1,275)">
sticky box</span></th>
</tr>
<tr>
<th align=left>Documentation:</th>
<th colspan=3 align=left class=tt>
<a class=tt href="http://gmod.org/wiki/Popup_Balloons"
   onmouseover="balloon.showTooltip(event,'Click this link to go to documentation on the GMOD Wiki')"
   onmouseout="alert('Read the docs, when you get a chance...')">
http://gmod.org/wiki/Popup_Balloons
</th>
</tr>
<tr>
<th align=left>Download:</th>
<th class=tt colspan=3 align=left>
<a class=tt href="http://mckay.cshl.edu/downloads/balloons.tar.gz"
   onmouseover="box.showTooltip(event,'Click to download the whole package, with all required scripts, images, etc',0,300)">
balloons.tar.gz</a>
<font color="black">
or for windows users...
</font>
<a class=tt href="http://mckay.cshl.edu/downloads/balloons.zip"
   onmouseover="box.showTooltip(event,'Click to download the whole package. Try this if your unzip program complains that the tar.gz file is corrupted')">
balloons.zip
</a>

</th>
</tr>
</table>
</div>
</div>
<br>

<!-- These hidden elements contain balloon contents -->
<div id="lorem1" class="hidden">
Lorem ipsum dolor sit amet, <b><i>consectetuer adipiscing elit</b></i>. Vestibulum iaculis,
ligula quis fringilla volutpat, metus mi molestie lorem, <span style="color:red">quis accumsan pede
turpis nec metus.</span> Lorem ipsum dolor sit amet, consectetuer adipiscing elit.'
</div>

<div id="lorem2" class="hidden">
<a href="http://www.lipsum.com" target="_new" style="color:blue">What is <i>Lorem ipsum...</i>?</a>
Lorem ipsum dolor sit amet, <b><i>consectetuer adipiscing elit</b></i>. Vestibulum iaculis
, ligula quis fringilla volutpat, metus mi molestie lorem, quis accumsan pede
turpis nec metus. Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
</div>

<p>
This is an example of a simple balloon <span class=tt onmouseover="balloon.showTooltip(event,'I am a simple message...')">message</span>

<pre>
 &lt;span onmouseover="<b class=y>balloon</b>.showTooltip(event,'I am a simple message...')"&gt;message&lt;/span&gt;
</pre>

This is an example of the same message with a different balloon <span class=tt
onmouseover="tooltip.showTooltip(event,'I am a simple message...')">style</span>

<pre>
 onmouseover="<b class=y>tooltip</b>.showTooltip(event,'I am a simple message...')"&gt;message&lt;/span&gt;
</pre>

This is an example of the same message with a box <span class=tt
onmouseover="box.showTooltip(event,'I am a simple message...')">style</span>

<pre>
 onmouseover="<b class=y>box</b>.showTooltip(event,'I am a simple message...')"&gt;message&lt;/span&gt;
</pre>

</p>

<p>
Roll over <span class=tt onmouseover="balloon.showTooltip(event,'load:lorem1')">
this text</span> for an example of HTML-formatted text loaded from a hidden &lt;div&gt; element.
<pre>
 onmouseover="balloon.showTooltip(event,<b class=y>'load:lorem1'</b>)"
 ...
 &lt;div id="lorem1" style="display:none"&gt;
   Lorem ipsum dolor sit amet, &lt;b&gt;&lt;i&gt;consectetuer adipiscing elit&lt;/b&gt;&lt;/i&gt;. Vestibulum iaculis,
   ligula quis fringilla volutpat, metus mi molestie lorem, &lt;span style=&#34color:red&#34;&gt;quis accumsan pede
    turpis nec metus.&lt;/span&gt; Lorem ipsum dolor sit amet, consectetuer adipiscing elit.'
 &lt;/div&gt;

</pre>

<span id=sticky>
Adding a third argument makes the tooltip <span class=tt
onmouseover="balloon.showTooltip(event,'load:lorem2',1)">sticky</span>.</span>
<pre>
 onmouseover="balloon.showTooltip(event,'load:lorem2',<b class=y>1</b>)"
</pre>

A fourth argument will set the width (Example:<span class=tt 
onmouseover="balloon.showTooltip(event,'load:lorem2',1,300)">
300px sticky balloon</span>)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Try a <span class=tt
onmouseover="tooltip.showTooltip(event,'load:lorem2',1,300)">plain version</span>

<pre>
 onmouseover="balloon.showTooltip(event,'load:lorem2',1,<b class=y>300</b>)"
</pre>

Now let's try that with a <span class=tt
onmouseover="box.showTooltip(event,'load:lorem2',1,300)">
sticky box</span>.

<pre>
 onmouseover="box.showTooltip(event,'load:lorem2',1,<b class=y>300</b>)"
</pre>

The height can also be specified with a fifth argument (Example:<span class=tt
onmouseover="balloon.showTooltip(event,'load:lorem2',1,250,250)">
250px x 250px sticky balloon</span>)

<pre>
 onmouseover="balloon.showTooltip(event,'load:lorem2',1,<b class=y>250</b>,<b class=y>250</b>)"
</pre>


If the balloon contents are too large for the specified dimensions, you will <span class=tt
onmouseover="balloon.showTooltip(event,'load:lorem2',1,150,150)">scrollbars for sticky balloons</span> 
and <span class=tt onmouseover="balloon.showTooltip(event,'load:lorem2',0,150,150)">clipping for non-sticky balloons</span>.

<pre>
 onmouseover="balloon.showTooltip(event,'load:lorem2',1,<b class=y>150</b>,<b class=y>150</b>)"
</pre>

</p>

<p>
Here is an example of a tooltip balloon that is populated by an
<span class=tt
onmouseover="balloon.showTooltip(event,'<img height=150 src=\'images/balloons.png\' />')">
image</span>.
<pre>
 onmouseover="balloon.showTooltip(event,'&lt;img height=150 src=\'images/balloons.png\' /&gt;')"
</pre>
</p>

<img src="images/balloons.png" onmouseover="balloon.showTooltip(event,'my message')" />

<p>
This creates a sticky balloon whose contents are from an external website.
<span class=tt
onmouseover="balloon.showTooltip(event,'<iframe style=\'width:300;height:290\' frameborder=0 src=\'http://m.nypost.com\'></iframe>',1)">
What's new at the NY Post?</span><br>

<b>Note: </b> This requires an embedded iframe because it is an external website.
<pre>
&lt;span onmouseover="balloon.showTooltip(event,'&lt;iframe style=\'width:300;height:290\'                                                                                                                       frameborder=0 src=\'http://m.nypost.com\'&gt;&lt;/iframe&gt;',1)"&gt;
What's new at the NY Post?&lt;/span&gt;
</pre>
<br>
Ajax methods are <a href="http://gmod.org/wiki/Popup_Balloons#Using_AJAX_to_get_balloon_contents">also available</a>.
</p>
</body>
</html>