AJAX
  Home arrow AJAX arrow Page 4 - Using Prototip with AJAX
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
Google.com  
AJAX

Using Prototip with AJAX
By: Dan Wellman
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 6
    2009-02-04


    Table of Contents:
  • Using Prototip with AJAX
  • Adding Some PHP
  • Extending the Tooltips with Additional Mark-up
  • Getting the Rules Right

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Using Prototip with AJAX - Getting the Rules Right
    ( Page 4 of 4 )

    Now we need some CSS. In a new file in your text editor add the following selectors and rules:

     

    #outerContainer { width:800px; }

    .container {

    width:370px; float:left; padding:7px 0 0 0;

    background:url(../images/containerTop.gif) no-repeat 0 0;

    margin:0 10px 10px 0;

    }

    .container .contents {

    width:350px;

    background:url(../images/containerBody.gif) no-repeat 0 100%; padding:0 10px 10px;

    }

    .container h2 {

    font-size:12px; font-weight:bold; font-family:verdana;

    margin:0 0 10px;

    }

    .container .placeholder {

    float:right; width:132px; height:132px; margin:5px 10px 5px 15px;

    background:url(../images/placeholder.gif) no-repeat;

    position:relative;

    }

    .placeholder img { position:absolute; left:6px; top:6px; }

    .container p { margin:0; }

     

    /* override prototip styles */

    .prototip .protogrey .content { padding:0; margin-bottom:-5px; }

     

    Save this in the css folder as imagetips.css . Mostly this is just layout stuff, although at the end of the file we have a selector and some styles that override the default styling of the prototips. This is necessary to get the images in the tooltips without having a border of white around each image.  

    Finally we can add the script that will bring it all together; add the following code after the last script element in prototip4.html:

     

    <script type="text/javascript">

    //get all trigger elements

    var triggers = $$(".thumb");

     

    //add prototip for each trigger

    triggers.each(function(item, i) {

     

    //create full size image for tooltip

    var image = document.createElement("img");

    var id = item.readAttribute("id");

    image.writeAttribute("src", "../images/space/large/" + id + "_large.jpg");

     

    //define each individual prototip

    new Tip (item, image, {

    title: item.readAttribute("alt"),

    showOn: "click",

    style: "protogrey",

    width:300,

    hideOn: { element: "closeButton", event: "click" },

    hook: { target: "bottomRight", tip: "topLeft" },

    offset: { x: -126, y: -126 }

    });

    });

    </script>

     

    We use the same loop construct in this example as we have before, although this time we create a new image and add an src attribute based on the path to the large images and the id of the current thumbnail.  

    We also use some different properties this time, like the showOn , hideOn and width properties. The width property is an easy way to control the width of the tooltip without overriding styles. We set showOn to click ,  which configures the event that generates the tooltips.  

    We aren’t using the tooltips like traditional tooltips; we want them to stay open until the close button is clicked, rather than close when the pointer moves off of the target element. For this reason, we also specify the hideOn property, which takes an object taking the name of an element and an event. Using the built-in closeButton as the element automatically adds the close button to the tooltip for us.  

    Finally we hook to the target element (the thumbnail) instead of the mouse pointer. This means that the tooltip will not track with the mouse. We use the offset property to lay the tooltip over the top of the thumbnail image.

    Summary

    Prototip provides an excellent foundation for building great-looking and responsive tooltips. It comes with many configuration options that allow us to easily tailor the plugin to our own implementation needs.



     
     
    >>> More AJAX Articles          >>> More By Dan Wellman
     

       

    AJAX ARTICLES

    - PHP AJAX Form Validation
    - Completing a User-Defined CSS Website with P...
    - Create a User-Defined CSS Website with PHP
    - Build A Better Twitter Chat Client Than Cham...
    - Using Division Equations to Make Web Forms S...
    - Using Integer Multiplication to Protect Web ...
    - Using Simple Checksums for Web Form Verifica...
    - Protecting Web Forms with AJAX
    - Using Prototip with AJAX
    - Using Prototip
    - Using the google.load() Method with Google`s...
    - How to Handle Ajax Errors
    - Uncompressing Source Files with Google`s AJA...
    - Using the jQuery Framework with Google`s Aja...
    - Using Google`s Ajax Libraries API




    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek